Struct DigitLayout

Source
#[repr(C)]
pub struct DigitLayout { /* private fields */ }
Expand description

A layout of a digit data type in memory.

Implementations§

Source§

impl DigitLayout

Source

pub const fn unsigned(width: u16, group: u16) -> Self

Create a new digit layout for an unsigned integer type.

Examples found in repository?
examples/basic.rs (line 4)
3fn main() {
4    let u8_layout = DigitLayout::unsigned(8, 1);
5    let u16_layout = DigitLayout::unsigned(16, 1);
6    let u32_layout = DigitLayout::unsigned(32, 1);
7    let u64_layout = DigitLayout::unsigned(64, 1);
8
9    println!("Unsigned Integer Types:");
10    println!("  u8: {u8_layout}");
11    println!("  u16: {u16_layout}");
12    println!("  u32: {u32_layout}");
13    println!("  u64: {u64_layout}");
14
15    let f16_layout = DigitLayout::real(5, 10, 1);
16    let f32_layout = DigitLayout::real(8, 23, 1);
17    let f64_layout = DigitLayout::real(11, 52, 1);
18
19    println!("Floating Point Types:");
20    println!("  f16: {f16_layout}");
21    println!("  f32: {f32_layout}");
22    println!("  f64: {f64_layout}");
23
24    let u8_array = DigitLayout::unsigned(8, 4);
25    let f32_array = DigitLayout::real(8, 23, 4);
26
27    println!("Array Types:");
28    println!("  [u8; 4]: {u8_array}");
29    println!("  [f32; 4]: {f32_array}");
30
31    let custom_layout = DigitLayout::named("custom", 1, 4);
32    println!("Custom Type:");
33    println!("  custom: {custom_layout}");
34}
More examples
Hide additional examples
examples/benchmark.rs (line 12)
5fn main() {
6    println!("Starting performance test...");
7    println!();
8    println!("Testing layout creation:");
9
10    let start = Instant::now();
11    for _ in 0..5 {
12        black_box(DigitLayout::unsigned(8, 1));
13        black_box(DigitLayout::unsigned(16, 1));
14        black_box(DigitLayout::unsigned(32, 1));
15        black_box(DigitLayout::unsigned(64, 1));
16    }
17    let duration = start.elapsed();
18    println!("Creating unsigned integer layouts: {:?}", duration / 20);
19
20    let start = Instant::now();
21    for _ in 0..5 {
22        black_box(DigitLayout::real(5, 10, 1));
23        black_box(DigitLayout::real(8, 23, 1));
24        black_box(DigitLayout::real(11, 52, 1));
25    }
26    let duration = start.elapsed();
27    println!("Creating floating point layouts: {:?}", duration / 15);
28
29    let start = Instant::now();
30    for _ in 0..5 {
31        black_box(DigitLayout::named("custom", 1, 4));
32    }
33    let duration = start.elapsed();
34    println!("Creating custom layouts: {:?}", duration / 5);
35    println!();
36    println!("Testing layout decoding:");
37
38    let u8_layout = DigitLayout::unsigned(8, 1);
39    let f32_layout = DigitLayout::real(8, 23, 1);
40    let custom_layout = DigitLayout::named("custom", 1, 4);
41
42    let start = Instant::now();
43    for _ in 0..5 {
44        black_box(u8_layout.decode());
45    }
46    let duration = start.elapsed();
47    println!("Decoding unsigned integer layouts: {:?}", duration / 5);
48
49    let start = Instant::now();
50    for _ in 0..5 {
51        black_box(f32_layout.decode());
52    }
53    let duration = start.elapsed();
54    println!("Decoding floating point layouts: {:?}", duration / 5);
55
56    let start = Instant::now();
57    for _ in 0..5 {
58        black_box(custom_layout.decode());
59    }
60    let duration = start.elapsed();
61    println!("Decoding custom layouts: {:?}", duration / 5);
62}
Source

pub const fn real(exponent: u16, mantissa: u16, group: u16) -> Self

Create a new digit layout for a real number type.

Examples found in repository?
examples/basic.rs (line 15)
3fn main() {
4    let u8_layout = DigitLayout::unsigned(8, 1);
5    let u16_layout = DigitLayout::unsigned(16, 1);
6    let u32_layout = DigitLayout::unsigned(32, 1);
7    let u64_layout = DigitLayout::unsigned(64, 1);
8
9    println!("Unsigned Integer Types:");
10    println!("  u8: {u8_layout}");
11    println!("  u16: {u16_layout}");
12    println!("  u32: {u32_layout}");
13    println!("  u64: {u64_layout}");
14
15    let f16_layout = DigitLayout::real(5, 10, 1);
16    let f32_layout = DigitLayout::real(8, 23, 1);
17    let f64_layout = DigitLayout::real(11, 52, 1);
18
19    println!("Floating Point Types:");
20    println!("  f16: {f16_layout}");
21    println!("  f32: {f32_layout}");
22    println!("  f64: {f64_layout}");
23
24    let u8_array = DigitLayout::unsigned(8, 4);
25    let f32_array = DigitLayout::real(8, 23, 4);
26
27    println!("Array Types:");
28    println!("  [u8; 4]: {u8_array}");
29    println!("  [f32; 4]: {f32_array}");
30
31    let custom_layout = DigitLayout::named("custom", 1, 4);
32    println!("Custom Type:");
33    println!("  custom: {custom_layout}");
34}
More examples
Hide additional examples
examples/benchmark.rs (line 22)
5fn main() {
6    println!("Starting performance test...");
7    println!();
8    println!("Testing layout creation:");
9
10    let start = Instant::now();
11    for _ in 0..5 {
12        black_box(DigitLayout::unsigned(8, 1));
13        black_box(DigitLayout::unsigned(16, 1));
14        black_box(DigitLayout::unsigned(32, 1));
15        black_box(DigitLayout::unsigned(64, 1));
16    }
17    let duration = start.elapsed();
18    println!("Creating unsigned integer layouts: {:?}", duration / 20);
19
20    let start = Instant::now();
21    for _ in 0..5 {
22        black_box(DigitLayout::real(5, 10, 1));
23        black_box(DigitLayout::real(8, 23, 1));
24        black_box(DigitLayout::real(11, 52, 1));
25    }
26    let duration = start.elapsed();
27    println!("Creating floating point layouts: {:?}", duration / 15);
28
29    let start = Instant::now();
30    for _ in 0..5 {
31        black_box(DigitLayout::named("custom", 1, 4));
32    }
33    let duration = start.elapsed();
34    println!("Creating custom layouts: {:?}", duration / 5);
35    println!();
36    println!("Testing layout decoding:");
37
38    let u8_layout = DigitLayout::unsigned(8, 1);
39    let f32_layout = DigitLayout::real(8, 23, 1);
40    let custom_layout = DigitLayout::named("custom", 1, 4);
41
42    let start = Instant::now();
43    for _ in 0..5 {
44        black_box(u8_layout.decode());
45    }
46    let duration = start.elapsed();
47    println!("Decoding unsigned integer layouts: {:?}", duration / 5);
48
49    let start = Instant::now();
50    for _ in 0..5 {
51        black_box(f32_layout.decode());
52    }
53    let duration = start.elapsed();
54    println!("Decoding floating point layouts: {:?}", duration / 5);
55
56    let start = Instant::now();
57    for _ in 0..5 {
58        black_box(custom_layout.decode());
59    }
60    let duration = start.elapsed();
61    println!("Decoding custom layouts: {:?}", duration / 5);
62}
Source

pub const fn named(name: &str, group: u16, size: u16) -> Self

Create a new digit layout for a named type.

Examples found in repository?
examples/basic.rs (line 31)
3fn main() {
4    let u8_layout = DigitLayout::unsigned(8, 1);
5    let u16_layout = DigitLayout::unsigned(16, 1);
6    let u32_layout = DigitLayout::unsigned(32, 1);
7    let u64_layout = DigitLayout::unsigned(64, 1);
8
9    println!("Unsigned Integer Types:");
10    println!("  u8: {u8_layout}");
11    println!("  u16: {u16_layout}");
12    println!("  u32: {u32_layout}");
13    println!("  u64: {u64_layout}");
14
15    let f16_layout = DigitLayout::real(5, 10, 1);
16    let f32_layout = DigitLayout::real(8, 23, 1);
17    let f64_layout = DigitLayout::real(11, 52, 1);
18
19    println!("Floating Point Types:");
20    println!("  f16: {f16_layout}");
21    println!("  f32: {f32_layout}");
22    println!("  f64: {f64_layout}");
23
24    let u8_array = DigitLayout::unsigned(8, 4);
25    let f32_array = DigitLayout::real(8, 23, 4);
26
27    println!("Array Types:");
28    println!("  [u8; 4]: {u8_array}");
29    println!("  [f32; 4]: {f32_array}");
30
31    let custom_layout = DigitLayout::named("custom", 1, 4);
32    println!("Custom Type:");
33    println!("  custom: {custom_layout}");
34}
More examples
Hide additional examples
examples/benchmark.rs (line 31)
5fn main() {
6    println!("Starting performance test...");
7    println!();
8    println!("Testing layout creation:");
9
10    let start = Instant::now();
11    for _ in 0..5 {
12        black_box(DigitLayout::unsigned(8, 1));
13        black_box(DigitLayout::unsigned(16, 1));
14        black_box(DigitLayout::unsigned(32, 1));
15        black_box(DigitLayout::unsigned(64, 1));
16    }
17    let duration = start.elapsed();
18    println!("Creating unsigned integer layouts: {:?}", duration / 20);
19
20    let start = Instant::now();
21    for _ in 0..5 {
22        black_box(DigitLayout::real(5, 10, 1));
23        black_box(DigitLayout::real(8, 23, 1));
24        black_box(DigitLayout::real(11, 52, 1));
25    }
26    let duration = start.elapsed();
27    println!("Creating floating point layouts: {:?}", duration / 15);
28
29    let start = Instant::now();
30    for _ in 0..5 {
31        black_box(DigitLayout::named("custom", 1, 4));
32    }
33    let duration = start.elapsed();
34    println!("Creating custom layouts: {:?}", duration / 5);
35    println!();
36    println!("Testing layout decoding:");
37
38    let u8_layout = DigitLayout::unsigned(8, 1);
39    let f32_layout = DigitLayout::real(8, 23, 1);
40    let custom_layout = DigitLayout::named("custom", 1, 4);
41
42    let start = Instant::now();
43    for _ in 0..5 {
44        black_box(u8_layout.decode());
45    }
46    let duration = start.elapsed();
47    println!("Decoding unsigned integer layouts: {:?}", duration / 5);
48
49    let start = Instant::now();
50    for _ in 0..5 {
51        black_box(f32_layout.decode());
52    }
53    let duration = start.elapsed();
54    println!("Decoding floating point layouts: {:?}", duration / 5);
55
56    let start = Instant::now();
57    for _ in 0..5 {
58        black_box(custom_layout.decode());
59    }
60    let duration = start.elapsed();
61    println!("Decoding custom layouts: {:?}", duration / 5);
62}
Source

pub const fn to_u64(self) -> u64

Raw transmutation to u64.

Source

pub const fn group_size(self) -> usize

Get the number of bytes occupied by this layout.

Source

pub const fn nbytes(self) -> usize

Get the number of bytes occupied by this layout.

Source

pub const fn decode(self) -> LayoutContent

Decode the content of the digit layout.

Examples found in repository?
examples/benchmark.rs (line 44)
5fn main() {
6    println!("Starting performance test...");
7    println!();
8    println!("Testing layout creation:");
9
10    let start = Instant::now();
11    for _ in 0..5 {
12        black_box(DigitLayout::unsigned(8, 1));
13        black_box(DigitLayout::unsigned(16, 1));
14        black_box(DigitLayout::unsigned(32, 1));
15        black_box(DigitLayout::unsigned(64, 1));
16    }
17    let duration = start.elapsed();
18    println!("Creating unsigned integer layouts: {:?}", duration / 20);
19
20    let start = Instant::now();
21    for _ in 0..5 {
22        black_box(DigitLayout::real(5, 10, 1));
23        black_box(DigitLayout::real(8, 23, 1));
24        black_box(DigitLayout::real(11, 52, 1));
25    }
26    let duration = start.elapsed();
27    println!("Creating floating point layouts: {:?}", duration / 15);
28
29    let start = Instant::now();
30    for _ in 0..5 {
31        black_box(DigitLayout::named("custom", 1, 4));
32    }
33    let duration = start.elapsed();
34    println!("Creating custom layouts: {:?}", duration / 5);
35    println!();
36    println!("Testing layout decoding:");
37
38    let u8_layout = DigitLayout::unsigned(8, 1);
39    let f32_layout = DigitLayout::real(8, 23, 1);
40    let custom_layout = DigitLayout::named("custom", 1, 4);
41
42    let start = Instant::now();
43    for _ in 0..5 {
44        black_box(u8_layout.decode());
45    }
46    let duration = start.elapsed();
47    println!("Decoding unsigned integer layouts: {:?}", duration / 5);
48
49    let start = Instant::now();
50    for _ in 0..5 {
51        black_box(f32_layout.decode());
52    }
53    let duration = start.elapsed();
54    println!("Decoding floating point layouts: {:?}", duration / 5);
55
56    let start = Instant::now();
57    for _ in 0..5 {
58        black_box(custom_layout.decode());
59    }
60    let duration = start.elapsed();
61    println!("Decoding custom layouts: {:?}", duration / 5);
62}

Trait Implementations§

Source§

impl Clone for DigitLayout

Source§

fn clone(&self) -> DigitLayout

Returns a duplicate of the value. Read more
1.0.0 · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for DigitLayout

Source§

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

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

impl Display for DigitLayout

Source§

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

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

impl Hash for DigitLayout

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 DigitLayout

Source§

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

This method returns an Ordering between self and other. Read more
1.21.0 · Source§

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

Compares and returns the maximum of two values. Read more
1.21.0 · Source§

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

Compares and returns the minimum of two values. Read more
1.50.0 · Source§

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

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

impl PartialEq for DigitLayout

Source§

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

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

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

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl PartialOrd for DigitLayout

Source§

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

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · 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 · 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 · 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 · 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 Copy for DigitLayout

Source§

impl Eq for DigitLayout

Source§

impl StructuralPartialEq for DigitLayout

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, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.