### Check vector capacity Source: https://docs.rs/toml/latest/toml/value/type.Array.html Examples showing how to inspect the capacity of a vector, including the behavior for zero-sized types. ```rust let mut vec: Vec = Vec::with_capacity(10); vec.push(42); assert!(vec.capacity() >= 10); ``` ```rust #[derive(Clone)] struct ZeroSized; fn main() { assert_eq!(std::mem::size_of::(), 0); let v = vec![ZeroSized; 0]; assert_eq!(v.capacity(), usize::MAX); } ``` -------------------------------- ### Vec::into_parts_with_alloc Example Source: https://docs.rs/toml/latest/toml/value/type.Array.html?search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Demonstrates how to extract the internal components of a Vec and reconstruct it using a specific allocator. This is an advanced usage for custom memory management. ```rust #![feature(allocator_api)] use std::alloc.System; let mut v: Vec = Vec::new_in(System); v.push(-1); v.push(0); v.push(1); let (ptr, len, cap, alloc) = v.into_parts_with_alloc(); let rebuilt = unsafe { // We can now make changes to the components, such as // transmuting the raw pointer to a compatible type. let ptr = ptr.cast::(); Vec::from_parts_in(ptr, len, cap, alloc) }; assert_eq!(rebuilt, [4294967295, 0, 1]); ``` -------------------------------- ### Vec::into_parts_with_alloc Example Source: https://docs.rs/toml/latest/toml/value/type.Array.html?search=u32+-%3E+bool Demonstrates converting a Vec into its raw components and rebuilding it with a different pointer type. Note the use of `unsafe` for pointer manipulation. ```rust #![feature(allocator_api)] use std::alloc::System; let mut v: Vec = Vec::new_in(System); v.push(-1); v.push(0); v.push(1); let (ptr, len, cap, alloc) = v.into_parts_with_alloc(); let rebuilt = unsafe { // We can now make changes to the components, such as // transmuting the raw pointer to a compatible type. let ptr = ptr.cast::(); Vec::from_parts_in(ptr, len, cap, alloc) }; assert_eq!(rebuilt, [4294967295, 0, 1]); ``` -------------------------------- ### Vec::capacity Example Source: https://docs.rs/toml/latest/toml/value/type.Array.html?search=u32+-%3E+bool Shows how to check the current capacity of a vector. The capacity is guaranteed to be at least the requested amount after `with_capacity`. ```rust let mut vec: Vec = Vec::with_capacity(10); vec.push(42); assert!(vec.capacity() >= 10); ``` -------------------------------- ### Serializing Rust Structs to TOML Source: https://docs.rs/toml/latest/toml/index.html?search=std%3A%3Avec Demonstrates how to serialize Rust structs into TOML format using Serde. ```APIDOC You can serialize types in a similar fashion: ```rust use serde::Serialize; #[derive(Serialize)] struct Config { ip: String, port: Option, keys: Keys, } #[derive(Serialize)] struct Keys { github: String, travis: Option, } let config = Config { ip: "127.0.0.1".to_string(), port: None, keys: Keys { github: "xxxxxxxxxxxxxxxxx".to_string(), travis: Some("yyyyyyyyyyyyyyyyy".to_string()), }, }; let toml = toml::to_string(&config).unwrap(); ``` ``` -------------------------------- ### Example Datetime value Source: https://docs.rs/toml/latest/toml/enum.Value.html An example of an ISO 8601 formatted datetime string used in TOML. ```text 1979-05-27T07:32:00Z ``` -------------------------------- ### TOML date specification example Source: https://docs.rs/toml/latest/toml/value/struct.Date.html An example of a local date value as defined in the TOML v1.0.0 specification. ```toml ld1 = 1979-05-27 ``` -------------------------------- ### impl CloneToUninit for T Source: https://docs.rs/toml/latest/toml/value/struct.DatetimeParseError.html This is a nightly-only experimental API. (`clone_to_uninit`) Performs copy-assignment from `self` to `dest`. ```rust unsafe fn clone_to_uninit(&self, dest: *mut u8) ``` -------------------------------- ### take Source: https://docs.rs/toml/latest/toml/map/struct.IterMut.html?search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Creates an iterator that yields the first `n` elements. ```APIDOC ## fn take(self, n: usize) -> Take ### Description Creates an iterator that yields at most the first `n` elements from the underlying iterator. If the underlying iterator yields fewer than `n` elements, all of them will be yielded. ### Method `take` ### Parameters - `n`: The maximum number of elements to yield. ``` -------------------------------- ### TOML Time Specification Examples Source: https://docs.rs/toml/latest/toml/value/struct.Time.html Examples of TOML local time values as defined in the TOML v1.0.0 specification. ```toml lt1 = 07:32:00 lt2 = 00:32:00.999999 ``` -------------------------------- ### take Source: https://docs.rs/toml/latest/toml/map/struct.IntoIter.html?search=u32+-%3E+bool Creates an iterator that yields the first `n` elements. ```APIDOC ## fn take(self, n: usize) -> Take ### Description Creates an iterator that yields the first `n` elements, or fewer if the underlying iterator ends sooner. ### Parameters - `n`: The maximum number of elements to yield. ### Returns A `Take` iterator. ``` -------------------------------- ### TOML time examples Source: https://docs.rs/toml/latest/toml/value/struct.Time.html?search= Examples of TOML time values, demonstrating local time without date or timezone information. Millisecond precision is required. ```toml lt1 = 07:32:00 ``` ```toml lt2 = 00:32:00.999999 ``` -------------------------------- ### take Source: https://docs.rs/toml/latest/toml/map/struct.IntoIter.html?search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Creates an iterator that yields the first `n` elements. ```APIDOC ## take(self, n: usize) -> Take ### Description Creates an iterator that yields the first `n` elements, or fewer if the underlying iterator ends sooner. ### Parameters - `n`: The maximum number of elements to yield. ``` -------------------------------- ### Local Date-Time Examples Source: https://docs.rs/toml/latest/toml/value/struct.Datetime.html Examples of Local Date-Time formats. These represent a specific date and time without a timezone offset, as per the TOML specification. ```toml ldt1 = 1979-05-27T07:32:00 ldt2 = 1979-05-27T00:32:00.999999 ``` -------------------------------- ### Vec::reserve_exact Example Source: https://docs.rs/toml/latest/toml/value/type.Array.html?search=u32+-%3E+bool Shows reserving the exact minimum additional capacity for a vector. Note that the allocator might still provide more space than requested. ```rust let mut vec = vec![1]; vec.reserve_exact(10); assert!(vec.capacity() >= 11); ``` -------------------------------- ### take Source: https://docs.rs/toml/latest/toml/map/struct.IterMut.html?search=u32+-%3E+bool Creates an iterator that yields the first `n` elements. ```APIDOC ## fn take(self, n: usize) -> Take ### Description Creates an iterator that yields the first `n` elements, or fewer if the underlying iterator ends sooner. ### Parameters #### Path Parameters - **n** (usize) - Description: The maximum number of elements to yield. ### Returns - **Take** - A new iterator that yields at most `n` elements. ``` -------------------------------- ### Offset Date-Time Examples Source: https://docs.rs/toml/latest/toml/value/struct.Datetime.html Examples of Offset Date-Time formats as defined by the TOML specification. These include RFC 3339 formatted strings with timezone offsets. ```toml odt1 = 1979-05-27T07:32:00Z odt2 = 1979-05-27T00:32:00-07:00 odt3 = 1979-05-27T00:32:00.999999-07:00 ``` ```toml odt4 = 1979-05-27 07:32:00Z ``` -------------------------------- ### Map Creation and Initialization Source: https://docs.rs/toml/latest/toml/map/struct.Map.html Methods for creating new Map instances, including empty maps and maps with a specified capacity. ```APIDOC ### `new()` Makes a new empty Map. ### `with_capacity(capacity: usize)` Available on **crate feature`preserve_order`** only. Makes a new empty Map with the given initial capacity. ``` -------------------------------- ### Get Map entry for manipulation Source: https://docs.rs/toml/latest/toml/type.Table.html?search=u32+-%3E+bool Gets the entry for a given key, allowing for in-place manipulation of the key-value pair. The key can be any type that can be converted into the map's key type `K`. ```rust pub fn entry(&mut self, key: S) -> Entry<'_, K, V> where S: Into, ``` -------------------------------- ### type_id Source: https://docs.rs/toml/latest/toml/map/struct.Map.html?search=u32+-%3E+bool Gets the `TypeId` of the `Map`. ```APIDOC ## fn type_id(&self) -> TypeId ### Description Gets the `TypeId` of `self`. ### Returns * `TypeId`: The unique identifier for the type of `self`. ``` -------------------------------- ### SerializeMap Initialization Source: https://docs.rs/toml/latest/src/toml/table.rs.html?search=std%3A%3Avec Provides constructors for `SerializeMap`, including `new` for a default empty map and `with_capacity` for pre-allocating space. ```rust impl SerializeMap { pub(crate) fn new() -> Self { Self { map: Table::new(), next_key: None, } } pub(crate) fn with_capacity(capacity: usize) -> Self { Self { map: Table::with_capacity(capacity), next_key: None, } } } ``` -------------------------------- ### Append Element and Get Mutable Reference Source: https://docs.rs/toml/latest/toml/value/type.Array.html?search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Use `push_mut` to append an element and immediately get a mutable reference to it. This is useful for modifying the newly added element in place. It also has amortized O(1) time complexity. ```rust let mut vec = vec![1, 2]; let last = vec.push_mut(3); assert_eq!(*last, 3); assert_eq!(vec, [1, 2, 3]); let last = vec.push_mut(3); *last += 1; assert_eq!(vec, [1, 2, 3, 4]); ``` -------------------------------- ### values Source: https://docs.rs/toml/latest/src/toml/map.rs.html?search= Gets an iterator over the values of the map. ```APIDOC ## values ### Description Returns an iterator over the values in the map. ### Signature `pub fn values(&self) -> Values<'_, K, V>` ``` -------------------------------- ### clone_to_uninit Source: https://docs.rs/toml/latest/toml/value/struct.Time.html This is a nightly-only experimental API. It performs copy-assignment from `self` to `dest`. ```APIDOC ## unsafe fn clone_to_uninit(&self, dest: *mut u8) ### Description This is a nightly-only experimental API. It performs copy-assignment from `self` to `dest`. ### Method unsafe fn ### Endpoint N/A ### Parameters #### Path Parameters N/A #### Query Parameters N/A #### Request Body N/A ### Request Example N/A ### Response #### Success Response (200) N/A #### Response Example N/A ``` -------------------------------- ### keys Source: https://docs.rs/toml/latest/src/toml/map.rs.html?search= Gets an iterator over the keys of the map. ```APIDOC ## keys ### Description Returns an iterator over the keys in the map. ### Signature `pub fn keys(&self) -> Keys<'_, K, V>` ``` -------------------------------- ### iter Source: https://docs.rs/toml/latest/src/toml/map.rs.html?search= Gets an iterator over the entries of the map. ```APIDOC ## iter ### Description Returns an iterator over the key-value pairs in the map. ### Signature `pub fn iter(&self) -> Iter<'_, K, V>` ``` -------------------------------- ### values Source: https://docs.rs/toml/latest/src/toml/map.rs.html?search=u32+-%3E+bool Gets an iterator over the values of the map. ```APIDOC ## values ### Description Gets an iterator over the values of the map. ### Signature `pub fn values(&self) -> Values<'_, K, V>` ``` -------------------------------- ### Initializing Vector Elements via `as_mut_ptr` Source: https://docs.rs/toml/latest/toml/value/type.Array.html?search=u32+-%3E+bool Shows how to initialize vector elements by writing directly to the raw mutable pointer obtained from `as_mut_ptr`, followed by setting the vector's length. Requires `unsafe` block. ```rust // Allocate vector big enough for 4 elements. let size = 4; let mut x: Vec = Vec::with_capacity(size); let x_ptr = x.as_mut_ptr(); // Initialize elements via raw pointer writes, then set length. unsafe { for i in 0..size { *x_ptr.add(i) = i as i32; } x.set_len(size); } assert_eq!(&*x, &[0, 1, 2, 3]); ``` -------------------------------- ### keys Source: https://docs.rs/toml/latest/src/toml/map.rs.html?search=u32+-%3E+bool Gets an iterator over the keys of the map. ```APIDOC ## keys ### Description Gets an iterator over the keys of the map. ### Signature `pub fn keys(&self) -> Keys<'_, K, V>` ``` -------------------------------- ### from_raw_parts_in Source: https://docs.rs/toml/latest/toml/value/type.Array.html?search= Creates a `Vec` directly from a pointer, a length, a capacity, and an allocator. This is a nightly-only experimental API. ```APIDOC ## pub const unsafe fn from_raw_parts_in( ptr: *mut T, length: usize, capacity: usize, alloc: A, ) -> Vec ### Description Creates a `Vec` directly from a pointer, a length, a capacity, and an allocator. ``` -------------------------------- ### iter Source: https://docs.rs/toml/latest/src/toml/map.rs.html?search=u32+-%3E+bool Gets an iterator over the entries of the map. ```APIDOC ## iter ### Description Gets an iterator over the entries of the map. ### Signature `pub fn iter(&self) -> Iter<'_, K, V>` ``` -------------------------------- ### Create new `SerializeMap` Source: https://docs.rs/toml/latest/src/toml/table.rs.html?search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Constructs a new `SerializeMap` instance with an empty TOML table and no pending key. ```rust pub(crate) fn new() -> Self { Self { map: Table::new(), next_key: None, } } ``` -------------------------------- ### Buffer::new Source: https://docs.rs/toml/latest/src/toml/ser/document/buffer.rs.html?search=u32+-%3E+bool Initializes a new, empty serialization buffer. ```APIDOC ## fn new() -> Buffer ### Description Initialize a new serialization buffer. ### Returns A new instance of `Buffer`. ``` -------------------------------- ### values Source: https://docs.rs/toml/latest/src/toml/map.rs.html?search=std%3A%3Avec Gets an iterator over the values of the map. ```APIDOC ## values ### Description Returns an iterator that yields references to the values in the map, in their iteration order. ### Method Signature `pub fn values(&self) -> Values<'_, K, V>` ``` -------------------------------- ### Map Struct and Initialization Source: https://docs.rs/toml/latest/src/toml/map.rs.html Details the `Map` struct and its initialization methods, including `new` and `with_capacity`. ```APIDOC ## Map Struct Represents a TOML key/value type. ### Fields - `map` (MapImpl) - The underlying map implementation. - `dotted` (bool) - Indicates if dotted keys are used. - `implicit` (bool) - Indicates if implicit keys are used. - `inline` (bool) - Indicates if the map is inlined. ## `Map::new()` ### Description Makes a new empty Map. ### Method `new()` ### Endpoint N/A (Constructor) ## `Map::with_capacity(capacity: usize)` ### Description Makes a new empty Map with the given initial capacity. ### Method `with_capacity(capacity: usize)` ### Endpoint N/A (Constructor) ### Note - The `with_capacity` method is only available when the `preserve_order` feature is enabled. - When `preserve_order` is not enabled, this method effectively calls `Map::new()` and the capacity is not guaranteed. ``` -------------------------------- ### keys Source: https://docs.rs/toml/latest/src/toml/map.rs.html?search=std%3A%3Avec Gets an iterator over the keys of the map. ```APIDOC ## keys ### Description Returns an iterator that yields references to the keys in the map, in their iteration order. ### Method Signature `pub fn keys(&self) -> Keys<'_, K, V>` ``` -------------------------------- ### Create Pretty TOML Serializer Source: https://docs.rs/toml/latest/toml/struct.Serializer.html Creates a new `Serializer` instance with a default "pretty" policy. For more customization, serialize to a `toml_edit::DocumentMut` instead. ```rust pub fn pretty(buf: &'d mut Buffer) -> Self ``` -------------------------------- ### Get Mutable Value by Index (Array or Map) Source: https://docs.rs/toml/latest/toml/enum.Value.html?search=u32+-%3E+bool Provides mutable access to a value within a TOML array or map. Similar to `get`, it uses string or usize indices and returns `None` on type mismatch or if the key/index is not found. ```rust pub fn get_mut(&mut self, index: I) -> Option<&mut Self> ``` -------------------------------- ### iter_mut Source: https://docs.rs/toml/latest/src/toml/map.rs.html?search= Gets a mutable iterator over the entries of the map. ```APIDOC ## iter_mut ### Description Returns a mutable iterator over the key-value pairs in the map. ### Signature `pub fn iter_mut(&mut self) -> IterMut<'_, K, V>` ``` -------------------------------- ### Create Vec from External Memory Source: https://docs.rs/toml/latest/toml/value/type.Array.html Shows how to initialize a Vec from memory allocated via a custom allocator using Vec::from_parts_in. ```rust #![feature(allocator_api)] use std::alloc::{AllocError, Allocator, Global, Layout}; fn main() { let layout = Layout::array::(16).expect("overflow cannot happen"); let vec = unsafe { let mem = match Global.allocate(layout) { Ok(mem) => mem.cast::(), Err(AllocError) => return, }; mem.write(1_000_000); Vec::from_parts_in(mem, 1, 16, Global) }; assert_eq!(vec, &[1_000_000]); assert_eq!(vec.capacity(), 16); } ``` -------------------------------- ### Begin Map Serialization Source: https://docs.rs/toml/latest/toml/ser/struct.Serializer.html?search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Initiates the serialization of a map. This must be followed by `serialize_key` and `serialize_value` calls for each entry, and a final `end` call. ```APIDOC ## fn serialize_map(self, _len: Option) -> Result ### Description Begin to serialize a map. This call must be followed by zero or more calls to `serialize_key` and `serialize_value`, then a call to `end`. ### Method `serialize_map` ### Parameters - `_len` (Option): The expected number of key-value pairs in the map, if known. ### Return Value A `Result` containing a `SerializeMap` struct for further key-value pair serialization, or an error. ``` -------------------------------- ### OccupiedEntry::get Source: https://docs.rs/toml/latest/src/toml/map.rs.html?search=u32+-%3E+bool Gets a reference to the value in the entry. ```APIDOC ## OccupiedEntry::get ### Description Gets a reference to the value in the entry. ### Signature ```rust pub fn get(&self) -> &V ``` ``` -------------------------------- ### OccupiedEntry::key Source: https://docs.rs/toml/latest/src/toml/map.rs.html?search=u32+-%3E+bool Gets a reference to the key in the entry. ```APIDOC ## OccupiedEntry::key ### Description Gets a reference to the key in the entry. ### Signature ```rust pub fn key(&self) -> &K ``` ``` -------------------------------- ### From> for Vec Source: https://docs.rs/toml/latest/toml/value/type.Array.html Converts a BinaryHeap into a Vec. This conversion requires no data movement or allocation, and has constant time complexity. ```APIDOC ## fn from(heap: BinaryHeap) -> Vec ### Description Converts a `BinaryHeap` into a `Vec`. ### Method `from` ### Endpoint N/A (Implementation of From trait for Vec) ### Parameters - **heap** (*BinaryHeap*) - Required - The binary heap to convert. ### Request Body None ### Response #### Success Response (200) - **Vec** - A vector containing the elements from the binary heap. ``` -------------------------------- ### iter_mut Source: https://docs.rs/toml/latest/src/toml/map.rs.html?search=u32+-%3E+bool Gets a mutable iterator over the entries of the map. ```APIDOC ## iter_mut ### Description Gets a mutable iterator over the entries of the map. ### Signature `pub fn iter_mut(&mut self) -> IterMut<'_, K, V>` ``` -------------------------------- ### Initializing SerializeDatetime Source: https://docs.rs/toml/latest/src/toml/ser/value/map.rs.html?search=std%3A%3Avec The `new` function creates a `SerializeDatetime` instance, initializing the inner datetime serializer. ```rust impl<'d> SerializeDatetime<'d> { pub(crate) fn new(dst: &'d mut String) -> Self { Self { dst, inner: toml_datetime::ser::DatetimeSerializer::new(), } } } ``` -------------------------------- ### Vec::try_reserve_exact Example Source: https://docs.rs/toml/latest/toml/value/type.Array.html?search=u32+-%3E+bool Demonstrates attempting to reserve the exact minimum additional capacity, returning a `Result`. This method is preferred when precise capacity control is needed and OOM errors must be handled. ```rust use std::collections::TryReserveError; fn process_data(data: &[u32]) -> Result, TryReserveError> { let mut output = Vec::new(); // Pre-reserve the memory, exiting if we can't output.try_reserve_exact(data.len())?; // Now we know this can't OOM in the middle of our complex work output.extend(data.iter().map(|&val| { val * 2 + 5 // very complicated })); Ok(output) } ``` -------------------------------- ### fn type_id(&self) -> TypeId Source: https://docs.rs/toml/latest/toml/struct.Spanned.html?search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Gets the `TypeId` of `self`. ```APIDOC ## fn type_id(&self) -> TypeId ### Description Gets the `TypeId` of `self`. ### Returns The `TypeId` of the underlying type. ``` -------------------------------- ### type_id Source: https://docs.rs/toml/latest/toml/map/struct.Iter.html?search= Gets the TypeId of an object. This is part of the Any trait implementation. ```APIDOC #### fn type_id(&self) -> TypeId Gets the `TypeId` of `self`. Read more ``` -------------------------------- ### OccupiedEntry::get Method Source: https://docs.rs/toml/latest/src/toml/map.rs.html?search= Gets a reference to the value in the entry. ```rust pub fn get(&self) -> &V { self.occupied.get() } ``` -------------------------------- ### Initializing SerializeTable Source: https://docs.rs/toml/latest/src/toml/ser/value/map.rs.html?search=std%3A%3Avec The `map` function initializes a `SerializeTable` and opens an inline table in the destination string. ```rust impl<'d> SerializeTable<'d> { pub(crate) fn map(dst: &'d mut String, style: Style) -> Result { dst.open_inline_table()?; Ok(Self { dst, seen_value: false, ``` -------------------------------- ### Map::new Source: https://docs.rs/toml/latest/toml/map/struct.Map.html?search=std%3A%3Avec Creates a new, empty `Map`. ```APIDOC ## Map::new ### Description Makes a new empty Map. ### Method ```rust pub fn new() -> Self ``` ``` -------------------------------- ### OccupiedEntry::key Method Source: https://docs.rs/toml/latest/src/toml/map.rs.html?search= Gets a reference to the key in the entry. ```rust pub fn key(&self) -> &K { self.occupied.key() } ``` -------------------------------- ### OccupiedEntry::get_mut Source: https://docs.rs/toml/latest/src/toml/map.rs.html?search=u32+-%3E+bool Gets a mutable reference to the value in the entry. ```APIDOC ## OccupiedEntry::get_mut ### Description Gets a mutable reference to the value in the entry. ### Signature ```rust pub fn get_mut(&mut self) -> &mut V ``` ``` -------------------------------- ### Try Shrink to Fit (Experimental) Source: https://docs.rs/toml/latest/toml/value/type.Array.html Tries to shrink the capacity of the vector as much as possible. This is a nightly-only experimental API and returns a `Result` indicating success or failure. ```APIDOC ## pub fn try_shrink_to_fit(&mut self) -> Result<(), TryReserveError> ### Description Tries to shrink the capacity of the vector as much as possible. The behavior depends on the allocator. Returns an error if the allocator fails to shrink the allocation. ### Method `&mut self` ### Endpoint N/A (Method on Vec) ### Parameters None ### Request Example ```rust #![feature(vec_fallible_shrink)] let mut vec = Vec::with_capacity(10); vec.extend([1, 2, 3]); assert!(vec.capacity() >= 10); vec.try_shrink_to_fit().expect("Allocator failed to shrink"); assert!(vec.capacity() >= 3); ``` ### Response #### Success Response (Ok) - **()** - Indicates successful shrinking. #### Error Response (Err) - **TryReserveError** - Returned if the allocator fails to shrink the allocation. ``` -------------------------------- ### Define TOML configuration Source: https://docs.rs/toml/latest/index.html Example of a basic TOML configuration structure. ```toml [package] name = "toml" [dependencies] serde = "1.0" ``` -------------------------------- ### new_in Source: https://docs.rs/toml/latest/toml/value/type.Array.html?search= Constructs a new, empty `Vec` with the specified allocator. This is a nightly-only experimental API. ```APIDOC ## pub const fn new_in(alloc: A) -> Vec ### Description Constructs a new, empty `Vec`. The vector will not allocate until elements are pushed onto it. ### Examples ``` #![feature(allocator_api)] use std::alloc::System; let mut vec: Vec = Vec::new_in(System); ``` ``` -------------------------------- ### Serializer Initialization Source: https://docs.rs/toml/latest/src/toml/ser/document/mod.rs.html Methods for creating and configuring a new TOML document serializer. ```APIDOC ## Serializer::new ### Description Creates a new serializer which will emit TOML into the provided buffer. ### Parameters - **buf** (&mut Buffer) - Required - The buffer where the serialized TOML will be stored. ## Serializer::pretty ### Description Creates a new serializer with a default 'pretty' policy applied, such as enabling multiline arrays. ### Parameters - **buf** (&mut Buffer) - Required - The buffer where the serialized TOML will be stored. ``` -------------------------------- ### Get Vec Length Source: https://docs.rs/toml/latest/toml/value/type.Array.html?search=u32+-%3E+bool Returns the number of elements currently in the vector. ```rust let a = vec![1, 2, 3]; assert_eq!(a.len(), 3); ``` -------------------------------- ### Get vector length Source: https://docs.rs/toml/latest/toml/value/type.Array.html Returns the number of elements currently in the vector. ```rust let a = vec![1, 2, 3]; assert_eq!(a.len(), 3); ``` -------------------------------- ### Create Pretty Serializer Source: https://docs.rs/toml/latest/toml/ser/struct.Serializer.html?search=std%3A%3Avec Creates a new `Serializer` instance with a default "pretty" policy applied to the TOML document. For more advanced customization, consider serializing directly to a `toml_edit::DocumentMut`. ```rust pub fn pretty(buf: &'d mut Buffer) -> Self ``` -------------------------------- ### Try Shrink to Minimum Capacity (Experimental) Source: https://docs.rs/toml/latest/toml/value/type.Array.html Tries to shrink the capacity of the vector with a lower bound, returning a `Result`. This is a nightly-only experimental API. ```APIDOC ## pub fn try_shrink_to(&mut self, min_capacity: usize) -> Result<(), TryReserveError> ### Description Tries to shrink the capacity of the vector with a lower bound. The capacity will remain at least as large as both the length and the supplied `min_capacity`. Returns an error if the allocator fails to shrink the allocation. ### Method `&mut self` ### Endpoint N/A (Method on Vec) ### Parameters #### Query Parameters - **min_capacity** (usize) - Required - The minimum capacity to maintain. ### Request Example ```rust #![feature(vec_fallible_shrink)] let mut vec = Vec::with_capacity(10); vec.extend([1, 2, 3]); assert!(vec.capacity() >= 10); vec.try_shrink_to(4).expect("Allocator failed to shrink"); assert!(vec.capacity() >= 4); vec.try_shrink_to(0).expect("No-op shrink"); assert!(vec.capacity() >= 3); ``` ### Response #### Success Response (Ok) - **()** - Indicates successful shrinking. #### Error Response (Err) - **TryReserveError** - Returned if the allocator fails to shrink the allocation. ``` -------------------------------- ### impl AsRef for Spanned Source: https://docs.rs/toml/latest/toml/struct.Spanned.html?search=u32+-%3E+bool Provides a way to get a reference to the contained value. ```APIDOC ### impl AsRef for Spanned Source #### fn as_ref(&self) -> &T Converts this type into a shared reference of the (usually inferred) input type. ``` -------------------------------- ### Map::new Source: https://docs.rs/toml/latest/toml/map/struct.Map.html?search=u32+-%3E+bool Creates a new, empty Map. ```APIDOC ## Map::new ### Description Makes a new empty Map. ### Signature ```rust pub fn new() -> Self ``` ``` -------------------------------- ### Any Trait Implementation Source: https://docs.rs/toml/latest/toml/map/struct.Values.html?search= Provides the `type_id` method to get the `TypeId` of the implementing type. ```APIDOC ## impl Any for T where T: 'static + ?Sized, #### fn type_id(&self) -> TypeId Gets the `TypeId` of `self`. Read more ``` -------------------------------- ### Initialize Map Serialization in Rust TOML Source: https://docs.rs/toml/latest/src/toml/value.rs.html Prepares for serializing a map (like a HashMap) by creating a ValueSerializeMap. Uses an internal serializer for map entries. ```rust fn serialize_map(self, _len: Option) -> Result { Ok(ValueSerializeMap { ser: crate::table::SerializeMap::new(), }) } ``` -------------------------------- ### key Source: https://docs.rs/toml/latest/toml/map/struct.VacantEntry.html?search=u32+-%3E+bool Gets a reference to the key that would be used when inserting a value through the `VacantEntry`. ```APIDOC ## VacantEntry::key `pub fn key(&self) -> &K` ### Description Gets a reference to the key that would be used when inserting a value through the `VacantEntry`. ### Returns A reference to the key. ``` -------------------------------- ### Begin Tuple Serialization Source: https://docs.rs/toml/latest/toml/ser/struct.Serializer.html?search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Initiates the serialization of a tuple with a known, fixed length. This must be followed by `serialize_element` calls and a final `end` call. ```APIDOC ## fn serialize_tuple(self, len: usize) -> Result ### Description Begin to serialize a statically sized sequence whose length will be known at deserialization time without looking at the serialized data. This call must be followed by zero or more calls to `serialize_element`, then a call to `end`. ### Method `serialize_tuple` ### Parameters - `len` (usize): The exact number of elements in the tuple. ### Return Value A `Result` containing a `SerializeTuple` struct for further element serialization, or an error. ``` -------------------------------- ### Get Iterator Over Values Source: https://docs.rs/toml/latest/toml/map/struct.Map.html?search= Returns an iterator that yields references to the values in the map. ```rust pub fn values(&self) -> Values<'_, K, V> ``` -------------------------------- ### Get Iterator Over Keys Source: https://docs.rs/toml/latest/toml/map/struct.Map.html?search= Returns an iterator that yields references to the keys in the map. ```rust pub fn keys(&self) -> Keys<'_, K, V> ``` -------------------------------- ### from_raw_parts_in Source: https://docs.rs/toml/latest/toml/value/type.Array.html?search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Creates a Vec directly from a pointer, a length, a capacity, and an allocator. This is a nightly-only experimental API. ```APIDOC ## from_raw_parts_in ### Description Creates a `Vec` directly from a pointer, a length, a capacity, and an allocator. ### Method `unsafe fn from_raw_parts_in(ptr: *mut T, length: usize, capacity: usize, alloc: A) -> Vec` ### Constraints `A: Allocator` ### Notes This is a nightly-only experimental API. (`allocator_api`) ``` -------------------------------- ### from_raw_parts_in Source: https://docs.rs/toml/latest/toml/value/type.Array.html?search=u32+-%3E+bool Creates a Vec directly from a pointer, a length, a capacity, and an allocator. This is a nightly-only experimental API. ```APIDOC ## from_raw_parts_in ### Description Creates a `Vec` directly from a pointer, a length, a capacity, and an allocator. ### Method `unsafe fn from_raw_parts_in( ptr: *mut T, length: usize, capacity: usize, alloc: A, ) -> Vec` ### Notes This is a nightly-only experimental API. (`allocator_api`) ``` -------------------------------- ### Get Map Length Source: https://docs.rs/toml/latest/toml/map/struct.Map.html?search= Returns the number of elements currently stored in the map. ```rust pub fn len(&self) -> usize ``` -------------------------------- ### DoubleEndedIterator::rfold() Source: https://docs.rs/toml/latest/toml/map/struct.IntoIter.html?search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Applies a closure to accumulate values starting from the back of the iterator. ```rust fn rfold(self, init: B, f: F) -> B where Self: Sized, F: FnMut(B, Self::Item) -> B, ``` -------------------------------- ### Initialize Vec from External Memory Source: https://docs.rs/toml/latest/toml/value/type.Array.html Shows how to create a Vec from a raw pointer allocated via the global allocator, ensuring the layout matches the requirements of the Vec. ```rust #![feature(box_vec_non_null)] use std::alloc::{alloc, Layout}; use std::ptr::NonNull; fn main() { let layout = Layout::array::(16).expect("overflow cannot happen"); let vec = unsafe { let Some(mem) = NonNull::new(alloc(layout).cast::()) else { return; }; mem.write(1_000_000); Vec::from_parts(mem, 1, 16) }; assert_eq!(vec, &[1_000_000]); assert_eq!(vec.capacity(), 16); } ``` -------------------------------- ### TOML Example Structure Source: https://docs.rs/toml/latest/toml/index.html?search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Illustrates a basic TOML structure for package information and dependencies. ```toml [package] name = "toml" [dependencies] serde = "1.0" ``` -------------------------------- ### CloneToUninit Trait Implementation Source: https://docs.rs/toml/latest/toml/struct.Spanned.html?search= Nightly-only experimental API for cloning to uninitialized memory. ```APIDOC ### impl CloneToUninit for T #### unsafe fn clone_to_uninit(&self, dest: *mut u8) Performs copy-assignment from `self` to `dest`. ``` -------------------------------- ### Generic `CloneToUninit::clone_to_uninit` (Nightly Experimental) Source: https://docs.rs/toml/latest/toml/ser/struct.Error.html?search=u32+-%3E+bool Performs copy-assignment from `self` to an uninitialized memory location. This is an experimental API available only on nightly Rust. ```rust unsafe fn clone_to_uninit(&self, dest: *mut u8) ``` -------------------------------- ### impl AsMut for Spanned Source: https://docs.rs/toml/latest/toml/struct.Spanned.html?search=u32+-%3E+bool Provides a way to get a mutable reference to the contained value. ```APIDOC ### impl AsMut for Spanned Source #### fn as_mut(&mut self) -> &mut T Converts this type into a mutable reference of the (usually inferred) input type. ``` -------------------------------- ### GetTypeId Method for Any Trait Source: https://docs.rs/toml/latest/toml/map/struct.VacantEntry.html Gets the TypeId of self. This method is part of the Any trait implementation. ```rust fn type_id(&self) -> TypeId ``` -------------------------------- ### Rebuild Vec from parts with allocator Source: https://docs.rs/toml/latest/toml/value/type.Array.html Demonstrates using into_parts_with_alloc and from_parts_in to manipulate vector components directly. ```rust #![feature(allocator_api)] use std::alloc::System; let mut v: Vec = Vec::new_in(System); v.push(-1); v.push(0); v.push(1); let (ptr, len, cap, alloc) = v.into_parts_with_alloc(); let rebuilt = unsafe { // We can now make changes to the components, such as // transmuting the raw pointer to a compatible type. let ptr = ptr.cast::(); Vec::from_parts_in(ptr, len, cap, alloc) }; assert_eq!(rebuilt, [4294967295, 0, 1]); ``` -------------------------------- ### Vec::try_with_capacity_in (Nightly) Source: https://docs.rs/toml/latest/toml/value/type.Array.html Constructs a new, empty Vec with a specified capacity and allocator. This is a nightly-only experimental API. ```APIDOC ## pub fn try_with_capacity_in( capacity: usize, alloc: A, ) -> Result, TryReserveError> ### Description Constructs a new, empty `Vec` with at least the specified capacity with the provided allocator. The vector will be able to hold at least `capacity` elements without reallocating. This method is allowed to allocate for more elements than `capacity`. If `capacity` is zero, the vector will not allocate. ### Method `try_with_capacity_in` ### Parameters - **capacity** (usize) - The minimum capacity for the vector. - **alloc** (A) - The allocator to use for this vector. ### Errors Returns an error if the capacity exceeds `isize::MAX` _bytes_ , or if the allocator reports allocation failure. ### Response #### Success Response (200) - **vec** (Vec) - A new, empty vector with the specified capacity and allocator. #### Error Response (non-200) - **TryReserveError** - An error indicating allocation failure or capacity overflow. ### Note This API is experimental and requires the `allocator_api` feature. ``` -------------------------------- ### Get Reference to Value Source: https://docs.rs/toml/latest/toml/map/struct.OccupiedEntry.html?search= Retrieves an immutable reference to the value associated with the occupied entry. ```rust pub fn get(&self) -> &V ``` -------------------------------- ### From Conversions Source: https://docs.rs/toml/latest/src/toml/value.rs.html?search=std%3A%3Avec Enables creating `Value` instances from various Rust types. ```APIDOC ## From Conversions ### Description Provides implementations for `From` trait to convert common Rust types into `toml::Value`. ### Supported Conversions: - `&str` to `Value::String` - `String` to `Value::String` - `Vec` (where `V: Into`) to `Value::Array` - `BTreeMap` (where `S: Into`, `V: Into`) to `Value::Table` - `HashMap` (where `S: Into + Hash + Eq`, `V: Into`) to `Value::Table` (requires `std` feature) - Primitive types like `i64`, `f64`, `bool`, `Datetime` to their corresponding `Value` variants. ### Example Usage: ```rust use toml::Value; let string_val: Value = "hello".into(); let array_val: Value = vec![1, 2, 3].into(); let mut map = std::collections::BTreeMap::new(); map.insert("key", "value"); let table_val: Value = map.into(); ``` ``` -------------------------------- ### entry Source: https://docs.rs/toml/latest/src/toml/map.rs.html?search= Gets the given key's corresponding entry in the map for in-place manipulation. ```APIDOC ## entry ### Description Provides access to an entry in the map, allowing for in-place modification or insertion. ### Signature `pub fn entry(&mut self, key: S) -> Entry<'_, K, V>` ### Type Parameters * `S`: The type of the key to look up. Must be convertible into `K`. ``` -------------------------------- ### Creating a New Table Source: https://docs.rs/toml/latest/src/toml/ser/document/buffer.rs.html?search=std%3A%3Avec Initializes and returns a new Table struct, adding it to the buffer's internal storage. ```rust pub(crate) fn new_table(&mut self, key: Option>) -> Table { let pos = self.tables.len(); let table = Table { key, body: String::new(), has_children: false, pos, array: false, }; self.tables.push(None); table } ``` -------------------------------- ### VacantEntry::key Source: https://docs.rs/toml/latest/src/toml/map.rs.html?search=u32+-%3E+bool Gets a reference to the key that would be used when inserting a value through the `VacantEntry`. ```APIDOC ## VacantEntry::key ### Description Gets a reference to the key that would be used when inserting a value through the `VacantEntry`. ### Signature ```rust pub fn key(&self) -> &K ``` ``` -------------------------------- ### Buffer Implementations Source: https://docs.rs/toml/latest/toml/ser/struct.Buffer.html?search=std%3A%3Avec Details on the implementations for the `Buffer` struct, including `Debug`, `Default`, and `Display` traits. ```APIDOC ## Buffer Implementations ### Debug Implements the `Debug` trait for the `Buffer` struct, allowing it to be formatted for debugging purposes. ### Default Implements the `Default` trait, providing a default value for the `Buffer` struct. ### Display Implements the `Display` trait for the `Buffer` struct, enabling it to be formatted as a string. ``` -------------------------------- ### entry Source: https://docs.rs/toml/latest/src/toml/map.rs.html?search=u32+-%3E+bool Gets the given key's corresponding entry in the map for in-place manipulation. ```APIDOC ## entry ### Description Gets the given key's corresponding entry in the map for in-place manipulation. ### Signature `pub fn entry(&mut self, key: S) -> Entry<'_, K, V>` ### Type Parameters * `S`: The type that can be converted into the map's key type `K`. ```