### starts_with Source: https://docs.rs/ufbx/latest/ufbx/prelude/struct Checks if the string slice starts with a given pattern. ```APIDOC ## GET /websites/rs_ufbx_ufbx/starts_with ### Description Verifies if the string slice begins with the specified pattern. The pattern can be a substring, a character, or a set of characters. ### Method GET ### Endpoint /websites/rs_ufbx_ufbx/starts_with ### Parameters #### Query Parameters - **pattern** (string | char | array of char) - Required - The pattern to check at the beginning of the string slice. ### Request Example ```APIDOC GET /websites/rs_ufbx_ufbx/starts_with?pattern=bana # Example Usage: let bananas = "bananas"; let starts_with_bana = bananas.starts_with("bana"); // true let starts_with_nana = bananas.starts_with("nana"); // false println!("Starts with 'bana': {}", starts_with_bana); println!("Starts with 'nana': {}", starts_with_nana); ``` ### Response #### Success Response (200) - **result** (boolean) - `true` if the string slice starts with the pattern, `false` otherwise. #### Response Example ```APIDOC { "result": true } ``` ``` -------------------------------- ### Get Metadata with Error Handling Source: https://docs.rs/ufbx/latest/ufbx/generated/type Illustrates retrieving file metadata and handling potential errors using `Result`. It shows how to access metadata for a valid path and asserts that the operation is successful. It also demonstrates attempting to get metadata for an invalid path, asserting that it results in an error and checking the specific `ErrorKind`. ```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); ``` -------------------------------- ### Get String Subslice Safely Source: https://docs.rs/ufbx/latest/ufbx/prelude/struct Illustrates retrieving a subslice of a `ufbx::prelude::String` using `get()`. This method returns an `Option<&str>` and handles out-of-bounds or invalid UTF-8 sequence indices gracefully by returning `None`. ```rust let v = String::from("🗻∈🌏"); assert_eq!(Some("🗻"), v.get(0..4)); // indices not on UTF-8 sequence boundaries assert!(v.get(1..).is_none()); assert!(v.get(..8).is_none()); // out of bounds assert!(v.get(..42).is_none()); ``` -------------------------------- ### Rust: Splitting a String by a Pattern (rsplit) Source: https://docs.rs/ufbx/latest/ufbx/prelude/struct Demonstrates splitting a string slice into substrings using a specified pattern. Supports various pattern types like char, &str, and closures. Shows examples with simple separators and multiple occurrences. ```rust let v: Vec<&str> = "Mary had a little lamb".rsplit(' ').collect(); assert_eq!(v, ["lamb", "little", "a", "had", "Mary"]); let v: Vec<&str> = "".rsplit('X').collect(); assert_eq!(v, [""]); let v: Vec<&str> = "lionXXtigerXleopard".rsplit('X').collect(); assert_eq!(v, ["leopard", "tiger", "", "lion"]); let v: Vec<&str> = "lion::tiger::leopard".rsplit("::").collect(); assert_eq!(v, ["leopard", "tiger", "lion"]); ``` ```rust let v: Vec<&str> = "abc1defXghi".rsplit(|c| c == '1' || c == 'X').collect(); assert_eq!(v, ["ghi", "def", "abc"]); ``` -------------------------------- ### Rust Result into_ok() - Safely get Ok value Source: https://docs.rs/ufbx/latest/ufbx/generated/type Shows the `into_ok()` method, a nightly-only experimental API that safely returns the `Ok` value without panicking. It's designed as a compile-time safeguard against Results that can never be `Err`. ```rust fn only_good_news() -> Result { Ok("this is fine".into()) } let s: String = only_good_news().into_ok(); println!("{s}"); ``` -------------------------------- ### Check if String Starts With a Pattern Source: https://docs.rs/ufbx/latest/ufbx/prelude/struct Verifies if a string slice begins with a specified pattern. The pattern can be a string slice, a character, a slice of characters, or a closure. It checks the prefix of the string. ```rust let bananas = "bananas"; assert!(bananas.starts_with("bana")); assert!(!bananas.starts_with("nana")); ``` ```rust let bananas = "bananas"; // Note that both of these assert successfully. assert!(bananas.starts_with(&['b', 'a', 'n', 'a'])); assert!(bananas.starts_with(&['a', 'b', 'c', 'd'])); ``` -------------------------------- ### Handle `Err` with `or` Method Source: https://docs.rs/ufbx/latest/ufbx/generated/type Demonstrates the `or` method for `Result`, which returns the `Ok` value of the first `Result` if it is `Ok`, otherwise returns the second `Result`. The examples show cases where the first `Result` is `Ok` (the second is ignored) and where the first `Result` is `Err` (the second `Result` is returned). Note that arguments to `or` are eagerly evaluated. ```rust let x: Result = Ok(2); let y: Result = Err("late error"); assert_eq!(x.or(y), Ok(2)); let x: Result = Err("early error"); let y: Result = Ok(2); assert_eq!(x.or(y), Ok(2)); let x: Result = Err("not a 2"); let y: Result = Err("late error"); assert_eq!(x.or(y), Err("late error")); let x: Result = Ok(2); let y: Result = Ok(100); assert_eq!(x.or(y), Ok(2)); ``` -------------------------------- ### Remove leading whitespace with trim_start Source: https://docs.rs/ufbx/latest/ufbx/prelude/struct The `trim_start` method removes leading whitespace from a string slice. Whitespace is defined by the Unicode `White_Space` property. The 'start' is determined by byte string position, respecting text directionality. ```rust let s = "\n Hello\tworld\t\n"; assert_eq!("Hello\tworld\t\n", s.trim_start()); let s = " English "; assert!(Some('E') == s.trim_start().chars().next()); let s = " עברית "; assert!(Some('ע') == s.trim_start().chars().next()); ``` -------------------------------- ### Get Raw Pointer to String Bytes Source: https://docs.rs/ufbx/latest/ufbx/prelude/struct Demonstrates obtaining a raw pointer (`*const u8`) to the first byte of a `ufbx::prelude::String` using `as_ptr()`. The pointer should not be mutated. ```rust let s = "Hello"; let ptr = s.as_ptr(); ``` -------------------------------- ### Trim Start Matches in Rust Source: https://docs.rs/ufbx/latest/ufbx/prelude/struct Removes all matching prefixes from a string. Supports various pattern types like &str, char, slices of char, or functions. This method repeatedly removes prefixes until no match is found. ```rust assert_eq!("11foo1bar11".trim_start_matches('1'), "foo1bar11"); assert_eq!("123foo1bar123".trim_start_matches(char::is_numeric), "foo1bar123"); let x: &[_] = &['1', '2']; assert_eq!("12foo1bar12".trim_start_matches(x), "foo1bar12"); ``` -------------------------------- ### Rust Result into_err() - Safely get Err value Source: https://docs.rs/ufbx/latest/ufbx/generated/type Demonstrates the `into_err()` method, another nightly-only experimental API that safely returns the `Err` value without panicking. This serves as a compile-time safeguard for Results that can never be `Ok`. ```rust fn only_bad_news() -> Result { Err("Oops, it failed".into()) } let error: String = only_bad_news().into_err(); println!("{error}"); ``` -------------------------------- ### Load and Open Files with ufbx Source: https://docs.rs/ufbx/latest/ufbx/generated/index Functions for loading 3D model data from files or memory streams. Includes options for file paths, memory buffers, and standard I/O streams. ```c ufbx_load_file(const char *filename); ufbx_load_file_len(const char *filename, size_t size); ufbx_load_stdio(FILE *file, const char *name); ufbx_load_stdio_prefix(FILE *file, size_t prefix, const char *name); upload_load_stream(ufbx_stream *stream, const char *name); upload_load_stream_prefix(ufbx_stream *stream, size_t prefix, const char *name); upload_open_file(const char *filename); upload_open_file_ctx(const char *filename, ufbx_context *ctx); upload_open_memory(const void *data, size_t size); upload_open_memory_ctx(const void *data, size_t size, ufbx_context *ctx); ``` -------------------------------- ### Get String Subslice Unsafely Source: https://docs.rs/ufbx/latest/ufbx/prelude/struct Provides an example of `get_unchecked()`, which retrieves a subslice without bounds or UTF-8 boundary checks. This is an unsafe operation and requires the caller to guarantee the validity of the indices. ```rust let v = "🗻∈🌏"; unsafe { assert_eq!("🗻", v.get_unchecked(0..4)); assert_eq!("∈", v.get_unchecked(4..7)); assert_eq!("🌏", v.get_unchecked(7..11)); } ``` -------------------------------- ### into_ok() Source: https://docs.rs/ufbx/latest/ufbx/generated/type Returns the contained Ok value, never panics. (Nightly-only experimental API) ```APIDOC ## GET /api/users/{id} ### Description Retrieves a specific user by their ID. ### Method GET ### Endpoint /api/users/{id} ### Parameters #### Path Parameters - **id** (integer) - Required - The unique identifier of the user to retrieve. ### Response #### Success Response (200) - **id** (integer) - The user's unique identifier. - **name** (string) - The user's name. - **email** (string) - The user's email address. #### Response Example ```json { "id": 1, "name": "John Doe", "email": "john.doe@example.com" } ``` #### Error Response (404) - **message** (string) - Indicates that the user was not found. #### Error Response Example ```json { "message": "User with ID 99 not found." } ``` ``` -------------------------------- ### Get ASCII Slice from String in Rust (Experimental) Source: https://docs.rs/ufbx/latest/ufbx/prelude/struct Provides a way to get a slice of ASCII characters from a string if it's entirely ASCII. This is a nightly-only experimental API. ```Rust let ascii_str = "hello"; let ascii_chars = ascii_str.as_ascii(); assert!(ascii_chars.is_some()); ``` -------------------------------- ### Get String Length Source: https://docs.rs/ufbx/latest/ufbx/prelude/struct Demonstrates how to get the byte length of a `ufbx::prelude::String`. The `len()` method returns the number of bytes, which may not correspond to the number of characters in UTF-8 strings. ```rust let len = "foo".len(); assert_eq!(3, len); assert_eq!("ƒoo".len(), 4); // fancy f! assert_eq!("ƒoo".chars().count(), 3); ``` -------------------------------- ### Unchecked Unwrap with `unwrap_unchecked` Source: https://docs.rs/ufbx/latest/ufbx/generated/type Explains the `unwrap_unchecked` method, which returns the contained `Ok` value without checking if the `Result` is `Err`. This method is `unsafe` and calling it on an `Err` results in undefined behavior. The example shows a successful unwrapping and a commented-out example of unsafe usage with an `Err`. ```rust let x: Result = Ok(2); assert_eq!(unsafe { x.unwrap_unchecked() }, 2); let x: Result = Err("emergency failure"); unsafe { x.unwrap_unchecked() }; // Undefined behavior! ``` -------------------------------- ### Result Operations Source: https://docs.rs/ufbx/latest/ufbx/generated/type Demonstrates chaining fallible operations using `and_then` and handling potential overflows. ```APIDOC ## `and_then` - Chaining Fallible Operations ### Description Chains fallible operations that may return `Err`. If the `Result` is `Ok`, it applies the closure to the contained value; otherwise, it returns the `Err` value. ### Method `and_then` ### Endpoint N/A (Method on `Result` enum) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```rust fn sq_then_to_string(x: u32) -> Result { x.checked_mul(x).map(|sq| sq.to_string()).ok_or("overflowed") } assert_eq!(Ok(2).and_then(sq_then_to_string), Ok("4".to_string())); assert_eq!(Ok(1_000_000).and_then(sq_then_to_string), Err("overflowed")); assert_eq!(Err("not a number").and_then(sq_then_to_string), Err("not a number")); ``` ### Response #### Success Response (200) N/A (Method return value) #### Response Example N/A ``` -------------------------------- ### repeat Source: https://docs.rs/ufbx/latest/ufbx/prelude/struct Creates a new string by repeating a string n times. ```APIDOC ## POST /string/repeat ### Description Creates a new `String` by repeating a given string `n` times. ### Method POST ### Endpoint /string/repeat ### Parameters #### Request Body - **s** (string) - Required - The string to repeat. - **n** (integer) - Required - The number of times to repeat the string. ### Response #### Success Response (200) - **result** (string) - The repeated string. #### Response Example ```json { "result": "abcabcabcabc" } ``` ``` -------------------------------- ### match_indices Source: https://docs.rs/ufbx/latest/ufbx/prelude/struct Returns an iterator over the disjoint matches of a pattern within this string slice as well as the index that the match starts at. ```APIDOC ## POST /match_indices ### Description Returns an iterator over the disjoint matches of a pattern within this string slice, along with the starting index of each match. For overlapping matches, only the indices of the first match are returned. ### Method POST ### Endpoint /match_indices ### Parameters #### Request Body - **text** (string) - Required - The string to search within. - **pattern** (string) - Required - The pattern to search for. Can be a string, character, slice of characters, or a closure. ### Request Example ```json { "text": "abcXXXabcYYYabc", "pattern": "abc" } ``` ### Response #### Success Response (200) - **matches** (array of objects) - An array where each object contains the index and the matched string. - **index** (integer) - The starting index of the match. - **match** (string) - The matched string. #### Response Example ```json { "matches": [ {"index": 0, "match": "abc"}, {"index": 6, "match": "abc"}, {"index": 12, "match": "abc"} ] } ``` ``` -------------------------------- ### Trim ASCII Whitespace from Start in Rust Source: https://docs.rs/ufbx/latest/ufbx/prelude/struct Removes leading ASCII whitespace characters from a string slice. Whitespace is defined by the `u8::is_ascii_whitespace` method. ```Rust let s = " hello"; assert_eq!(s.trim_ascii_start(), "hello"); ``` -------------------------------- ### as_ref Source: https://docs.rs/ufbx/latest/ufbx/generated/type Converts from &Result to Result<&T, &E>, producing a new Result containing references to the original values. ```APIDOC ## as_ref ### Description Converts from `&Result` to `Result<&T, &E>`, producing a new `Result` containing a reference into the original, leaving the original in place. ### Method fn ### Endpoint N/A (Method on Result) ### Parameters N/A ### Request Body N/A ### Response #### Success Response (N/A) - **Result<&T, &E>** - A new Result containing references to the original values. #### Response Example ``` Ok(&2) ``` ``` -------------------------------- ### Create Result from Residual (Rust - Nightly) Source: https://docs.rs/ufbx/latest/ufbx/generated/type Shows how to construct a Result type from a compatible `Residual` type. This is an experimental API, currently available only on nightly Rust. ```Rust impl FromResidual> for Result where F: From { ... } ``` ```Rust impl FromResidual> for Result where F: From { ... } ``` -------------------------------- ### Rust: Splitting String with rsplitn Source: https://docs.rs/ufbx/latest/ufbx/prelude/struct Demonstrates splitting a string into a specified number of subslices using `rsplitn`. Supports various delimiters including characters, strings, and closures. ```rust let v: Vec<&str> = "Mary had a little lamb".rsplitn(3, ' ').collect(); assert_eq!(v, ["lamb", "little", "Mary had a"]); let v: Vec<&str> = "lionXXtigerXleopard".rsplitn(3, 'X').collect(); assert_eq!(v, ["leopard", "tiger", "lionX"]); let v: Vec<&str> = "lion::tiger::leopard".rsplitn(2, "::").collect(); assert_eq!(v, ["leopard", "lion::tiger"]); let v: Vec<&str> = "abc1defXghi".rsplitn(2, |c| c == '1' || c == 'X').collect(); assert_eq!(v, ["ghi", "abc1def"]); ``` -------------------------------- ### Trim ASCII Whitespace from Start of String in Rust Source: https://docs.rs/ufbx/latest/ufbx/prelude/struct Removes leading ASCII whitespace from a string slice. Whitespace is defined by `u8::is_ascii_whitespace`. Handles cases with only whitespace or empty strings. ```rust assert_eq!(" \t \u{3000}hello world\n".trim_ascii_start(), "\u{3000}hello world\n"); assert_eq!(" ".trim_ascii_start(), ""); assert_eq!("".trim_ascii_start(), ""); ``` -------------------------------- ### Result Implementations Source: https://docs.rs/ufbx/latest/ufbx/generated/type Provides various utility methods for working with the `Result` type, including mapping, checking states, and flattening nested results. ```APIDOC ## Implementations for Result ### `impl Result<&T, E>` #### `copied(self) -> Result` * **Description**: Maps a `Result<&T, E>` to a `Result` by copying the contents of the `Ok` part, requiring `T` to implement `Copy`. * **Since**: 1.59.0 (const: 1.83.0) * **Example**: ```rust let val = 12; let x: Result<&i32, i32> = Ok(&val); assert_eq!(x, Ok(&12)); let copied = x.copied(); assert_eq!(copied, Ok(12)); ``` #### `cloned(self) -> Result` * **Description**: Maps a `Result<&T, E>` to a `Result` by cloning the contents of the `Ok` part, requiring `T` to implement `Clone`. * **Since**: 1.59.0 * **Example**: ```rust let val = 12; let x: Result<&i32, i32> = Ok(&val); assert_eq!(x, Ok(&12)); let cloned = x.cloned(); assert_eq!(cloned, Ok(12)); ``` ### `impl Result<&mut T, E>` #### `copied(self) -> Result` * **Description**: Maps a `Result<&mut T, E>` to a `Result` by copying the contents of the `Ok` part, requiring `T` to implement `Copy`. * **Since**: 1.59.0 (const: 1.83.0) * **Example**: ```rust let mut val = 12; let x: Result<&mut i32, i32> = Ok(&mut val); assert_eq!(x, Ok(&mut 12)); let copied = x.copied(); assert_eq!(copied, Ok(12)); ``` #### `cloned(self) -> Result` * **Description**: Maps a `Result<&mut T, E>` to a `Result` by cloning the contents of the `Ok` part, requiring `T` to implement `Clone`. * **Since**: 1.59.0 * **Example**: ```rust let mut val = 12; let x: Result<&mut i32, i32> = Ok(&mut val); assert_eq!(x, Ok(&mut 12)); let cloned = x.cloned(); assert_eq!(cloned, Ok(12)); ``` ### `impl Result, E>` #### `transpose(self) -> Option>` * **Description**: Transposes a `Result` of an `Option` into an `Option` of a `Result`. `Ok(None)` becomes `None`, while `Ok(Some(v))` and `Err(e)` become `Some(Ok(v))` and `Some(Err(e))` respectively. * **Since**: 1.33.0 (const: 1.83.0) * **Example**: ```rust #[derive(Debug, Eq, PartialEq)] struct SomeErr; let x: Result, SomeErr> = Ok(Some(5)); let y: Option> = Some(Ok(5)); assert_eq!(x.transpose(), y); ``` ### `impl Result, E>` #### `flatten(self) -> Result` * **Description**: Converts from `Result, E>` to `Result`, removing one level of nesting. * **Since**: 1.89.0 (const: 1.89.0) * **Example**: ```rust let x: Result, u32> = Ok(Ok("hello")); assert_eq!(Ok("hello"), x.flatten()); let x: Result, u32> = Ok(Err(6)); assert_eq!(Err(6), x.flatten()); let x: Result, u32> = Err(6); assert_eq!(Err(6), x.flatten()); ``` * **Example (Nested Flattening)**: ```rust let x: Result, u32>, u32> = Ok(Ok(Ok("hello"))); assert_eq!(Ok(Ok("hello")), x.flatten()); assert_eq!(Ok("hello"), x.flatten().flatten()); ``` ### `impl Result` #### `is_ok(&self) -> bool` * **Description**: Returns `true` if the result is `Ok`. * **Since**: 1.0.0 (const: 1.48.0) * **Example**: ```rust let x: Result = Ok(-3); assert_eq!(x.is_ok(), true); let x: Result = Err("Some error message"); assert_eq!(x.is_ok(), false); ``` #### `is_ok_and(self, f: F) -> bool` where `F: FnOnce(T) -> bool` * **Description**: Returns `true` if the result is `Ok` and the value inside of it matches a predicate. * **Since**: 1.70.0 (const: unstable) * **Example**: ```rust let x: Result = Ok(2); assert_eq!(x.is_ok_and(|x| x > 1), true); let x: Result = Ok(0); assert_eq!(x.is_ok_and(|x| x > 1), false); let x: Result = Err("hey"); assert_eq!(x.is_ok_and(|x| x > 1), false); let x: Result = Ok("ownership".to_string()); assert_eq!(x.as_ref().is_ok_and(|x| x.len() > 1), true); println!("still alive {:?}", x); ``` #### `is_err(&self) -> bool` * **Description**: Returns `true` if the result is `Err`. * **Since**: 1.0.0 (const: 1.48.0) * **Example**: ```rust let x: Result = Ok(-3); assert_eq!(x.is_err(), false); let x: Result = Err("Some error message"); assert_eq!(x.is_err(), true); ``` #### `is_err_and(self, f: F) -> bool` where `F: FnOnce(E) -> bool` * **Description**: Returns `true` if the result is `Err` and the value inside of it matches a predicate. * **Since**: 1.70.0 (const: unstable) ``` -------------------------------- ### Rust: Finding match indices with match_indices Source: https://docs.rs/ufbx/latest/ufbx/prelude/struct Returns an iterator over the starting indices and content of all non-overlapping occurrences of a pattern within a string slice. Supports string slices, characters, and closures as patterns. ```rust let v: Vec<_> = "abcXXXabcYYYabc".match_indices("abc").collect(); assert_eq!(v, [(0, "abc"), (6, "abc"), (12, "abc")]); let v: Vec<_> = "1abcabc2".match_indices("abc").collect(); assert_eq!(v, [(1, "abc"), (4, "abc")]); let v: Vec<_> = "ababa".match_indices("aba").collect(); assert_eq!(v, [(0, "aba")]); ``` -------------------------------- ### Matrix and Quaternion Operations with ufbx Source: https://docs.rs/ufbx/latest/ufbx/generated/index Utility functions for performing common mathematical operations on matrices and quaternions, including inversion, multiplication, and conversion between formats. ```c ufbx_euler_to_quat(ufbx_vec3 euler); ufbx_matrix_determinant(ufbx_matrix m); ufbx_matrix_for_normals(ufbx_matrix m); ufbx_matrix_invert(ufbx_matrix m); ufbx_matrix_mul(ufbx_matrix a, ufbx_matrix b); ufbx_matrix_to_transform(ufbx_matrix m); ufbx_quat_dot(ufbx_quat a, ufbx_quat b); ufbx_quat_fix_antipodal(ufbx_quat q); ufbx_quat_mul(ufbx_quat a, ufbx_quat b); ufbx_quat_normalize(ufbx_quat q); ufbx_quat_rotate_vec3(ufbx_quat q, ufbx_vec3 v); ufbx_quat_slerp(ufbx_quat a, ufbx_quat b, float t); ufbx_quat_to_euler(ufbx_quat q); ufbx_transform_direction(ufbx_transform transform, ufbx_vec3 dir); ufbx_transform_position(ufbx_transform transform, ufbx_vec3 pos); ufbx_transform_to_matrix(ufbx_transform transform); ``` -------------------------------- ### Get String Slice Reference in Rust (Nightly) Source: https://docs.rs/ufbx/latest/ufbx/prelude/struct Returns the string slice `&str` from other string-like types, such as `Box` or `Arc`. This is a nightly-only experimental API and is redundant when used directly on `&str`. ```rust let boxed_str: Box = Box::new("hello"); let slice: &str = boxed_str.as_str(); assert_eq!(slice, "hello"); ``` -------------------------------- ### Product for Result Source: https://docs.rs/ufbx/latest/ufbx/generated/type Product implementation for Result type, allowing multiplication of contained values. ```APIDOC ## impl Product> for Result ### Description Implements the `Product` trait for `Result`. This allows multiplying elements of an iterator of `Result`s, where the contained type `U` also implements `Product`. If any element in the iterator is an `Err`, that `Err` is returned immediately. ### Method `product()` (via `Iterator::product()`) ### Endpoint N/A (Functionality within Rust's standard library) ### Parameters N/A ### Request Example ```rust let values = vec![Ok(2), Ok(3), Ok(4)]; let product: Result = values.into_iter().product(); assert_eq!(product, Ok(24)); let values_with_err = vec![Ok(2), Err("Failed!"), Ok(4)]; let product_err: Result = values_with_err.into_iter().product(); assert_eq!(product_err, Err("Failed!")); ``` ### Response #### Success Response (Ok(T)) - **T** - The product of all contained `Ok` values. #### Error Response (Err(E)) - **E** - The first `Err` value encountered in the iterator. #### Response Example ```rust let values = vec![Ok(2u32), Ok(3), Ok(4)]; let product: Result = values.into_iter().product(); assert_eq!(product, Ok(24)); ``` ``` -------------------------------- ### PartialOrd for Result Source: https://docs.rs/ufbx/latest/ufbx/generated/type Partial ordering implementation for Result type. ```APIDOC ## impl PartialOrd for Result ### Description Provides partial ordering for `Result` values. `Ok(a)` is considered greater than `Err(b)` for any `a` and `b`. If both are `Ok` or both are `Err`, their contained values are compared using partial ordering. ### Methods - `partial_cmp(&self, other: &Result) -> Option` - `lt(&self, other: &Rhs) -> bool` - `le(&self, other: &Rhs) -> bool` - `gt(&self, other: &Rhs) -> bool` - `ge(&self, other: &Rhs) -> bool` ### Endpoint N/A (Methods on the Result type) ### Parameters - **self**: The `Result` instance. - **other**: The other `Result` instance to compare against. ### Request Example ```rust assert!(Ok(5) > Ok(4)); assert!(Ok(5) > Err(4)); assert!(Err(5) < Err(6)); assert!(Err(5) < Ok(6)); ``` ### Response #### Success Response - **Option**: An `Option` containing `Less`, `Equal`, or `Greater` if a comparison is possible, otherwise `None`. - **bool**: Result of the comparison operator (`<`, `<=`, `>`, `>=`). #### Response Example ```rust use std::cmp::Ordering; let r1: Result = Ok(10.5); let r2: Result = Ok(5.2); assert_eq!(r1.partial_cmp(&r2), Some(Ordering::Greater)); let r3: Result = Err(10.5); assert_eq!(r1.partial_cmp(&r3), Some(Ordering::Greater)); let r4: Result = Ok(f64::NAN); // NaN comparison yields None assert_eq!(r1.partial_cmp(&r4), None); ``` ``` -------------------------------- ### Rust: Finding match indices in reverse with rmatch_indices Source: https://docs.rs/ufbx/latest/ufbx/prelude/struct Returns an iterator over the starting indices and content of all non-overlapping occurrences of a pattern within a string slice, in reverse order. Supports string slices, characters, and closures. ```rust let v: Vec<_> = "abcXXXabcYYYabc".rmatch_indices("abc").collect(); assert_eq!(v, [(12, "abc"), (6, "abc"), (0, "abc")]); let v: Vec<_> = "1abc2abc3".rmatch_indices(char::is_numeric).collect(); assert_eq!(v, [(7, "3"), (5, "2"), (1, "1")]); ``` -------------------------------- ### to_uppercase Source: https://docs.rs/ufbx/latest/ufbx/prelude/struct Returns the uppercase equivalent of this string slice. ```APIDOC ## POST /string/to_uppercase ### Description Returns the uppercase equivalent of this string slice, as a new `String`. Case conversion is based on Unicode case mapping rules. ### Method POST ### Endpoint /string/to_uppercase ### Parameters #### Request Body - **s** (string) - Required - The string to convert to uppercase. ### Response #### Success Response (200) - **result** (string) - The uppercase version of the string. #### Response Example ```json { "result": "HELLO" } ``` ``` -------------------------------- ### to_lowercase Source: https://docs.rs/ufbx/latest/ufbx/prelude/struct Returns the lowercase equivalent of this string slice. ```APIDOC ## POST /string/to_lowercase ### Description Returns the lowercase equivalent of this string slice, as a new `String`. Case conversion is based on Unicode case mapping rules. ### Method POST ### Endpoint /string/to_lowercase ### Parameters #### Request Body - **s** (string) - Required - The string to convert to lowercase. ### Response #### Success Response (200) - **result** (string) - The lowercase version of the string. #### Response Example ```json { "result": "hello" } ``` ``` -------------------------------- ### Chain Fallible Operations with `sq_then_to_string` Source: https://docs.rs/ufbx/latest/ufbx/generated/type Demonstrates chaining fallible operations using a custom function `sq_then_to_string`. This function squares a u32 and converts it to a string, handling potential overflows. It showcases how to use `and_then` to chain these operations, returning `Ok` with the string representation on success or `Err` on overflow or if the initial value was an error. ```rust fn sq_then_to_string(x: u32) -> Result { x.checked_mul(x).map(|sq| sq.to_string()).ok_or("overflowed") } assert_eq!(Ok(2).and_then(sq_then_to_string), Ok(4.to_string())); assert_eq!(Ok(1_000_000).and_then(sq_then_to_string), Err("overflowed")); assert_eq!(Err("not a number").and_then(sq_then_to_string), Err("not a number")); ``` -------------------------------- ### Provide Default Value with `unwrap_or` Source: https://docs.rs/ufbx/latest/ufbx/generated/type Illustrates using `unwrap_or` to retrieve the `Ok` value from a `Result` or a provided default value if the `Result` is `Err`. The `default` argument is eagerly evaluated. The examples show successful unwrapping and unwrapping with a default value when an error occurs. ```rust let default = 2; let x: Result = Ok(9); assert_eq!(x.unwrap_or(default), 9); let x: Result = Err("error"); assert_eq!(x.unwrap_or(default), default); ``` -------------------------------- ### trim_start_matches Source: https://docs.rs/ufbx/latest/ufbx/prelude/struct Removes all leading prefixes from a string that match a given pattern. ```APIDOC ## GET /string/trim_start_matches ### Description Returns a string slice with all prefixes that match a pattern repeatedly removed. ### Method GET ### Endpoint /string/trim_start_matches ### Parameters #### Query Parameters - **pat** (string | char | slice | function) - Required - The pattern to match prefixes against. ### Response #### Success Response (200) - **trimmed_string** (string) - The string slice with matching prefixes removed. #### Response Example ```json { "trimmed_string": "foo1bar11" } ``` ``` -------------------------------- ### Split a String Slice at a Byte Offset in Rust Source: https://docs.rs/ufbx/latest/ufbx/prelude/struct Divides a string slice into two at a specified byte offset. The offset must be on a UTF-8 code point boundary. Returns two slices: one from the start to the offset, and one from the offset to the end. ```rust let s = "Per Martin-Löf"; let (first, last) = s.split_at(3); assert_eq!("Per", first); assert_eq!(" Martin-Löf", last); ``` -------------------------------- ### trim_start() - Remove Leading Whitespace Source: https://docs.rs/ufbx/latest/ufbx/prelude/struct Returns a string slice with leading whitespace removed. 'Whitespace' is defined by Unicode White_Space property. ```APIDOC ## trim_start() ### Description Returns a string slice with leading whitespace removed. ‘Whitespace’ is defined according to the terms of the Unicode Derived Core Property `White_Space`, which includes newlines. ### Method `&self` (implicitly within a string context) ### Endpoint N/A (This is a method on string slices) ### Parameters #### Query Parameters N/A ### Request Example ```rust let s = "\n Hello\tworld\t\n"; assert_eq!("Hello\tworld\t\n", s.trim_start()); ``` ### Response #### Success Response (200) - **trimmed_string** (string) - The string slice with leading whitespace removed. #### Response Example ``` "Hello\tworld\t\n" ``` ``` -------------------------------- ### Check if String is Empty Source: https://docs.rs/ufbx/latest/ufbx/prelude/struct Shows how to check if a `ufbx::prelude::String` is empty (has a length of zero bytes) using the `is_empty()` method. ```rust let s = ""; assert!(s.is_empty()); let s = "not empty"; assert!(!s.is_empty()); ``` -------------------------------- ### Reverse string matching with rmatch_indices Source: https://docs.rs/ufbx/latest/ufbx/prelude/struct Demonstrates reverse searching within strings using the `rmatch_indices` method, which returns an iterator yielding tuples of the starting index and the matched substring. This method is useful for finding all non-overlapping occurrences of a pattern from the end of the string backwards. ```rust let v: Vec<_> = "abcXXXabcYYYabc".rmatch_indices("abc").collect(); assert_eq!(v, [(12, "abc"), (6, "abc"), (0, "abc")]); let v: Vec<_> = "1abcabc2".rmatch_indices("abc").collect(); assert_eq!(v, [(4, "abc"), (1, "abc")]); let v: Vec<_> = "ababa".rmatch_indices("aba").collect(); assert_eq!(v, [(2, "aba")]); // only the last `aba` ``` -------------------------------- ### Unchecked Unwrap of Error with `unwrap_err_unchecked` Source: https://docs.rs/ufbx/latest/ufbx/generated/type Details the `unwrap_err_unchecked` method, which returns the contained `Err` value without checking if the `Result` is `Ok`. This method is `unsafe`, and calling it on an `Ok` results in undefined behavior. The example shows the unsafe usage with an `Ok` and a successful unwrapping of an `Err` value. ```rust let x: Result = Ok(2); unsafe { x.unwrap_err_unchecked() }; // Undefined behavior! let x: Result = Err("emergency failure"); assert_eq!(unsafe { x.unwrap_err_unchecked() }, "emergency failure"); ``` -------------------------------- ### Split String by Whitespace (Rust) Source: https://docs.rs/ufbx/latest/ufbx/prelude/struct Demonstrates splitting a string slice into substrings based on Unicode whitespace using `split_whitespace()`. Handles multiple whitespace characters between words. ```Rust let mut iter = "A few words".split_whitespace(); assert_eq!(Some("A"), iter.next()); assert_eq!(Some("few"), iter.next()); assert_eq!(Some("words"), iter.next()); assert_eq!(None, iter.next()); ``` ```Rust let mut iter = " Mary had\ta\u{2009}little \n\t lamb".split_whitespace(); assert_eq!(Some("Mary"), iter.next()); assert_eq!(Some("had"), iter.next()); assert_eq!(Some("a"), iter.next()); assert_eq!(Some("little"), iter.next()); assert_eq!(Some("lamb"), iter.next()); assert_eq!(None, iter.next()); ``` ```Rust assert_eq!("".split_whitespace().next(), None); assert_eq!(" ".split_whitespace().next(), None); ``` -------------------------------- ### Find Substring Range using Pointer Arithmetic in Rust (Nightly) Source: https://docs.rs/ufbx/latest/ufbx/prelude/struct Returns the byte range of a substring within a string slice using pointer arithmetic. This is a nightly-only experimental API and does not perform a search. It may return false positives for zero-length substrings at the start or end. ```rust #![feature(substr_range)] let data = "a, b, b, a"; let mut iter = data.substr_range(s).unwrap(); assert_eq!(iter.next(), Some(0..1)); assert_eq!(iter.next(), Some(3..4)); assert_eq!(iter.next(), Some(6..7)); assert_eq!(iter.next(), Some(9..10)); ``` -------------------------------- ### split_once Source: https://docs.rs/ufbx/latest/ufbx/prelude/struct Splits the string on the first occurrence of the specified delimiter and returns the prefix before the delimiter and the suffix after the delimiter. ```APIDOC ## POST /split_once ### Description Splits the string on the first occurrence of the specified delimiter and returns the prefix before the delimiter and the suffix after the delimiter. ### Method POST ### Endpoint /split_once ### Parameters #### Request Body - **text** (string) - Required - The string to split. - **delimiter** (string) - Required - The delimiter to split by. ### Request Example ```json { "text": "cfg=foo=bar", "delimiter": "=" } ``` ### Response #### Success Response (200) - **prefix** (string) - The part of the string before the delimiter. - **suffix** (string) - The part of the string after the delimiter. #### Response Example ```json { "prefix": "cfg", "suffix": "foo=bar" } ``` ``` -------------------------------- ### Handle `Err` with Lazy `or_else` Source: https://docs.rs/ufbx/latest/ufbx/generated/type Showcases the `or_else` method for `Result`, which lazily calls a closure if the `Result` is `Err`. The closure receives the error value and must return a `Result`. This is useful for control flow based on error values. The examples demonstrate chaining `or_else` calls and handling different error scenarios. ```rust fn sq(x: u32) -> Result { Ok(x * x) } fn err(x: u32) -> Result { Err(x) } assert_eq!(Ok(2).or_else(sq).or_else(sq), Ok(2)); assert_eq!(Ok(2).or_else(err).or_else(sq), Ok(2)); assert_eq!(Err(3).or_else(sq).or_else(err), Ok(9)); assert_eq!(Err(3).or_else(err).or_else(err), Err(3)); ``` -------------------------------- ### PartialEq for Result Source: https://docs.rs/ufbx/latest/ufbx/generated/type Partial equality implementation for Result type. ```APIDOC ## impl PartialEq for Result ### Description Tests for equality between `Result` values. Two `Ok` variants are equal if their contained values are equal. Two `Err` variants are equal if their contained errors are equal. An `Ok` variant is never equal to an `Err` variant. ### Methods - `eq(&self, other: &Result) -> bool` - `ne(&self, other: &Rhs) -> bool` ### Endpoint N/A (Methods on the Result type) ### Parameters - **self**: The first `Result` instance. - **other**: The second `Result` instance to compare against. ### Request Example ```rust assert_eq!(Ok(5), Ok(5)); assert_ne!(Ok(5), Ok(6)); assert_ne!(Ok(5), Err(5)); assert_eq!(Err(5), Err(5)); assert_ne!(Err(5), Err(6)); ``` ### Response #### Success Response - **bool**: `true` if the `Result` values are equal, `false` otherwise. #### Response Example (See Request Example for usage) ```