Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve the Reader and Writer creation #27

Merged
merged 6 commits into from
Dec 3, 2023
Merged

Conversation

Kerollmops
Copy link
Member

This PR improves the creation of a Reader and Writer types.

@Kerollmops Kerollmops added the breaking Something that will break in the next release label Nov 30, 2023
@Kerollmops Kerollmops added this to the v0.2.0 milestone Nov 30, 2023
Copy link
Member

@irevoire irevoire left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn’t we use our own Database type in our examples?

I already did it in this PR for the movies examples.

But basically, we could change this:

    let database = env
        .database_options()
        .flags(DatabaseFlags::INTEGER_KEY)
        .types::<KeyCodec, NodeCodec<Euclidean>>()
        .create(&mut wtxn)?;

For this:

    let database: Database<Euclidean> = env
        .database_options()
        .flags(DatabaseFlags::INTEGER_KEY)
        .types()
        .create(&mut wtxn)?;

If we don't want to force people to use the Database type, then maybe we should move the mandatory KeyCodec and NodeCodec outside of the internal module?

src/node_id.rs Outdated
@@ -63,7 +63,7 @@ impl NodeId {
self.item
}

pub fn to_bytes(&self) -> [u8; 5] {
pub fn as_bytes(&self) -> [u8; 5] {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we want to follow the rust convention shouldn't we call this one « into_bytes » since it makes an allocation instead of returning a reference to its content?

From what I see, as_bytes and to_bytes returns references while into_bytes generally return something you can own.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I propose that we use self instead of &self and use the to_bytes name. What do you think?
https://doc.rust-lang.org/std/primitive.u32.html#method.to_le_bytes

src/writer.rs Show resolved Hide resolved
@Kerollmops Kerollmops merged commit 07950e1 into main Dec 3, 2023
5 checks passed
@Kerollmops Kerollmops deleted the improve-write-prepare branch December 3, 2023 18:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
breaking Something that will break in the next release
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants