pub struct BlockSize(/* private fields */);Expand description
Block size in bytes, checked against the valid range.
Sizes run 65 KiB through 511 MiB. The default is 16 MiB.
Level 1 selects MIN, level 14 selects MAX; levels 2-13 are
powers of two from 128 KiB to 256 MiB.
§Examples
use bzip3_rs::BlockSize;
let size = BlockSize::kib(128)?;
assert_eq!(size.get(), 131_072);
assert!(BlockSize::MIN < size && size < BlockSize::MAX);
assert_eq!(BlockSize::default(), BlockSize::DEFAULT);Implementations§
Source§impl BlockSize
impl BlockSize
Sourcepub const fn new(size: u32) -> Result<Self>
pub const fn new(size: u32) -> Result<Self>
Build from a byte count.
§Errors
Returns Error::InvalidBlockSize when size is outside MIN..=MAX.
§Examples
use bzip3_rs::BlockSize;
assert!(BlockSize::new(1024 * 1024).is_ok());
assert!(BlockSize::new(1024).is_err()); // Below `MIN`.
assert!(BlockSize::new(u32::MAX).is_err()); // Above `MAX`.Sourcepub const fn kib(kibibytes: u32) -> Result<Self>
pub const fn kib(kibibytes: u32) -> Result<Self>
Build from a kibibyte count.
§Errors
Returns Error::InvalidBlockSize when the size is outside MIN..=MAX
or the multiplication overflows.
§Examples
use bzip3_rs::BlockSize;
assert_eq!(BlockSize::kib(65)?, BlockSize::MIN);
assert!(BlockSize::kib(64).is_err());Sourcepub const fn mib(mebibytes: u32) -> Result<Self>
pub const fn mib(mebibytes: u32) -> Result<Self>
Build from a mebibyte count.
§Errors
Returns Error::InvalidBlockSize when the size is outside MIN..=MAX
or the multiplication overflows.
§Examples
use bzip3_rs::BlockSize;
assert_eq!(BlockSize::mib(16)?, BlockSize::DEFAULT);
assert!(BlockSize::mib(512).is_err());Sourcepub const fn from_level(level: u8) -> Result<Self>
pub const fn from_level(level: u8) -> Result<Self>
Build from a compression level 1-14.
Level 1 selects Self::MIN (65 KiB). Levels 2-13 are powers
of two: 128 KiB, 256 KiB, 512 KiB, 1 MiB, 2 MiB, 4 MiB, 8 MiB,
16 MiB, 32 MiB, 64 MiB, 128 MiB, 256 MiB.
Level 14 selects Self::MAX (511 MiB).
Level 9 matches Self::DEFAULT.
§Errors
Returns Error::InvalidBlockSize when level is outside 1-14.
§Examples
use bzip3_rs::BlockSize;
assert_eq!(BlockSize::from_level(1)?, BlockSize::MIN);
assert_eq!(BlockSize::from_level(9)?, BlockSize::DEFAULT);
assert_eq!(BlockSize::from_level(14)?, BlockSize::MAX);
assert!(BlockSize::from_level(0).is_err());Trait Implementations§
impl Copy for BlockSize
impl Eq for BlockSize
Source§impl Ord for BlockSize
impl Ord for BlockSize
1.21.0 (const: unstable) · Source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
1.21.0 (const: unstable) · Source§fn min(self, other: Self) -> Selfwhere
Self: Sized,
fn min(self, other: Self) -> Selfwhere
Self: Sized,
Source§impl PartialOrd for BlockSize
impl PartialOrd for BlockSize
impl StructuralPartialEq for BlockSize
Auto Trait Implementations§
impl Freeze for BlockSize
impl RefUnwindSafe for BlockSize
impl Send for BlockSize
impl Sync for BlockSize
impl Unpin for BlockSize
impl UnsafeUnpin for BlockSize
impl UnwindSafe for BlockSize
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more