-
Notifications
You must be signed in to change notification settings - Fork 48
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
feat: Allow public access to bytes #250
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,7 +10,7 @@ macro_rules! newtype_buffer { | |
#[derive(Debug, Clone, PartialEq, Eq)] | ||
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] | ||
pub struct $name { | ||
bytes: Vec<u8>, | ||
pub bytes: Vec<u8>, | ||
} | ||
|
||
impl $name { | ||
|
@@ -31,7 +31,7 @@ macro_rules! newtype_buffer { | |
|
||
impl<'a> $name_ref<'a> { | ||
/// Construct a new container around this reference version | ||
fn new(bytes: &'a [u8]) -> $name_ref<'a> { | ||
pub fn new(bytes: &'a [u8]) -> $name_ref<'a> { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Implementing this requires an assertion on the length of There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. True, especially if we're dealing with pointer arithmetic under the hood. In idiomatic rust would use result types instead of assertions, especially if we decide to hand over partial control of building these wrappers to the user. |
||
$name_ref { bytes } | ||
} | ||
|
||
|
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 will not merge this: it does not provide faster reference than
as_ref
and this allows to mutually accessbytes
which I do not think is a) idiomatic Rust and b) good and safe API design.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.
We need the ability to construct this given a
Vec<u8>
. TheAsRef<u8>
impl is only good for reading the data.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.
So, if you're interesed in idiomatic rust, we could do: