Crates.io | struct_as_array |
lib.rs | struct_as_array |
version | 0.2.0 |
source | src |
created_at | 2023-11-13 05:51:55.870684 |
updated_at | 2023-11-13 15:12:11.693632 |
description | A Rust library that allows you to represent the structure as an array |
homepage | https://github.com/Nikitamuraviev10/struct_as_array.git |
repository | https://github.com/Nikitamuraviev10/struct_as_array.git |
max_upload_size | |
id | 1033290 |
size | 9,589 |
A Rust library that allows you to represent the structure as an array.
Library works only with named structs whose fields have the same type.
Basic usage:
use struct_as_array::*;
#[derive(AsArray)]
struct TestStruct {
t1: i32,
t2: i32,
t3: i32,
}
let t = TestStruct {
t1: 0,
t2: 1,
t3: 2,
};
// Represent as array of reference
assert_eq!(t.as_array(), [&0, &1, &2]);
// Convert struct to array
assert_eq!(t.to_array(), [0, 1, 2]);
Using as an iterator:
use struct_as_array::*;
#[derive(AsArray)]
struct TestStruct {
t1: i32,
t2: i32,
t3: i32,
}
let t = TestStruct {
t1: 0,
t2: 1,
t3: 2,
};
for i in t.as_array() {
println!("{}", i);
}