cberner / redb

An embedded key-value database in pure Rust
https://www.redb.org
Apache License 2.0
3.07k stars 137 forks source link

Impl key and value for String #788

Closed casey closed 3 months ago

casey commented 3 months ago

I noticed that &str implements key and value, but String doesn't.

cberner commented 3 months ago

Ya, I didn't implement that because you would have to insert a &String. And with &str you can call to_string() when retrieving values, if needed. Do you have a use case that needs String?

Sent from my phone

On Mon, Apr 1, 2024, 12:52 AM Casey Rodarmor @.***> wrote:

I noticed that &str implements key and value, but String doesn't.

— Reply to this email directly, view it on GitHub https://github.com/cberner/redb/issues/788, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAGNXQEWAAG5CDGA5W5DIGLY3EG4TAVCNFSM6AAAAABFRHGSFKVHI2DSMVQWIX3LMV43ASLTON2WKOZSGIYTONZVGA4DQNA . You are receiving this because you are subscribed to this thread.Message ID: @.***>

casey commented 3 months ago

We have an Entry trait which abstracts over complex types that can be loaded and stored from the database:

pub(crate) trait Entry: Sized {
  type Value;

  fn load(value: Self::Value) -> Self;

  fn store(self) -> Self::Value;
}

Entry::store can't borrow self, because it doesn't have any lifetimes, so we couldn't implement Entry for something with a &str field.