-
Notifications
You must be signed in to change notification settings - Fork 6
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
Conversation
There was a problem hiding this 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] { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
d57ef16
to
a9c1a42
Compare
a9c1a42
to
0974706
Compare
This PR improves the creation of a
Reader
andWriter
types.