#[repr(C)]pub struct DigitLayout { /* private fields */ }
Expand description
A layout of a digit data type in memory.
Implementations§
Source§impl DigitLayout
impl DigitLayout
Sourcepub const fn unsigned(width: u16, group: u16) -> Self
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
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}
Sourcepub const fn real(exponent: u16, mantissa: u16, group: u16) -> Self
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
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}
Sourcepub const fn named(name: &str, group: u16, size: u16) -> Self
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
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}
Sourcepub const fn group_size(self) -> usize
pub const fn group_size(self) -> usize
Get the number of bytes occupied by this layout.
Sourcepub const fn decode(self) -> LayoutContent
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
impl Clone for DigitLayout
Source§fn clone(&self) -> DigitLayout
fn clone(&self) -> DigitLayout
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source
. Read moreSource§impl Debug for DigitLayout
impl Debug for DigitLayout
Source§impl Display for DigitLayout
impl Display for DigitLayout
Source§impl Hash for DigitLayout
impl Hash for DigitLayout
Source§impl Ord for DigitLayout
impl Ord for DigitLayout
Source§fn cmp(&self, other: &DigitLayout) -> Ordering
fn cmp(&self, other: &DigitLayout) -> Ordering
1.21.0 · Source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
Compares and returns the maximum of two values. Read more
Source§impl PartialEq for DigitLayout
impl PartialEq for DigitLayout
Source§impl PartialOrd for DigitLayout
impl PartialOrd for DigitLayout
impl Copy for DigitLayout
impl Eq for DigitLayout
impl StructuralPartialEq for DigitLayout
Auto Trait Implementations§
impl Freeze for DigitLayout
impl RefUnwindSafe for DigitLayout
impl Send for DigitLayout
impl Sync for DigitLayout
impl Unpin for DigitLayout
impl UnwindSafe for DigitLayout
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
Mutably borrows from an owned value. Read more