-
-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
Add length_field_type
to LengthDelimitedCodec
builder
#4508
Add length_field_type
to LengthDelimitedCodec
builder
#4508
Conversation
Allows passing in the wanted unsigned integer type.
`u128` is analogous to `length_field_length(16)`, which would fail.
r? @hawkw |
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.
this seems good to have to me! it would be nice to get a +1 from someone else as well to make sure there are no API issues that i've overlooked...
/// .length_field_type::<u32>() | ||
/// .new_read(io); | ||
/// # } | ||
/// # pub fn main() {} |
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.
my guess is that the fn main()
s in these doctests are here because other functions in the module have them? AFAICT, they shouldn't actually be necessary; not a blocker though.
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.
Yeah I figured the same but wanted to just be consistent with the other doctests.
Thanks Eliza! r? @carllerche since you touched |
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.
LGTM. Should we actually get Carl to review this?
/// The default type is [`u32`]. The max type is [`u64`] (or [`usize`] on | ||
/// 64-bit targets). |
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.
The example uses u128
?
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.
The compilation failure example uses u128
.
Like
length_field_length
except you pass a compile-time checked unsigned integer type instead.Motivation
Powers of two are the most common values for
length_field_length
, but passing in a number of bytes for these feels a bit awkward, especially when the docs state "parse au16
length field".Solution
Add
length_field_type
method that takes a generic type.Implement a sealed (public in private) trait for acceptable types, failing on bad types at compile-time (e.g.
i32
,u128
,String
).