Expand description
§ArrayObject
A simple self-describing array of integers, real numbers, complex numbers and strings, designed for object storage, database and single file.
§Examples
Encoding and decording:
use array_object::*;
fn main() {
// Convert data into binary
let original = vec![1u32, 2, 3, 4];
let obj: ArrayObject = original.clone().try_into().unwrap();
let packed = obj.pack(); // This converts the data into Vec<u8>.
// Restore data
let unpacked = ArrayObject::unpack(packed).unwrap();
let inflated: Vec<u32> = unpacked.try_into().unwrap();
assert_eq!(original, inflated);
}
One can also use the macros to write and read a file:
use array_object::*;
fn main() {
// Save into a file
let original = vec![1f64, 2.2, -1.1, 5.6];
export_obj!("testdata.bin", original.clone()); // The type has to be known at this point.
// Load from a file
let restored: Vec<f64> = import_obj!("testdata.bin"); // The type annotation is required.
assert_eq!(original, restored);
}
Modules§
- adaptor
- Adaptors for Complex and Array. These can be used to restore the data or construct ArrayObject without num::complex, ndarray or nalgebra.
Macros§
- export_
obj - A macro to save the data into a file. If the file exists, this will overwrite the existing file.
- import_
obj - A macro to load the data from a file.
Structs§
- Array
Object - The main array storage with type abstraction.
Enums§
- Data
Type - The type of the elements.