### Vec::allocator() Method Example (Rust) Source: https://docs.rs/unsynn/latest/unsynn/expressions/struct.RightAssocExpr_search= Provides an example of the `allocator()` method for `Vec`, which returns a reference to the underlying allocator. Note that this is an experimental, nightly-only API. ```rust #![feature(allocator_api)] use std::vec::Vec; fn main() { let v: Vec = Vec::new(); let allocator = v.allocator(); // Use the allocator reference... } ``` -------------------------------- ### Example Usage of AnyOf in Rust Source: https://docs.rs/unsynn/latest/unsynn/struct.AnyOf_search= Demonstrates how to use the `AnyOf` struct with different combinations of predicates. It shows examples with two predicates and four predicates, verifying success or failure based on the predicate outcomes. ```rust use unsynn::*; let mut tokens = "".to_token_iter(); // Two predicates assert!(AnyOf::::parse(&mut tokens).is_ok()); assert!(AnyOf::::parse(&mut tokens).is_err()); // Four predicates assert!(AnyOf::::parse(&mut tokens).is_ok()); ``` -------------------------------- ### Example Usage of PostfixExpr Source: https://docs.rs/unsynn/latest/unsynn/expressions/struct.PostfixExpr Demonstrates how to parse a string into a PostfixExpr and how to define a PostfixExpr with a limited number of operators. This example uses a custom 'Number' type and a 'Bang' operator. ```rust unsynn! { type Number = LiteralInteger; } // Parse "5 ! !" let mut tokens = "5 ! !".to_token_iter(); let expr: PostfixExpr = tokens.parse().unwrap(); assert_eq!(expr.operators.len(), 2); // 2 Bang operators // Limit postfix depth type LimitedPostfix = PostfixExpr; // Max 3 postfix operators ``` -------------------------------- ### format_literal Macro Usage Example (Rust) Source: https://docs.rs/unsynn/latest/unsynn/macro.format_literal_search= An example demonstrating the usage of the `format_literal` macro. It shows how to create a `Literal` from a format string and asserts its equality with an expected string literal. ```rust use unsynn::*; let literal = format_literal!("123{}", ".456"); assert_tokens_eq!(literal, str "123.456"); ``` -------------------------------- ### Example Usage of EndOfStream Parser in Rust Source: https://docs.rs/unsynn/latest/unsynn/fundamental/struct.EndOfStream_search= Demonstrates how to use the `parser` method of `EndOfStream` to consume tokens from an iterator. This example shows matching the end of a stream. ```rust let mut token_iter = "".to_token_iter(); let _end_ = EndOfStream::parser(&mut token_iter).unwrap(); ``` -------------------------------- ### Parse Postfix Expression Example in Rust Source: https://docs.rs/unsynn/latest/unsynn/struct.PostfixExpr_search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Demonstrates parsing a postfix expression using the PostfixExpr struct. This example shows how to parse a string with an integer operand and multiple '!' operators, verifying the number of operators parsed. ```rust unsynn! { type Number = LiteralInteger; } // Parse "5 ! !" let mut tokens = "5 ! !".to_token_iter(); let expr: PostfixExpr = tokens.parse().unwrap(); assert_eq!(expr.operators.len(), 2); // 2 Bang operators ``` -------------------------------- ### Example Usage of Expect Parser in Rust Source: https://docs.rs/unsynn/latest/unsynn/fundamental/struct.Expect Demonstrates how to use the `Expect::::parser` in Rust to parse an identifier token from a `TokenIter`. This example shows a successful parse of the token 'ident'. ```rust let mut token_iter = "ident".to_token_iter(); let _ = Expect::::parser(&mut token_iter).unwrap(); ``` -------------------------------- ### Example of using Insert struct in Rust Source: https://docs.rs/unsynn/latest/unsynn/struct.Insert Demonstrates how to use the `Insert` struct with a token iterator. This example shows parsing a sequence of tokens including an identifier, an inserted plus sign, and another identifier. ```rust let mut token_iter = "foo bar".to_token_iter(); let parsed = , Ident>>::parser(&mut token_iter).unwrap(); assert_tokens_eq!(parsed, "foo + bar"); ``` -------------------------------- ### Example Usage of PunctAlone in Rust Source: https://docs.rs/unsynn/latest/unsynn/punct/struct.PunctAlone_search=u32+-%3E+bool Demonstrates how to parse a PunctAlone token from a token iterator. This example shows creating a token iterator and then parsing two consecutive colon punctuation tokens. ```rust let mut token_iter = ": :".to_token_iter(); let colon = PunctAlone::<':'>::parse(&mut token_iter).unwrap(); let colon = PunctAlone::<':'>::parse(&mut token_iter).unwrap(); ``` -------------------------------- ### Rust: Get Start Line/Column of Span Source: https://docs.rs/unsynn/latest/unsynn/struct.Span Retrieves the starting line and column number of the span in the source file. Requires the 'span-locations' feature, and accuracy within procedural macros depends on the toolchain. ```rust pub fn start(&self) -> LineColumn ``` -------------------------------- ### Get Vector Length Source: https://docs.rs/unsynn/latest/unsynn/expressions/struct.RightAssocExpr_search=u32+-%3E+bool Provides an example of how to retrieve the number of elements currently stored in a vector, also known as its length. ```Rust let a = vec![1, 2, 3]; assert_eq!(a.len(), 3); ``` -------------------------------- ### Get Underlying Allocator (Rust - Nightly) Source: https://docs.rs/unsynn/latest/unsynn/expressions/struct.RightAssocExpr_search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Provides an example of retrieving a reference to the allocator used by a vector. Note that this is an experimental API and requires the nightly Rust toolchain. ```Rust #![feature(allocator_api)] fn get_allocator(vec: &Vec) -> &A { vec.allocator() } ``` -------------------------------- ### Enable Struct and Parsing Source: https://docs.rs/unsynn/latest/unsynn/predicates/struct.Enable_search=u32+-%3E+bool Documentation for the `Enable` struct, including its purpose, usage examples, and the `Parser` trait implementation. ```APIDOC ## Struct Enable ### Description Always succeeds without consuming tokens. ### Method `Enable::parse(tokens: &mut TokenIter) -> Result` ### Endpoint N/A (This is a library function, not an HTTP endpoint) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```rust use unsynn::* let mut tokens = "foo bar".to_token_iter(); let result = Enable::parse(&mut tokens); assert!(result.is_ok()); assert_eq!(tokens.clone().count(), 2); // No tokens consumed ``` ### Response #### Success Response (200) - **Enable** (struct) - Represents a successful parse operation. #### Response Example ```json { "success": true } ``` ## Trait Implementations for Enable ### impl Parser for Enable #### fn parser(_tokens: &mut TokenIter) -> Result **Description**: The actual parsing function that must be implemented. This mutates the `tokens` iterator directly. It should not be called from user code except for implementing parsers itself and then only when the rules below are followed. ### impl Clone for Enable #### fn clone(&self) -> Enable **Description**: Returns a duplicate of the value. #### fn clone_from(&mut self, source: &Self) **Description**: Performs copy-assignment from `source`. ### impl Debug for Enable #### fn fmt(&self, f: &mut Formatter<'_>) -> Result **Description**: Formats the value using the given formatter. ### impl Default for Enable #### fn default() -> Enable **Description**: Returns the “default value” for a type. ### impl ToTokens for Enable #### fn to_tokens(&self, _tokens: &mut TokenStream) **Description**: Write `&self` to the given `TokenStream`. #### fn to_token_iter(&self) -> TokenIter **Description**: Convert `&self` into a `TokenIter` object. #### fn into_token_iter(self) -> TokenIter **Description**: Convert `self` into a `TokenIter` object. #### fn to_token_stream(&self) -> TokenStream **Description**: Convert `&self` into a `TokenStream` object. #### fn into_token_stream(self) -> TokenStream **Description**: Convert `self` into a `TokenStream` object. #### fn tokens_to_string(&self) -> String **Description**: Convert `&self` into a `String` object. This is mostly used in the test suite to compare the outputs. When the input is a `&str` then this parses it and returns a normalized `String`. ### impl PredicateOp for Enable **Description**: Indicates that `Enable` can be used as a predicate operation. ``` -------------------------------- ### Conversion Utilities (TryFrom, TryInto, Into) Source: https://docs.rs/unsynn/latest/unsynn/struct.IntoIdent_search= Documentation for type conversion utilities, including `TryFrom`, `TryInto`, and `Into` traits, enabling safe and standard conversions between types. ```APIDOC ## Conversion Utilities ### Description This section covers the standard Rust traits for type conversions: `TryFrom`, `TryInto`, and `Into`. ### `impl TryFrom for T` * **Description**: Enables attempting a conversion from type `U` into type `T`. This conversion might fail, hence the use of `Result`. * **Type Alias**: `type Error = Infallible` - The type returned in the event of a conversion error. `Infallible` indicates that this specific `TryFrom` implementation cannot fail. * **Method**: `fn try_from(value: U) -> Result>::Error>` * **Description**: Performs the conversion from `value` of type `U` to type `T`. * **Parameters**: * `value` (*U*) - Required - The value to convert. * **Returns**: `Result` - The converted value if successful. ``` ```APIDOC ### `impl TryInto for T` * **Description**: Enables attempting a conversion from type `T` into type `U`. This is the reciprocal of `TryFrom` and also returns a `Result`. * **Type Alias**: `type Error = >::Error` - The type returned in the event of a conversion error, which is determined by the `TryFrom` implementation for `U` from `T`. * **Method**: `fn try_into(self) -> Result>::Error>` * **Description**: Performs the conversion from `self` (type `T`) to type `U`. * **Parameters**: * `self` (*T*) - Required - The value to convert. * **Returns**: `Result>::Error>` - The converted value if successful, or an error if the conversion fails. ``` ```APIDOC ### `fn into(self) -> U` * **Description**: Calls `U::from(self)`. This conversion is guaranteed to succeed and is defined by the implementation of `From for U`. * **Method**: `fn into(self) -> U` * **Description**: Performs a conversion from `self` (type `T`) into type `U` using the `From` trait implementation. * **Parameters**: * `self` (*T*) - Required - The value to convert. * **Returns**: `U` - The converted value. ``` -------------------------------- ### Get Pointer Range of Slice in Rust Source: https://docs.rs/unsynn/latest/unsynn/container/struct.DelimitedVec_search=u32+-%3E+bool The `as_ptr_range` method returns a `Range` of raw pointers representing the start and end of the slice in memory. This is useful for interacting with foreign interfaces or checking if a pointer belongs to the slice. The end pointer points one past the last element. ```Rust let a = [1, 2, 3]; let x = &a[1] as *const _; let y = &5 as *const _; assert!(a.as_ptr_range().contains(&x)); assert!(!a.as_ptr_range().contains(&y)); ``` -------------------------------- ### Example Usage of Except Parser in Rust Source: https://docs.rs/unsynn/latest/unsynn/fundamental/struct.Except Demonstrates how to use the `Except` parser with a `TokenIter`. This example shows creating a `TokenIter` from a string and then attempting to parse using `Except::::parser`, expecting it to succeed if the next token is not a punctuation mark. ```rust let mut token_iter = "ident".to_token_iter(); let _ = Except::::parser(&mut token_iter).unwrap(); ``` -------------------------------- ### Accessing File Metadata with Result in Rust Source: https://docs.rs/unsynn/latest/unsynn/type.Result_search=u32+-%3E+bool Illustrates using `Result` to handle potential errors when accessing file metadata. The example attempts to get metadata for the root directory and a non-existent path, demonstrating successful retrieval and error handling using `and_then` and checking the error kind. ```rust use std::{io::ErrorKind, path::Path}; // Note: on Windows "/" maps to "C:\\" let root_modified_time = Path::new("/").metadata().and_then(|md| md.modified()); assert!(root_modified_time.is_ok()); let should_fail = Path::new("/bad/path").metadata().and_then(|md| md.modified()); assert!(should_fail.is_err()); assert_eq!(should_fail.unwrap_err().kind(), ErrorKind::NotFound); ``` -------------------------------- ### Safely Get Multiple Disjoint Mutable Slice Elements (Rust) Source: https://docs.rs/unsynn/latest/unsynn/expressions/struct.RightAssocExpr_search=u32+-%3E+bool Provides an example of using the safe `get_disjoint_mut` function to obtain multiple mutable references to disjoint parts of a slice. This method includes checks for out-of-bounds or overlapping indices, returning a `Result` to indicate success or failure. ```Rust let mut slice = [1, 2, 3, 4, 5]; let indices = [0, 2, 4]; match slice.get_disjoint_mut(indices) { Ok(refs) => { let [a, b, c] = refs; *a = 10; *b = 20; *c = 30; } Err(_) => { // Handle error: indices are out of bounds or overlapping } } assert_eq!(slice, [10, 2, 20, 4, 30]); ``` ```Rust let mut slice = [1, 2, 3, 4, 5]; let indices = [0..2, 3..5]; match slice.get_disjoint_mut(indices) { Ok(refs) => { let [a, b] = refs; a[0] = 11; a[1] = 22; b[0] = 33; b[1] = 44; } Err(_) => { // Handle error } } assert_eq!(slice, [11, 22, 33, 44, 5]); ``` -------------------------------- ### Recommended Usage of expect for Environment Variables in Rust Source: https://docs.rs/unsynn/latest/unsynn/type.Result_search= Provides a best practice example for using `expect` to retrieve environment variables, emphasizing clear messages that explain why the variable is expected to be set. ```rust let path = std::env::var("IMPORTANT_PATH") .expect("env variable `IMPORTANT_PATH` should be set by `wrapper_script.sh`"); ``` -------------------------------- ### Get Mutable Pointer Range of Slice in Rust Source: https://docs.rs/unsynn/latest/unsynn/container/struct.DelimitedVec_search=u32+-%3E+bool The `as_mut_ptr_range` method returns a `Range` of mutable raw pointers representing the start and end of the slice in memory. Similar to `as_ptr_range`, it's useful for interacting with foreign interfaces. The end pointer points one past the last element. Use with caution. ```Rust // No code example provided in the documentation. ``` -------------------------------- ### Enable Struct Source: https://docs.rs/unsynn/latest/unsynn/predicates/struct.Enable_search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Documentation for the `Enable` struct, which always succeeds without consuming tokens. ```APIDOC ## Struct Enable ### Description Always succeeds without consuming tokens. ### Method N/A (Struct definition) ### Endpoint N/A (Struct definition) ### Parameters N/A ### Request Example ```rust use unsynn::* let mut tokens = "foo bar".to_token_iter(); let result = Enable::parse(&mut tokens); assert!(result.is_ok()); assert_eq!(tokens.clone().count(), 2); // No tokens consumed ``` ### Response #### Success Response (N/A for struct definition) N/A #### Response Example N/A ``` -------------------------------- ### Get Pointer Range of Slice in Rust Source: https://docs.rs/unsynn/latest/unsynn/container/struct.DelimitedVec_search= This function returns a range of raw pointers that span the slice. It's useful for interacting with foreign interfaces that use pointers to refer to a range of memory. The end pointer points one past the last element. It includes an example to check if a pointer refers to an element within the slice. ```Rust pub fn as_ptr_range(&self) -> Range<*const T> { // Implementation details for as_ptr_range } ``` -------------------------------- ### Example: Creating IntoIdent from AST Source: https://docs.rs/unsynn/latest/unsynn/struct.IntoIdent Illustrates the usage of the `IntoIdent::from` method to create an `IntoIdent` from a parsed token stream representing an AST. It shows error handling and retrieving the identifier as a string. ```rust let mut token_iter = r#" foo "123" "#.to_token_iter(); let parsed = >::parser(&mut token_iter).unwrap(); let ident = IntoIdent::from(&parsed).unwrap(); assert_eq!(ident.as_str(), "foo123"); ``` -------------------------------- ### Get Slice Length in Rust Source: https://docs.rs/unsynn/latest/unsynn/container/struct.DelimitedVec_search= Demonstrates how to get the number of elements in a slice. This is analogous to getting the length of a vector. ```Rust let a = [1, 2, 3]; assert_eq!(a.len(), 3); ``` -------------------------------- ### Example Usage of AsDefault in Rust Source: https://docs.rs/unsynn/latest/unsynn/transform/type.AsDefault_search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Demonstrates the usage of `AsDefault` within a `Vec` for token parsing. It shows how `AsDefault` can be used to parse a sequence of dots and leverages the zero-sized type optimization in `Vec` for memory efficiency. ```rust let mut token_iter = "..........\வது.to_token_iter(); let parsed = >>::parser(&mut token_iter).unwrap(); assert_eq!(parsed.len(), 10); // Vec's ZST optimization at work: assert_eq!(parsed.capacity(), usize::MAX); assert_tokens_eq!(parsed, ". . . . . . . . . ."); ``` -------------------------------- ### Get Slice Length Source: https://docs.rs/unsynn/latest/unsynn/expressions/struct.RightAssocExpr_search=u32+-%3E+bool Demonstrates how to get the number of elements in a slice. ```Rust let a = [1, 2, 3]; assert_eq!(a.len(), 3); ``` -------------------------------- ### Type Conversion and Casting Source: https://docs.rs/unsynn/latest/unsynn/expressions/struct.PostfixExpr_search=std%3A%3Avec Documentation for methods related to type conversions, including `From`, `Into`, `TryFrom`, and `TryInto`. ```APIDOC ## fn from(t: T) -> T ### Description Returns the argument unchanged. This is a standard conversion function. ### Method `from` ### Endpoint N/A (Associated function within a trait implementation) ### Parameters - `t` (T): The value to convert. ### Request Example N/A ### Response #### Success Response - `T`: The converted value (unchanged). #### Response Example N/A ``` ```APIDOC ## fn into(self) -> U ### Description Calls `U::from(self)`. This conversion is determined by the `From for U` implementation. ### Method `into` ### Endpoint N/A (Method within a trait implementation) ### Parameters - `self`: The value to convert. ### Request Example N/A ### Response #### Success Response - `U`: The converted value. #### Response Example N/A ``` ```APIDOC ## fn try_from(value: U) -> Result>::Error> ### Description Performs the conversion from type `U` to type `T`. Returns a `Result` which indicates success or failure. ### Method `try_from` ### Endpoint N/A (Associated function within a trait implementation) ### Parameters - `value` (U): The value to convert. ### Request Example N/A ### Response #### Success Response - `Result`: Ok(T) on success, Err(Error) on failure. #### Response Example N/A ``` ```APIDOC ## fn try_into(self) -> Result>::Error> ### Description Performs the conversion from type `T` to type `U`. Returns a `Result` which indicates success or failure. ### Method `try_into` ### Endpoint N/A (Method within a trait implementation) ### Parameters - `self`: The value to convert. ### Request Example N/A ### Response #### Success Response - `Result`: Ok(U) on success, Err(Error) on failure. #### Response Example N/A ``` -------------------------------- ### get Source: https://docs.rs/unsynn/latest/unsynn/struct.RightAssocExpr_search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Safely gets a reference to an element or subslice based on the provided index. Returns None if the index is out of bounds. ```APIDOC ## GET /get ### Description Safely gets a reference to an element or subslice based on the provided index. Returns None if the index is out of bounds. ### Method GET ### Endpoint /get ### Parameters #### Query Parameters - **slice** (array) - Required - The slice to access. - **index** (string|object) - Required - The index or range to access. Can be a single index (e.g., "1") or a range (e.g., "0..2"). ### Request Example ```json { "slice": [10, 40, 30], "index": "1" } ``` ```json { "slice": [10, 40, 30], "index": "0..2" } ``` ### Response #### Success Response (200) - **element** (any) - The element at the specified index, or the subslice corresponding to the range. #### Response Example ```json { "element": 40 } ``` ```json { "element": [10, 40] } ``` ``` -------------------------------- ### Example Usage of format_literal_string Macro (Rust) Source: https://docs.rs/unsynn/latest/unsynn/macro.format_literal_string_search=std%3A%3Avec Demonstrates the usage of the format_literal_string macro in Rust. It shows how to import the macro, use it to create a literal string with formatting, and asserts the equality of the generated string with an expected literal string. ```rust use unsynn::*; let literal_string = format_literal_string!("my_{}", "literal_string"); assert_tokens_eq!(literal_string, r#" "my_literal_string" "#); ``` -------------------------------- ### Get TypeId for Any in Rust Source: https://docs.rs/unsynn/latest/unsynn/struct.TokenIter_search=u32+-%3E+bool A blanket implementation of the `Any` trait for any type `T` that is `'static` and not `?Sized`. It provides a method to get the `TypeId` of the instance. ```rust impl Any for T where T: 'static + ?Sized { fn type_id(&self) -> TypeId { // Implementation details omitted } } ``` -------------------------------- ### Get TypeId of a static type in Rust Source: https://docs.rs/unsynn/latest/unsynn/container/struct.NonEmptyOption_search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Gets the TypeId of a statically known type. This is part of the Any trait implementation, allowing for runtime type identification. ```rust impl Any for T { fn type_id(&self) -> TypeId { // ... implementation details ... } } ``` -------------------------------- ### Example Usage of OrDefault Parser in Rust Source: https://docs.rs/unsynn/latest/unsynn/transform/type.OrDefault_search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Demonstrates the usage of the `OrDefault` type's parser in Rust. It shows how to parse a token iterator, attempting to parse a `u32` or falling back to a default, and asserts the resulting token equality. ```rust let mut token_iter = "foo".to_token_iter(); let parsed = >::parser(&mut token_iter).unwrap(); assert_tokens_eq!(parsed, "?"); ``` -------------------------------- ### Example Usage of keyword! Macro (Rust) Source: https://docs.rs/unsynn/latest/src/unsynn/macros.rs_search= Demonstrates how to use the `keyword!` macro to define various keywords like `If`, `Else`, `IfElse`, `IfElseThen`, and `NotIfElseThen`. It shows how to parse these keywords from a token stream and assert their string values. ```rust keyword!{ /// Optional documentation for `If` pub If = "if"; pub Else = "else"; // keywords can be grouped from existing keywords IfElse = [If, Else,]; // or contain identifiers in double quotes IfElseThen = [IfElse, "then"]; // matching can be negated with `!=` NotIfElseThen != [IfElse, "then"]; } let mut tokens = "if".to_token_iter(); let if_kw = If::parse(&mut tokens).unwrap(); assert_eq!(if_kw.as_str(), "if"); let mut tokens = "else if then something".to_token_iter(); let else_kw = Else::parse(&mut tokens).unwrap(); assert_eq!(else_kw.as_str(), "else"); let ifelse_kw = IfElse::parse(&mut tokens).unwrap(); assert_eq!(ifelse_kw.as_str(), "if"); let ifelsethen_kw = IfElseThen::parse(&mut tokens).unwrap(); assert_eq!(ifelsethen_kw.as_str(), "then"); let notifelsethen_kw = NotIfElseThen::parse(&mut tokens).unwrap(); assert_eq!(notifelsethen_kw.as_str(), "something"); ``` -------------------------------- ### Type Conversion (TryInto) Source: https://docs.rs/unsynn/latest/unsynn/group/struct.BraceGroupContaining_search=std%3A%3Avec Documentation for the `TryInto` trait implementation, providing a convenient way to attempt conversions into another type. ```APIDOC ### impl TryInto for T where U: TryFrom, #### type Error = >::Error ### Description The type returned in the event of a conversion error. #### fn try_into(self) -> Result>::Error> ### Description Performs the conversion. ``` -------------------------------- ### IntoIdent Parsing Example Source: https://docs.rs/unsynn/latest/unsynn/struct.IntoIdent_search=u32+-%3E+bool Demonstrates parsing a token iterator into an `IntoIdent` struct. This example shows how to create an `IntoIdent` from a `Cons` and assert its string representation. ```rust let mut token_iter = r#" foo "123" "#.to_token_iter(); let parsed = >::parser(&mut token_iter).unwrap(); let ident = IntoIdent::from(&parsed).unwrap(); assert_eq!(ident.as_str(), "foo123"); ``` -------------------------------- ### Parse NonParseable Token Example in Rust Source: https://docs.rs/unsynn/latest/unsynn/fundamental/struct.NonParseable_search= Demonstrates how to parse a `NonParseable` token from an iterator. This example requires the `nonparseable` feature flag to be enabled for `Parser` and `ToTokens` to be implemented. ```rust let mut tokens = "something".to_token_iter(); let nonparseable: NonParseable = tokens.parse().unwrap(); ``` -------------------------------- ### Rust: Implement Traits with Simplified Syntax Source: https://docs.rs/unsynn/latest/src/unsynn/macros.rs_search=u32+-%3E+bool Demonstrates implementing traits for structs and primitive types using simplified syntax within the `unsynn!` macro. It shows how to define traits, implement them for structs, and handle multiple types in a single implementation block. ```rust trait SimpleAccessor { fn get(&self) -> bool;} pub struct SimpleStruct{ flag: bool } impl { #[doc = "impl attributes go here"] TestMarker; TestMarker2 {} SimpleAccessor {fn get(&self) -> bool {self.flag}} } impl TestMarker for i32, u32, i64, u64; impl SimpleAccessor for bool {fn get(&self) -> bool {*self}} impl TestMarker4 for SimpleStruct {} ``` -------------------------------- ### clone_to_uninit Source: https://docs.rs/unsynn/latest/unsynn/container/struct.LazyVecUntil_search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E This nightly-only experimental API 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. Performs copy-assignment from `self` to `dest`. ### Method `unsafe fn` ### Endpoint N/A (Internal method) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example None ### Response #### Success Response (200) None (operates via pointer) #### Response Example None ``` -------------------------------- ### LazyVecUntil Struct Definition and Usage Example (Rust) Source: https://docs.rs/unsynn/latest/unsynn/container/struct.LazyVecUntil Defines the LazyVecUntil struct, which holds a Vec and parses until a terminator S. The example demonstrates parsing tokens until a semicolon. ```Rust pub struct LazyVecUntil { pub vec: Vec, /* private fields */ } // Example usage: // let mut token_iter = "foo bar ; baz ;".to_token_iter(); // type Example = LazyVecUntil; // let _example = Example::parse(&mut token_iter).unwrap(); // let _example = Semicolon::parse(&mut token_iter).unwrap(); // let _example = Example::parse(&mut token_iter).unwrap(); // let _example = Semicolon::parse(&mut token_iter).unwrap(); ``` -------------------------------- ### Rust Example Searches Source: https://docs.rs/unsynn/latest/src/unsynn/combinator.rs_search= Provides examples of search queries for Rust code, illustrating how to find specific types, function signatures, and generic type transformations. ```text * std::vec * u32 -> bool * Option, (T -> U) -> Option ``` -------------------------------- ### CloneToUninit Source: https://docs.rs/unsynn/latest/unsynn/expressions/struct.PrefixExpr_search= Provides a method to clone data into an uninitialized memory location. This is a nightly-only experimental API. ```APIDOC ## unsafe fn clone_to_uninit(&self, dest: *mut u8) ### Description Performs copy-assignment from `self` to `dest`. ### Method `unsafe fn` ### Endpoint N/A (Method within a trait) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```rust // Example usage would depend on the specific type implementing CloneToUninit ``` ### Response #### Success Response (N/A) This method does not return a value, but performs an operation. #### Response Example N/A ``` -------------------------------- ### Get first element of slice from Option (Rust) Source: https://docs.rs/unsynn/latest/unsynn/struct.NonEmptyOption_search=std%3A%3Avec Demonstrates the inverse relationship between as_slice() and the first() method on slices. It shows how to get the first element of the slice obtained from an Option. ```rust for i in [Some(1234_u16), None] { assert_eq!(i.as_ref(), i.as_slice().first()); } ``` -------------------------------- ### Create TokenIter Instance in Rust Source: https://docs.rs/unsynn/latest/unsynn/struct.TokenIter Demonstrates how to create a new owned TokenIter instance from an iterable token stream. This is useful for initiating token parsing. ```rust pub fn new( stream: impl IntoIterator::IntoIter>, ) -> Self ``` -------------------------------- ### Get Vector Capacity in Rust Source: https://docs.rs/unsynn/latest/unsynn/container/struct.DelimitedVec_search= Demonstrates how to get the total capacity of a vector before reallocation. It shows a standard case and a special case for zero-sized elements where capacity is usize::MAX. ```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); } ``` -------------------------------- ### AllOf Predicate Logic Example Source: https://docs.rs/unsynn/latest/unsynn/predicates/struct.AllOf_search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Demonstrates the usage of the AllOf struct with different predicate combinations. It shows how to parse token iterators with AllOf, asserting success when all predicates are 'Enable' and failure when one is 'Disable'. ```rust use unsynn::*; let mut tokens = "".to_token_iter(); // Two predicates assert!(AllOf::::parse(&mut tokens).is_ok()); assert!(AllOf::::parse(&mut tokens).is_err()); // Four predicates assert!(AllOf::::parse(&mut tokens).is_ok()); ``` -------------------------------- ### IntoIdent Default Construction Example Source: https://docs.rs/unsynn/latest/unsynn/struct.IntoIdent_search=u32+-%3E+bool Illustrates the default construction of `IntoIdent` when `T` implements `Default` and `ToTokens`. This example uses a custom keyword `Foo` and a constant integer to create an `IntoIdent`. ```rust keyword!{Foo = "foo"} let default = >>>::default(); assert_tokens_eq!(default, "foo1234"); ``` -------------------------------- ### Not Struct Definition and Usage Example (Rust) Source: https://docs.rs/unsynn/latest/unsynn/predicates/struct.Not_search=u32+-%3E+bool Defines the Not struct which wraps a PredicateOp and inverts its result. Includes an example demonstrating its usage with Disable and Enable predicates. ```rust pub struct Not(/* private fields */); // Example Usage: use unsynn::* let mut tokens = "".to_token_iter(); assert!(Not::::parse(&mut tokens).is_ok()); assert!(Not::::parse(&mut tokens).is_err()); ``` -------------------------------- ### Example Usage of NonEmptyOption in Rust Source: https://docs.rs/unsynn/latest/unsynn/container/struct.NonEmptyOption_search=std%3A%3Avec Demonstrates how to use NonEmptyOption with a token iterator. It shows parsing with NonEmptyOption and asserting the result, highlighting its behavior compared to Option when dealing with empty input streams. ```Rust let mut token_iter = "ident".to_token_iter(); let parsed = NonEmptyOption::::parser(&mut token_iter).unwrap(); assert_tokens_eq!(parsed, ""); ``` -------------------------------- ### CloneToUninit API Source: https://docs.rs/unsynn/latest/unsynn/struct.PostfixExpr_search= Provides a nightly-only experimental API for performing copy-assignment from self to a mutable destination pointer. ```APIDOC ## unsafe fn clone_to_uninit(&self, dest: *mut u8) ### Description Performs copy-assignment from `self` to `dest`. ### Method `unsafe fn` ### Endpoint N/A (In-memory operation) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```rust // Example usage (requires nightly Rust) // let mut uninit_buffer = vec![0u8; std::mem::size_of::()]; // unsafe { value.clone_to_uninit(uninit_buffer.as_mut_ptr()); } ``` ### Response #### Success Response (N/A) This function does not return a value directly but performs an in-place operation. #### Response Example N/A ``` -------------------------------- ### Define Not struct and parse example in Rust Source: https://docs.rs/unsynn/latest/unsynn/predicates/struct.Not Demonstrates the definition of the Not struct and provides an example of its usage with parsing tokens. It shows how to use Not with Disable and Enable predicates. ```rust pub struct Not(/* private fields */); // Example usage: use unsynn::* let mut tokens = "".to_token_iter(); assert!(Not::::parse(&mut tokens).is_ok()); assert!(Not::::parse(&mut tokens).is_err()); ``` -------------------------------- ### unsynn keyword! Macro Usage Example Source: https://docs.rs/unsynn/latest/unsynn/macro.keyword_search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Demonstrates how to use the `keyword!` macro to define various keyword types, including simple string literals, grouped keywords, and negated keyword sets. It also shows how to parse input tokens to match these defined keywords. ```rust keyword!{ /// Optional documentation for `If` pub If = "if"; pub Else = "else"; // keywords can be grouped from existing keywords IfElse = [If, Else,]; // or contain identifiers in double quotes IfElseThen = [IfElse, "then"]; // matching can be negated with `!=` NotIfElseThen != [IfElse, "then"]; } let mut tokens = "if".to_token_iter(); let if_kw = If::parse(&mut tokens).unwrap(); assert_eq!(if_kw.as_str(), "if"); ``` -------------------------------- ### Get Slice as Array Reference (Rust) Source: https://docs.rs/unsynn/latest/unsynn/struct.RightAssocExpr_search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Attempts to get a reference to the underlying array if the slice's length exactly matches the specified size `N`. Returns `None` otherwise. ```rust let slice = &[1, 2, 3]; let array_ref: Option<&[i32; 3]> = slice.as_array(); assert!(array_ref.is_some()); let short_slice = &[1, 2]; let array_ref_fail: Option<&[i32; 3]> = short_slice.as_array(); assert!(array_ref_fail.is_none()); ``` -------------------------------- ### Get Underlying Allocator Reference in Rust (Nightly) Source: https://docs.rs/unsynn/latest/unsynn/expressions/struct.LeftAssocExpr Provides a nightly-only experimental API to get a reference to the underlying allocator used by a `Vec`. This feature is part of the `allocator_api` unstable feature. ```Rust pub fn allocator(&self) -> &A ``` -------------------------------- ### DynNode Parsing Example - Rust Source: https://docs.rs/unsynn/latest/unsynn/dynamic/struct.DynNode_search=u32+-%3E+bool Demonstrates parsing a string into a DynNode, asserting its initial value, and performing runtime replacements. It shows both global replacement of all cloned occurrences and local replacement of only the current instance. ```rust let mut token_iter = "foo".to_token_iter(); let parsed = >::parser(&mut token_iter).unwrap(); assert_tokens_eq!(parsed, "foo"); let _test: Ident = parsed.downcast_ref::().unwrap().clone(); // Global replacement of all cloned locations (parsed & other) let mut other = parsed.clone(); other.replace_all_with(, Comma>>::default()); assert_tokens_eq!(parsed, "123,"); // Local replacement (only other) other.replace_here_with(Bang::default()); assert_tokens_eq!(other, "!"); assert_tokens_eq!(parsed, "123,"); ``` -------------------------------- ### Get Mutable First Element of Slice in Rust Source: https://docs.rs/unsynn/latest/unsynn/container/struct.DelimitedVec_search= Demonstrates how to get a mutable reference to the first element of a slice. It returns None if the slice is empty and allows modification of the first element. ```Rust let x = &mut [0, 1, 2]; if let Some(first) = x.first_mut() { *first = 5; } assert_eq!(x, &[5, 1, 2]); let y: &mut [i32] = &mut []; assert_eq!(None, y.first_mut()); ```