Skip to content

Conversation

cassc
Copy link

@cassc cassc commented May 11, 2022

Currently there is no way to use our own data types as keys because the module is private, for example this will not work

// ...
use leveldb::database::key::Key; // error[E0603]: crate `key` is private

#[derive(Clone)]
struct MyData {
    key: String,
}

impl Key for MyData {
    fn from_u8(key: &[u8]) -> Self {
        MyData {
            key: str::from_utf8(key).unwrap().into(),
        }
    }

    fn as_slice<T, F: Fn(&[u8]) -> T>(&self, f: F) -> T {
        let dst = self.key.as_bytes();
        f(&dst)
    }
}
// ...

This PR creates a simple fix by removing the db-key dependency and adds the Key trait as public in src/database/key.rs.

A full example is here

@kaimast
Copy link

kaimast commented Oct 17, 2024

I saw this after commenting on #52. It really seems overly complicated to have db-key as a separate crate, unless other k/v stores are using it, but I do not think they are.

The PR works fine for me. All tests pass. I see some warnings, but those are on master too.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants