Skip to main content

BlockSize

Struct BlockSize 

Source
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

Source

pub const MIN: Self

Smallest valid size: 65 KiB.

Source

pub const MAX: Self

Largest valid size: 511 MiB.

Source

pub const DEFAULT: Self

Default size: 16 MiB.

Source

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`.
Source

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());
Source

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());
Source

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());
Source

pub const fn get(self) -> u32

Return the size in bytes.

§Examples
use bzip3_rs::BlockSize;

assert_eq!(BlockSize::MIN.get(), 65 * 1024);
Source

pub const fn as_usize(self) -> usize

Return the size in bytes as usize.

On 16-bit targets the value truncates like as.

§Examples
use bzip3_rs::BlockSize;

let buffer = vec![0_u8; BlockSize::MIN.as_usize()];
assert_eq!(buffer.len(), 65 * 1024);

Trait Implementations§

Source§

impl Clone for BlockSize

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Copy for BlockSize

Source§

impl Debug for BlockSize

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for BlockSize

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl Eq for BlockSize

Source§

impl Hash for BlockSize

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl Ord for BlockSize

Source§

fn cmp(&self, other: &Self) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 (const: unstable) · Source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 (const: unstable) · Source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 (const: unstable) · Source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized,

Restrict a value to a certain interval. Read more
Source§

fn clamp_to<R>(self, range: R) -> Self
where Self: Sized, R: ClampBounds<Self>,

🔬This is a nightly-only experimental API. (clamp_to)
Restrict a value to a certain range. Read more
Source§

impl PartialEq for BlockSize

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl PartialOrd for BlockSize

Source§

fn partial_cmp(&self, other: &Self) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 (const: unstable) · Source§

fn lt(&self, other: &Rhs) -> bool

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 (const: unstable) · Source§

fn le(&self, other: &Rhs) -> bool

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 (const: unstable) · Source§

fn gt(&self, other: &Rhs) -> bool

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 (const: unstable) · Source§

fn ge(&self, other: &Rhs) -> bool

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl StructuralPartialEq for BlockSize

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.