### FileResourceStorage Example Usage Source: https://docs.rs/flatdata/latest/src/flatdata/filestorage.rs.html Demonstrates how to use `FileResourceStorage` to create and read archives from the file system. This example shows initializing the storage, building an archive with data, and then opening it to read the data back. ```rust use flatdata::{FileResourceStorage, Vector}; use flatdata::test::{X, XBuilder}; let storage = FileResourceStorage::new("/root/to/my/archive"); let builder = XBuilder::new(storage.clone()).expect("failed to create builder"); // Write some data and store it archive, e.g. let v = Vector::new(); builder.set_data(&v.as_view()); let archive = X::open(storage).expect("failed to open"); // read data archive.data(); ``` -------------------------------- ### Example Output Source: https://docs.rs/flatdata/latest/flatdata/index.html The expected output when running the provided Rust code example to calculate and print prime factors. ```text List if prime factors for 1234 is [2, 617] ``` -------------------------------- ### TarArchiveResourceStorage Usage Example Source: https://docs.rs/flatdata/latest/src/flatdata/tarstorage.rs.html Example demonstrating how to create a TarArchiveResourceStorage and open a flatdata archive with it. ```APIDOC ## TarArchiveResourceStorage Usage Example ### Description This example shows how to initialize the `TarArchiveResourceStorage` and use it to open a flatdata archive. ### Code ```rust,no_run use flatdata::{TarArchiveResourceStorage, Vector}; use flatdata::test::X; let storage = TarArchiveResourceStorage::new("/root/to/my/archive.tar") .expect("failed to read tar archive"); let archive = X::open(storage).expect("failed to open"); // read data archive.data(); ``` ``` -------------------------------- ### ExternalVector Example: Building and Reading Data Source: https://docs.rs/flatdata/latest/src/flatdata/vector.rs.html Demonstrates how to use ExternalVector to build and then read data. This example shows appending elements, flushing, closing the vector, and then opening the archive to access the data. ```rust use flatdata::MemoryResourceStorage; use flatdata::test::{A, X, XBuilder}; let storage = MemoryResourceStorage::new("/root/extvec"); let builder = XBuilder::new(storage.clone()).expect("failed to create builder"); { let mut v = builder.start_data().expect("failed to start"); let mut a = v.grow().expect("grow failed"); a.set_x(0); a.set_y(1); let mut a = v.grow().expect("grow failed"); a.set_x(2); a.set_y(3); let view = v.close().expect("close failed"); // data can also be inspected directly after closing assert_eq!(view.len(), 2); assert_eq!(view[0].x(), 0); assert_eq!(view[0].y(), 1); } let archive = X::open(storage).expect("failed to open"); let view = archive.data(); assert_eq!(view[1].x(), 2); assert_eq!(view[1].y(), 3); ``` -------------------------------- ### Vector Example Source: https://docs.rs/flatdata/latest/flatdata/struct.Vector.html Demonstrates how to create, populate, and use a Vector with a custom struct. ```APIDOC ## §Examples ```rust struct A { x : u32 : 16; y : u32 : 16; } archive X { data : vector< A >; } ``` ```rust use flatdata::{ MemoryResourceStorage, Vector }; use flatdata::test::{A, X, XBuilder}; let storage = MemoryResourceStorage::new("/root/extvec"); let builder = XBuilder::new(storage.clone()).expect("failed to create builder"); let mut v: Vector = Vector::new(); let mut a = v.grow(); a.set_x(1); a.set_y(2); let mut b = v.grow(); b.set_x(3); b.set_y(4); assert_eq!(v.len(), 2); builder.set_data(&v.as_view()); let archive = X::open(storage).expect("failed to open"); let view = archive.data(); assert_eq!(view[1].x(), 3); ``` ``` -------------------------------- ### starts_with Source: https://docs.rs/flatdata/latest/flatdata/struct.RawData.html Checks if the slice starts with a given prefix slice. ```APIDOC ## pub fn starts_with(&self, needle: &[T]) -> bool ### Description Returns `true` if `needle` is a prefix of the slice or equal to the slice. ### Method `starts_with` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```rust let v = [10, 40, 30]; assert!(v.starts_with(&[10])); assert!(v.starts_with(&[10, 40])); assert!(v.starts_with(&v)); assert!(!v.starts_with(&[50])); assert!(!v.starts_with(&[10, 50])); ``` ### Response #### Success Response (200) `bool`: Returns `true` if the slice starts with the `needle`, `false` otherwise. #### Response Example ```json { "example": "true" } ``` ``` -------------------------------- ### Split Off Slice Starting from Third Element Source: https://docs.rs/flatdata/latest/flatdata/struct.Vector.html Use `split_off` with a `2..` range to remove and get a reference to the slice starting from the third element. ```rust let mut slice: &[_] = &['a', 'b', 'c', 'd']; let mut tail = slice.split_off(2..).unwrap(); assert_eq!(slice, &['a', 'b']); assert_eq!(tail, &['c', 'd']); ``` -------------------------------- ### Create and Populate Vector Source: https://docs.rs/flatdata/latest/flatdata/struct.Vector.html Demonstrates creating a Vector, adding elements, and writing it to storage using an archive builder. This example requires `flatdata` and its test utilities. ```rust use flatdata::{ MemoryResourceStorage, Vector }; use flatdata::test::{A, X, XBuilder}; let storage = MemoryResourceStorage::new("/root/extvec"); let builder = XBuilder::new(storage.clone()).expect("failed to create builder"); let mut v: Vector = Vector::new(); let mut a = v.grow(); a.set_x(1); a.set_y(2); let mut b = v.grow(); b.set_x(3); b.set_y(4); assert_eq!(v.len(), 2); builder.set_data(&v.as_view()); let archive = X::open(storage).expect("failed to open"); let view = archive.data(); assert_eq!(view[1].x(), 3); ``` -------------------------------- ### Split Off Slice Starting from Third Element Mutably Source: https://docs.rs/flatdata/latest/flatdata/struct.Vector.html Use `split_off_mut` with a `2..` range to remove and get a mutable reference to the slice starting from the third element. ```rust let mut slice: &mut [_] = &mut ['a', 'b', 'c', 'd']; let mut tail = slice.split_off_mut(2..).unwrap(); assert_eq!(slice, &mut ['a', 'b']); assert_eq!(tail, &mut ['c', 'd']); ``` -------------------------------- ### Create W Archive Builder Source: https://docs.rs/flatdata/latest/src/flatdata/test/test_generated.rs.html Initializes a new W archive with the specified storage handle and schema. This is used to begin building a W archive. ```rust pub fn new( storage: crate::StorageHandle, ) -> Result { crate::create_archive("W", schema::w::W, &storage)?; Ok(Self { storage }) } ``` -------------------------------- ### Iterate over slice elements Source: https://docs.rs/flatdata/latest/flatdata/struct.RawData.html Use `iter()` to get an iterator that yields references to each element in the slice from start to end. This is the standard way to traverse slice elements sequentially. ```rust let x = &[1, 2, 4]; let mut iterator = x.iter(); assert_eq!(iterator.next(), Some(&1)); assert_eq!(iterator.next(), Some(&2)); assert_eq!(iterator.next(), Some(&4)); assert_eq!(iterator.next(), None); ``` -------------------------------- ### Build and Read Flatdata Archive (Rust) Source: https://docs.rs/flatdata Example demonstrating how to use generated code to build a flatdata archive in memory and then read data from it. Ensure the schema is compiled into `prime_generated.rs`. ```rust include!("prime_generated.rs"); use flatdata::{ MemoryResourceStorage}; pub fn calculate_prime_factors( builder: &mut prime::ArchiveBuilder, max_number: u32, ) -> std::io::Result<()> { let mut numbers = builder.start_numbers()?; let mut factors = builder.start_factors()?; numbers.grow()?.set_first_factor_ref(0); for mut x in 0..=max_number { // Let's calculate prime factor in a very inefficient way for y in 2..x { let mut count = 0; while x % y == 0 { count += 1; x /= y; } if count > 0 { let mut factor = factors.grow()?; factor.set_value(y); factor.set_count(count); } } numbers.grow()?.set_first_factor_ref(factors.len() as u32); } numbers.close().expect("Failed to close"); factors.close().expect("Failed to close"); Ok(()) } pub fn main() { let storage = MemoryResourceStorage::new("/primes"); let mut builder = prime::ArchiveBuilder::new(storage.clone()).expect("failed to create builder"); calculate_prime_factors(&mut builder, 10000).expect("Failed to write archive"); // store archive for re-use // ... // in a different application open archive for use: let archive = prime::Archive::open(storage).expect("failed to open archive"); let number = 1234; let factor_range = archive.numbers().at(number).first_factor_ref() as usize ..archive.numbers().at(number + 1).first_factor_ref() as usize; let factors: Vec<_> = archive .factors() .slice(factor_range) .iter() .flat_map(|x| std::iter::repeat(x.value()).take(x.count() as usize)) .collect(); println!("List if prime factors for {}: {:?}", number, factors); } ``` -------------------------------- ### Mutably iterate over exact reverse chunks of a slice Source: https://docs.rs/flatdata/latest/flatdata/struct.Vector.html Use `rchunks_exact_mut` to get an iterator over mutable slices of a fixed size, starting from the end. This allows in-place modification of elements within each chunk. ```rust let v = &mut [0, 0, 0, 0, 0]; let mut count = 1; for chunk in v.rchunks_exact_mut(2) { for elem in chunk.iter_mut() { *elem += count; } count += 1; } assert_eq!(v, &[0, 2, 2, 1, 1]); ``` -------------------------------- ### Get Subslice Range Source: https://docs.rs/flatdata/latest/flatdata/struct.Vector.html Use `subslice_range` to find the start and end indices of a subslice within a larger slice. This is a nightly-only experimental API. It returns `None` if the subslice is not found or not aligned. Note that this method does not compare elements. ```rust #![feature(substr_range)] let nums = &[0, 5, 10, 0, 0, 5]; let mut iter = nums .split(|t| *t == 0) .map(|n| nums.subslice_range(n).unwrap()); assert_eq!(iter.next(), Some(0..0)); assert_eq!(iter.next(), Some(1..3)); assert_eq!(iter.next(), Some(4..4)); assert_eq!(iter.next(), Some(5..6)); ``` -------------------------------- ### Create New X Archive Builder Source: https://docs.rs/flatdata/latest/src/flatdata/test/test_generated.rs.html Initializes a new builder for creating an X archive. Requires a `StorageHandle` and will return an error if archive creation fails. ```rust crate::create_archive("X", schema::x::X, &storage)?; Ok(Self { storage }) ``` -------------------------------- ### Mutably split slices by a predicate (reverse) Source: https://docs.rs/flatdata/latest/flatdata/struct.Vector.html Use `rsplitn_mut` to get mutable subslices separated by elements matching a predicate, limited to a maximum number of items. Starts from the end of the slice. The matched element is not included in the subslices. ```rust let mut s = [10, 40, 30, 20, 60, 50]; for group in s.rsplitn_mut(2, |num| *num % 3 == 0) { group[0] = 1; } assert_eq!(s, [1, 40, 30, 20, 60, 1]); ``` -------------------------------- ### XBuilder::start_data Source: https://docs.rs/flatdata/latest/src/flatdata/test/test_generated.rs.html Opens the data resource in the archive for buffered writing. ```APIDOC ## XBuilder::start_data ### Description Opens the data resource in the archive for buffered writing. Elements can be added until `ExternalVector::close` is called. This method must be called at the end to fully flush the data. ### Signature ```rust #[inline] pub fn start_data(&self) -> ::std::io::Result> ``` ### Returns A `Result` containing an `ExternalVector` for buffered writing or an `io::Error`. ``` -------------------------------- ### Create and Use FileResourceStorage Source: https://docs.rs/flatdata/latest/flatdata/struct.FileResourceStorage.html Demonstrates creating a FileResourceStorage, writing data using a builder, and then reading the data back from the archive. ```rust use flatdata::{FileResourceStorage, Vector}; use flatdata::test::{X, XBuilder}; let storage = FileResourceStorage::new("/root/to/my/archive"); let builder = XBuilder::new(storage.clone()).expect("failed to create builder"); // Write some data and store it archive, e.g. let v = Vector::new(); builder.set_data(&v.as_view()); let archive = X::open(storage).expect("failed to open"); // read data archive.data(); ``` -------------------------------- ### Get Type ID Source: https://docs.rs/flatdata/latest/flatdata/struct.RawData.html Gets the `TypeId` of the implementing type. This is part of the `Any` trait implementation. ```rust fn type_id(&self) -> TypeId Gets the `TypeId` of `self`. Read more ``` -------------------------------- ### Get Mutable Element or Subslice Source: https://docs.rs/flatdata/latest/flatdata/struct.Vector.html Safely get a mutable reference to an element or subslice. Returns `None` if the index is out of bounds. ```rust let x = &mut [0, 1, 2]; if let Some(elem) = x.get_mut(1) { *elem = 42; } assert_eq!(x, &[0, 42, 2]); ``` -------------------------------- ### Building and Reading Flatdata Archives in Rust Source: https://docs.rs/flatdata/latest/src/flatdata/lib.rs.html Demonstrates how to use generated Rust code to build a flatdata archive with prime factor data and then read it back. Includes calculating prime factors and accessing stored data. ```rust include!("prime_generated.rs"); use flatdata::{ MemoryResourceStorage}; pub fn calculate_prime_factors( builder: &mut prime::ArchiveBuilder, max_number: u32, ) -> std::io::Result<()> { let mut numbers = builder.start_numbers()?; let mut factors = builder.start_factors()?; numbers.grow()?.set_first_factor_ref(0); for mut x in 0..=max_number { // Let's calculate prime factor in a very inefficient way for y in 2..x { let mut count = 0; while x % y == 0 { count += 1; x /= y; } if count > 0 { let mut factor = factors.grow()?; factor.set_value(y); factor.set_count(count); } } numbers.grow()?.set_first_factor_ref(factors.len() as u32); } numbers.close().expect("Failed to close"); factors.close().expect("Failed to close"); Ok(()) } pub fn main() { let storage = MemoryResourceStorage::new("/primes"); let mut builder = prime::ArchiveBuilder::new(storage.clone()).expect("failed to create builder"); calculate_prime_factors(&mut builder, 10000).expect("Failed to write archive"); // store archive for re-use // ... // in a different application open archive for use: let archive = prime::Archive::open(storage).expect("failed to open archive"); let number = 1234; let factor_range = archive.numbers().at(number).first_factor_ref() as usize ..archive.numbers().at(number + 1).first_factor_ref() as usize; let factors: Vec<_> = archive .factors() .slice(factor_range) .iter() .flat_map(|x| std::iter::repeat(x.value()).take(x.count() as usize)) .collect(); println!("List if prime factors for {}: {:?}", number, factors); } ``` -------------------------------- ### Get Mutable Pointer Range for Slice Source: https://docs.rs/flatdata/latest/flatdata/struct.Vector.html Get a half-open range of two unsafe mutable pointers spanning the slice. Useful for C interop. ```rust let x = &mut [1, 2, 4]; let x_ptr_range = x.as_mut_ptr_range(); ``` -------------------------------- ### Get Unchecked Mutable Element or Subslice Source: https://docs.rs/flatdata/latest/flatdata/struct.Vector.html Unsafely get a mutable reference to an element or subslice without bounds checking. Calling with an out-of-bounds index is undefined behavior. ```rust let x = &mut [1, 2, 4]; unsafe { let elem = x.get_unchecked_mut(1); *elem = 13; } assert_eq!(x, &[1, 13, 4]); ``` -------------------------------- ### Create Resource Handle with Output Stream Source: https://docs.rs/flatdata/latest/src/flatdata/storage.rs.html Shows how to create a ResourceHandle using an existing output stream. This is useful for associating data with a schema and managing its lifecycle. ```rust let stream = storage.create_output_stream("/root/extvec/blubb").unwrap(); let h = ResourceHandle::try_new( &*storage, "/root/extvec/blubb".into(), "myschema".into(), stream, ) .unwrap(); h.close().map(|_| ()) ``` -------------------------------- ### Open W Archive Source: https://docs.rs/flatdata/latest/src/flatdata/test/test_generated.rs.html Opens an existing W archive from the provided storage handle. It reads the archive's signature and initializes the 'blob' resource. ```rust pub fn open(storage: crate::StorageHandle) -> ::std::result::Result { #[allow(unused_imports)] use crate::SliceExt; #[allow(unused_variables)] use crate::ResourceStorageError as Error; // extend lifetime since Rust cannot know that we reference a cache here #[allow(unused_variables)] let extend = |x : Result<&[u8], Error>| -> Result<&'static [u8], Error> {x.map(|x| unsafe{std::mem::transmute(x)})}; storage.read(&Self::signature_name("W"), schema::w::W)?; let blob = { use crate::check_resource as check; let max_size = None; let resource = extend(storage.read("blob", schema::w::resources::BLOB)); check("blob", |r| r.len(), max_size, resource.map(|x| crate::RawData::new(x)))? }; Ok(Self { _storage: storage, blob, }) } ``` -------------------------------- ### MemoryResourceStorage Example Usage Source: https://docs.rs/flatdata/latest/src/flatdata/memstorage.rs.html Demonstrates how to create, write to, and read from a MemoryResourceStorage. This is useful for testing archive creation and data access without disk I/O. ```rust use flatdata::{MemoryResourceStorage, Vector}; use flatdata::test::{X, XBuilder}; let storage = MemoryResourceStorage::new("/root/to/my/archive/in/memory"); let builder = XBuilder::new(storage.clone()).expect("failed to create builder"); // Write some data and store it archive, e.g. let v = Vector::new(); builder.set_data(&v.as_view()); let archive = X::open(storage).expect("failed to open"); // read data archive.data(); ``` -------------------------------- ### WBuilder::new Source: https://docs.rs/flatdata/latest/src/flatdata/test/test_generated.rs.html Creates a new 'W' archive with the given storage handle. ```APIDOC ## new ### Description Creates a new 'W' archive with the given storage handle. ### Method `pub fn new(storage: crate::StorageHandle) -> Result` ### Endpoint N/A (SDK method) ### Parameters - **storage** (`crate::StorageHandle`): The storage handle for the archive. ### Request Example N/A ### Response #### Success Response - `Self`: A new `WBuilder` instance. #### Response Example N/A ``` -------------------------------- ### ExternalVector Usage Example Source: https://docs.rs/flatdata/latest/flatdata/struct.ExternalVector.html Demonstrates how to use ExternalVector to add elements, close the vector, and then access the data. This example shows the typical workflow for serializing data that might not fit entirely in memory. ```rust struct A { x : u32 : 16; y : u32 : 16; } archive X { data : vector< A >; } ``` ```rust use flatdata::MemoryResourceStorage; use flatdata::test::{A, X, XBuilder}; let storage = MemoryResourceStorage::new("/root/extvec"); let builder = XBuilder::new(storage.clone()).expect("failed to create builder"); { let mut v = builder.start_data().expect("failed to start"); let mut a = v.grow().expect("grow failed"); a.set_x(0); a.set_y(1); let mut a = v.grow().expect("grow failed"); a.set_x(2); a.set_y(3); let view = v.close().expect("close failed"); // data can also be inspected directly after closing assert_eq!(view.len(), 2); assert_eq!(view[0].x(), 0); assert_eq!(view[0].y(), 1); } let archive = X::open(storage).expect("failed to open"); let view = archive.data(); assert_eq!(view[1].x(), 2); assert_eq!(view[1].y(), 3); ``` -------------------------------- ### Get a mutable reference to the last element Source: https://docs.rs/flatdata/latest/flatdata/struct.Vector.html Use `last_mut()` to get an `Option` containing a mutable reference to the last element. Returns `None` if the slice is empty. Modifies the last element in place. ```rust let x = &mut [0, 1, 2]; if let Some(last) = x.last_mut() { *last = 10; } assert_eq!(x, &[0, 1, 10]); let y: &mut [i32] = &mut []; assert_eq!(None, y.last_mut()); ``` -------------------------------- ### XBuilder::new Source: https://docs.rs/flatdata/latest/src/flatdata/test/test_generated.rs.html Creates a new builder for the X archive. ```APIDOC ## XBuilder::new ### Description Creates a new builder for the X archive. ### Signature ```rust pub fn new(storage: crate::StorageHandle) -> Result ``` ### Parameters * `storage` (crate::StorageHandle) - The storage handle for the archive. ``` -------------------------------- ### Test ByteWriter with Various Data Source: https://docs.rs/flatdata/latest/src/flatdata/bytewriter.rs.html These examples demonstrate testing the ByteWriter with different integer values and byte vectors. They are useful for verifying the correct operation of the writer under various conditions. ```rust test_writer(1, 3, 49, &vec![8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]); test_writer(1, 3, 48, &vec![8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]); test_writer(1, 3, 47, &vec![8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]); test_writer(1, 3, 46, &vec![8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]); test_writer(1, 3, 45, &vec![8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]); test_writer(1, 3, 44, &vec![8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]); test_writer(1, 3, 43, &vec![8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]); test_writer(1, 3, 42, &vec![8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]); test_writer(1, 3, 41, &vec![8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]); test_writer(1, 3, 40, &vec![8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]); test_writer(1, 3, 39, &vec![8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]); test_writer(1, 3, 38, &vec![8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]); test_writer(1, 3, 37, &vec![8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]); test_writer(1, 3, 36, &vec![8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]); test_writer(1, 3, 35, &vec![8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]); test_writer(1, 3, 34, &vec![8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]); test_writer(1, 3, 33, &vec![8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]); test_writer(1, 3, 32, &vec![8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]); test_writer(1, 3, 31, &vec![8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]); test_writer(1, 3, 30, &vec![8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]); test_writer(1, 3, 29, &vec![8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]); test_writer(1, 3, 28, &vec![8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]); test_writer(1, 3, 27, &vec![8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]); test_writer(1, 3, 26, &vec![8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]); test_writer(1, 3, 25, &vec![8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]); test_writer(1, 3, 24, &vec![8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]); test_writer(1, 3, 23, &vec![8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]); test_writer(1, 3, 22, &vec![8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]); test_writer(1, 3, 21, &vec![8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]); test_writer(1, 3, 20, &vec![8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]); test_writer(1, 3, 19, &vec![8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]); test_writer(1, 3, 18, &vec![8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]); test_writer(1, 3, 17, &vec![8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]); test_writer(1, 3, 16, &vec![8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]); test_writer(1, 3, 15, &vec![8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]); test_writer(1, 3, 14, &vec![8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]); test_writer(1, 3, 13, &vec![8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]); test_writer(1, 3, 12, &vec![8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]); test_writer(1, 3, 11, &vec![8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]); test_writer(1, 3, 10, &vec![8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]); test_writer(1, 3, 9, &vec![8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]); test_writer(1, 3, 8, &vec![8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]); test_writer(1, 3, 7, &vec![8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]); test_writer(1, 3, 6, &vec![8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]); test_writer(1, 3, 5, &vec![8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]); test_writer(1, 3, 4, &vec![8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]); test_writer(1, 3, 3, &vec![8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]); test_writer(1, 3, 2, &vec![8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]); test_writer(1, 3, 1, &vec![8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]); test_writer(1, 2, 64, &vec![4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]); test_writer(1, 2, 63, &vec![4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]); test_writer(1, 2, 62, &vec![4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]); test_writer(1, 2, 61, &vec![4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]); test_writer(1, 2, 60, &vec![4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]); ``` -------------------------------- ### TypeId Source: https://docs.rs/flatdata/latest/flatdata/struct.Vector.html Gets the TypeId of the Vector. ```APIDOC ## fn type_id(&self) -> TypeId Gets the `TypeId` of `self`. ``` -------------------------------- ### type_id Source: https://docs.rs/flatdata/latest/flatdata/struct.RawData.html Gets the `TypeId` of the `RawData` value. ```APIDOC ## fn type_id(&self) -> TypeId ### Description Gets the `TypeId` of `self`. ### Parameters #### Path Parameters - None #### Query Parameters - None #### Request Body - None ### Response #### Success Response (200) - **TypeId**: The `TypeId` of the value. ``` -------------------------------- ### Create and Open TarArchiveResourceStorage Source: https://docs.rs/flatdata/latest/flatdata/struct.TarArchiveResourceStorage.html Demonstrates how to create a TarArchiveResourceStorage from a tar file path and then open a flatdata archive using it. Ensure the tar file exists at the specified path. ```rust use flatdata::{TarArchiveResourceStorage, Vector}; use flatdata::test::X; let storage = TarArchiveResourceStorage::new("/root/to/my/archive.tar") .expect("failed to read tar archive"); let archive = X::open(storage).expect("failed to open"); // read data archive.data(); ``` -------------------------------- ### Get a mutable reference to the last N elements Source: https://docs.rs/flatdata/latest/flatdata/struct.Vector.html Use `last_chunk_mut::()` to get an `Option` containing a mutable reference to the last `N` elements as an array. Returns `None` if the slice is shorter than `N`. Allows in-place modification of the last `N` elements. ```rust let x = &mut [0, 1, 2]; if let Some(last) = x.last_chunk_mut::<2>() { last[0] = 10; last[1] = 20; } assert_eq!(x, &[0, 10, 20]); assert_eq!(None, x.last_chunk_mut::<4>()); ``` -------------------------------- ### Create and Use MemoryResourceStorage Source: https://docs.rs/flatdata/latest/flatdata/struct.MemoryResourceStorage.html Demonstrates creating a MemoryResourceStorage, writing data to it using a builder, and then reading the data back from the archive. This is useful for testing scenarios. ```rust use flatdata::{MemoryResourceStorage, Vector}; use flatdata::test::{X, XBuilder}; let storage = MemoryResourceStorage::new("/root/to/my/archive/in/memory"); let builder = XBuilder::new(storage.clone()).expect("failed to create builder"); // Write some data and store it archive, e.g. let v = Vector::new(); builder.set_data(&v.as_view()); let archive = X::open(storage).expect("failed to open"); // read data archive.data(); ``` -------------------------------- ### Get a mutable reference to the first N elements Source: https://docs.rs/flatdata/latest/flatdata/struct.Vector.html Use `first_chunk_mut::()` to get an `Option` containing a mutable reference to the first `N` elements as an array. Returns `None` if the slice is shorter than `N`. Allows in-place modification of the first `N` elements. ```rust let x = &mut [0, 1, 2]; if let Some(first) = x.first_chunk_mut::<2>() { first[0] = 5; first[1] = 4; } assert_eq!(x, &[5, 4, 2]); assert_eq!(None, x.first_chunk_mut::<4>()); ``` -------------------------------- ### Create Z Archive Builder Source: https://docs.rs/flatdata/latest/src/flatdata/test/test_generated.rs.html Initializes a new Z archive with the specified storage handle and schema. This is used to begin building a Z archive. ```rust pub fn new( storage: crate::StorageHandle, ) -> Result { crate::create_archive("Z", schema::z::Z, &storage)?; Ok(Self { storage }) } ``` -------------------------------- ### GetTypeId for Any Trait Source: https://docs.rs/flatdata/latest/flatdata/struct.MultiArrayView.html Gets the TypeId of the MultiArrayView, as required by the Any trait. ```rust fn type_id(&self) -> TypeId ``` -------------------------------- ### Vector Usage Example Source: https://docs.rs/flatdata/latest/src/flatdata/vector.rs.html Demonstrates creating, populating, and storing a Vector of struct A in memory, then retrieving and asserting its contents. ```rust use flatdata::{ MemoryResourceStorage, Vector }; use flatdata::test::{A, X, XBuilder}; let storage = MemoryResourceStorage::new("/root/extvec"); let builder = XBuilder::new(storage.clone()).expect("failed to create builder"); let mut v: Vector = Vector::new(); let mut a = v.grow(); a.set_x(1); a.set_y(2); let mut b = v.grow(); b.set_x(3); b.set_y(4); assert_eq!(v.len(), 2); builder.set_data(&v.as_view()); let archive = X::open(storage).expect("failed to open"); let view = archive.data(); assert_eq!(view[1].x(), 3); ``` -------------------------------- ### strip_prefix Source: https://docs.rs/flatdata/latest/flatdata/struct.Vector.html Returns a subslice with the prefix removed. If the slice starts with `prefix`, returns the subslice after the prefix, wrapped in `Some`. If `prefix` is empty, simply returns the original slice. If `prefix` is equal to the original slice, returns an empty slice. If the slice does not start with `prefix`, returns `None`. ```APIDOC ## strip_prefix

(&self, prefix: &P) -> Option<&[T]> where P: SlicePattern + ?Sized, T: PartialEq ### Description Returns a subslice with the prefix removed. Returns `Some` with the subslice after the prefix if the slice starts with `prefix`, otherwise returns `None`. ### Parameters #### Path Parameters - **prefix** (&P) - Required - The prefix to remove. `P` must implement `SlicePattern`. ### Method `strip_prefix` ### Endpoint N/A (Method on slice) ### Request Example ```rust let v = &[10, 40, 30]; assert_eq!(v.strip_prefix(&[10]), Some(&[40, 30][..])); assert_eq!(v.strip_prefix(&[10, 40]), Some(&[30][..])); assert_eq!(v.strip_prefix(&[10, 40, 30]), Some(&[][..])); assert_eq!(v.strip_prefix(&[50]), None); assert_eq!(v.strip_prefix(&[10, 50]), None); let prefix : &str = "he"; assert_eq!(b"hello".strip_prefix(prefix.as_bytes()), Some(b"llo".as_ref())); ``` ### Response #### Success Response (Option) - `Option<&[T]>`: A slice with the prefix removed if it exists, otherwise `None`. ``` -------------------------------- ### YBuilder::start_data Source: https://docs.rs/flatdata/latest/src/flatdata/test/test_generated.rs.html Opens the data resource in the archive for buffered writing. ```APIDOC ## YBuilder::start_data ### Description Opens the data resource in the archive for buffered writing. Elements can be added until `ExternalVector::close` is called. This method must be called at the end to fully flush the data. ### Signature ```rust #[inline] pub fn start_data(&self) -> ::std::io::Result> ``` ### Returns A `Result` containing an `ExternalVector` for buffered writing or an `io::Error`. ``` -------------------------------- ### ZBuilder::new Source: https://docs.rs/flatdata/latest/src/flatdata/test/test_generated.rs.html Creates a new 'Z' archive with the given storage handle. ```APIDOC ## new ### Description Creates a new 'Z' archive with the given storage handle. ### Method `pub fn new(storage: crate::StorageHandle) -> Result` ### Endpoint N/A (SDK method) ### Parameters - **storage** (`crate::StorageHandle`): The storage handle for the archive. ### Request Example N/A ### Response #### Success Response - `Self`: A new `ZBuilder` instance. #### Response Example N/A ```