-
Notifications
You must be signed in to change notification settings - Fork 10
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
De-duplicate block sizes #835
Conversation
4bc9d01
to
f263ca1
Compare
.iter() | ||
.map(|sz| NonZeroU32::new(sz.get_bytes() as u32).expect("bytes must be non-zero")) | ||
.collect(); | ||
// TODO pass in datagram_friendly: true |
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.
Left a TODO here.
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.
intentional, this will be the next PR
#[must_use] | ||
/// The default block sizes. | ||
/// | ||
/// Panics are not possible in practice due to these being static values. | ||
/// # Panics | ||
/// - Panics if a block size is not representable as a 32bit integer | ||
/// - Panics if a block size is zero | ||
pub fn default_blocks() -> Vec<NonZeroU32> { | ||
[ | ||
byte_unit::Byte::from_unit(1.0 / 32.0, byte_unit::ByteUnit::MB).expect("valid bytes"), | ||
byte_unit::Byte::from_unit(1.0 / 16.0, byte_unit::ByteUnit::MB).expect("valid bytes"), | ||
byte_unit::Byte::from_unit(1.0 / 4.0, byte_unit::ByteUnit::MB).expect("valid bytes"), | ||
byte_unit::Byte::from_unit(1.0 / 2.0, byte_unit::ByteUnit::MB).expect("valid bytes"), | ||
byte_unit::Byte::from_unit(1.0, byte_unit::ByteUnit::MB).expect("valid bytes"), | ||
byte_unit::Byte::from_unit(2.0, byte_unit::ByteUnit::MB).expect("valid bytes"), | ||
byte_unit::Byte::from_unit(4.0, byte_unit::ByteUnit::MB).expect("valid bytes"), | ||
] | ||
.iter() | ||
.map(|sz| { | ||
NonZeroU32::new( | ||
u32::try_from(sz.get_bytes()).expect("Block size not representable as 32bit integer"), | ||
) | ||
.expect("Block size is non-zero") | ||
}) | ||
.collect() | ||
} |
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 is so much nicer than having this copied everywhere.
What does this PR do?
Refactors the generators that take in
block_sizes
as an argument and extracts that logic and default to a single location in the code.Motivation
Simplify my next set of changes and de-duplicate the code.
Related issues
Additional Notes