### Trim Start Example Source: https://docs.rs/numtoa/1.0.0/numtoa/struct.AsciiNumber.html?search= Demonstrates removing leading whitespace from a string, considering text directionality. ```rust let s = " עברית "; assert!(Some('ע') == s.trim_start().chars().next()); ``` -------------------------------- ### Example Search Queries Source: https://docs.rs/numtoa/latest/numtoa/fn.numtoa_i32.html?search=u32+-%3E+bool These are example search queries that demonstrate common patterns or types of searches one might perform on Docs.rs. ```text std::vec ``` ```text u32 -> bool ``` ```text Option, (T -> U) -> Option ``` -------------------------------- ### Example Search: Option Mapping Source: https://docs.rs/numtoa/latest/numtoa/fn.numtoa_i16_str.html?search=std%3A%3Avec This is an example search query illustrating the mapping of a function over an Option type. ```rust Option, (T -> U) -> Option ``` -------------------------------- ### AsciiNumber Length Example Source: https://docs.rs/numtoa/1.0.0/numtoa/struct.AsciiNumber.html?search= Demonstrates how to get the byte length of a string. Note that this might not be the human-perceived character count. ```rust let len = "foo".len(); assert_eq!(3, len); assert_eq!("ƒoo".len(), 4); // fancy f! assert_eq!("ƒoo".chars().count(), 3); ``` -------------------------------- ### Trim Start Matches Examples Source: https://docs.rs/numtoa/1.0.0/numtoa/struct.AsciiNumber.html?search= Removes prefixes that match a given pattern, which can be a character, numeric check, or slice of characters. ```rust assert_eq!("11foo1bar11".trim_start_matches('1'), "foo1bar11"); assert_eq!("123foo1bar123".trim_start_matches(char::is_numeric), "foo1bar123"); ``` -------------------------------- ### Example Searches Source: https://docs.rs/numtoa/1.0.0/numtoa/struct.AsciiNumber.html?search= Common search patterns demonstrated. ```text * std::vec * u32 -> bool * Option, (T -> U) -> Option ``` -------------------------------- ### Convenience Example Source: https://docs.rs/numtoa/1.0.0/src/numtoa/lib.rs.html Demonstrates a convenient way to convert numbers to strings and append them to a String. ```APIDOC ## Convenience Example ### Description This example shows how to use the `NumToA` trait to convert numbers to strings and append them to a `String`. ### Usage ```rust use numtoa::NumToA; let mut buf = [0u8; 20]; let mut string = String::new(); for number in (1..10) { string.push_str(number.numtoa_str(10, &mut buf)); string.push('\n'); } println!("{}", string); ``` ``` -------------------------------- ### Convenience Example: Number to String Conversion Source: https://docs.rs/numtoa/1.0.0/index.html Demonstrates a convenient way to convert numbers to strings using a reusable buffer. This example iterates through numbers, converts them to base 10 strings, and appends them to a single string with newline separators. ```rust use numtoa::NumToA; let mut buf = [0u8; 20]; let mut string = String::new(); for number in (1..10) { string.push_str(number.numtoa_str(10, &mut buf)); string.push('\n'); } println!("{}", string); ``` -------------------------------- ### Example Search: std::vec Source: https://docs.rs/numtoa/latest/numtoa/fn.numtoa_i16_str.html?search=std%3A%3Avec This is an example search query related to the standard library's vector type. ```rust std::vec ``` -------------------------------- ### Example of trim_start_matches Source: https://docs.rs/numtoa/latest/numtoa/struct.AsciiNumber.html Demonstrates removing a slice of characters from the beginning of a string using `trim_start_matches`. ```rust let x: &[_] = &['1', '2']; assert_eq!("12foo1bar12".trim_start_matches(x), "foo1bar12"); ``` -------------------------------- ### Base 10 Example Source: https://docs.rs/numtoa/1.0.0/src/numtoa/lib.rs.html Illustrates converting various integer types to base 10 strings using a provided buffer. ```APIDOC ## Base 10 Example ### Description This example demonstrates converting different integer types (u32, i32, i8, i16, u64) to their base 10 string representations using the `numtoa` method and a mutable byte buffer. ### Usage ```rust use numtoa::NumToA; use std::io::{self, Write}; let stdout = io::stdout(); let mut stdout = stdout.lock(); let mut buffer = [0u8; 20]; let number_u32: u32 = 162392; let _ = stdout.write(number_u32.numtoa(10, &mut buffer)); let _ = stdout.write(b"\n"); assert_eq!(number_u32.numtoa(10, &mut buffer), b"162392"); let number_i32: i32 = -6235; let _ = stdout.write(number_i32.numtoa(10, &mut buffer)); let _ = stdout.write(b"\n"); assert_eq!(number_i32.numtoa(10, &mut buffer), b"-6235"); let number_i8: i8 = -128; let _ = stdout.write(number_i8.numtoa(10, &mut buffer)); let _ = stdout.write(b"\n"); assert_eq!(number_i8.numtoa(10, &mut buffer), b"-128"); let number_i8_pos: i8 = 53; let _ = stdout.write(number_i8_pos.numtoa(10, &mut buffer)); let _ = stdout.write(b"\n"); assert_eq!(number_i8_pos.numtoa(10, &mut buffer), b"53"); let number_i16: i16 = -256; let _ = stdout.write(number_i16.numtoa(10, &mut buffer)); let _ = stdout.write(b"\n"); assert_eq!(number_i16.numtoa(10, &mut buffer), b"-256"); let number_i16_min: i16 = -32768; let _ = stdout.write(number_i16_min.numtoa(10, &mut buffer)); let _ = stdout.write(b"\n"); assert_eq!(number_i16_min.numtoa(10, &mut buffer), b"-32768"); let number_u64: u64 = 35320842; let _ = stdout.write(number_u64.numtoa(10, &mut buffer)); let _ = stdout.write(b"\n"); assert_eq!(number_u64.numtoa(10, &mut buffer), b"35320842"); let number_u64_max: u64 = 18446744073709551615; let _ = stdout.write(number_u64_max.numtoa(10, &mut buffer)); let _ = stdout.write(b"\n"); assert_eq!(number_u64_max.numtoa(10, &mut buffer), b"18446744073709551615"); ``` ``` -------------------------------- ### Example of assert_eq with a slice Source: https://docs.rs/numtoa/1.0.0/numtoa/struct.AsciiNumber.html?search= This snippet demonstrates an assertion for comparing a string slice with a vector of string slices. It's an example of expected output format. ```rust assert_eq!(d, &["a", "b", "c"]); ``` -------------------------------- ### Base 10 Conversion Example Source: https://docs.rs/numtoa/1.0.0/src/numtoa/lib.rs.html?search= Demonstrates how to use the `numtoa` method for base 10 conversion with different integer types. ```APIDOC ## Base 10 Conversion Example This example shows the usage of `numtoa` for converting various integer types to their base 10 string representation. ### Usage ```rust use numtoa::NumToA; use std::io::{self, Write}; let mut buffer = [0u8; 20]; // Unsigned integer let number_u32: u32 = 162392; assert_eq!(number_u32.numtoa(10, &mut buffer), b"162392"); // Signed integer let number_i32: i32 = -6235; assert_eq!(number_i32.numtoa(10, &mut buffer), b"-6235"); // Smallest i8 let number_i8_min: i8 = -128; assert_eq!(number_i8_min.numtoa(10, &mut buffer), b"-128"); // Positive i8 let number_i8_pos: i8 = 53; assert_eq!(number_i8_pos.numtoa(10, &mut buffer), b"53"); // Negative i16 let number_i16: i16 = -256; assert_eq!(number_i16.numtoa(10, &mut buffer), b"-256"); // Smallest i16 let number_i16_min: i16 = -32768; assert_eq!(number_i16_min.numtoa(10, &mut buffer), b"-32768"); // Large unsigned integer let number_u64: u64 = 35320842; assert_eq!(number_u64.numtoa(10, &mut buffer), b"35320842"); // Maximum u64 let number_u64_max: u64 = 18446744073709551615; assert_eq!(number_u64_max.numtoa(10, &mut buffer), b"18446744073709551615"); ``` ``` -------------------------------- ### AsciiNumber Iterator Example Source: https://docs.rs/numtoa/1.0.0/numtoa/struct.AsciiNumber.html?search= Demonstrates iterating over ranges generated by AsciiNumber. ```rust assert_eq!(iter.next(), Some(Range { start: 0, end: 1 })); assert_eq!(iter.next(), Some(Range { start: 3, end: 4 })); assert_eq!(iter.next(), Some(Range { start: 6, end: 7 })); assert_eq!(iter.next(), Some(Range { start: 9, end: 10 })); ``` -------------------------------- ### Example Search: u32 to bool Conversion Source: https://docs.rs/numtoa/1.0.0/numtoa/fn.numtoa_i128.html?search=u32+-%3E+bool Illustrates a common search pattern for type conversions in Rust, specifically converting a `u32` to a `bool`. ```rust u32 -> bool ``` -------------------------------- ### AsciiNumber is_char_boundary Example Source: https://docs.rs/numtoa/1.0.0/numtoa/struct.AsciiNumber.html?search= Verifies if a given byte index is the start of a UTF-8 character sequence or the end of the string. ```rust let s = "Löwe 老虎 Léopard"; assert!(s.is_char_boundary(0)); // start of `老` assert!(s.is_char_boundary(6)); assert!(s.is_char_boundary(s.len())); // second byte of `ö` assert!(!s.is_char_boundary(2)); // third byte of `老` assert!(!s.is_char_boundary(8)); ``` -------------------------------- ### Trimming Start with Text Directionality Source: https://docs.rs/numtoa/1.0.0/numtoa/struct.AsciiNumber.html?search=std%3A%3Avec Demonstrates `trim_start` behavior considering text directionality. For left-to-right languages, it trims from the left; for right-to-left, it trims from the right. ```Rust let s = " English "; assert!(Some('E') == s.trim_start().chars().next()); ``` -------------------------------- ### NumToA::numtoa Example Source: https://docs.rs/numtoa/1.0.0/numtoa/trait.NumToA.html?search= Demonstrates writing a number to a mutable byte slice using `numtoa`. Panics if the buffer is too small. Ensure the buffer is large enough for the conversion. ```rust use numtoa::NumToA; use std::io::{self, Write}; let stdout = io::stdout(); let stdout = &mut io::stdout(); // Allocate a buffer that will be reused in each iteration. let mut buffer = [0u8; 20]; let number = 15325; let _ = stdout.write(number.numtoa(10, &mut buffer)); let number = 1241; let _ = stdout.write(number.numtoa(10, &mut buffer)); assert_eq!(12345.numtoa(10, &mut buffer), b"12345"); ``` -------------------------------- ### numtoa_str Convenience Method Example Source: https://docs.rs/numtoa/1.0.0/src/numtoa/numtoa_trait.rs.html?search=u32+-%3E+bool Demonstrates the usage of the `numtoa_str` convenience method for obtaining a string slice representation of a number. ```APIDOC ## Method: numtoa_str ### Description Convenience method for quickly getting a string from the input's array buffer. ### Example ```rust assert_eq!("256123".numtoa_str(10, &mut [0u8; 20]), "256123"); ``` ``` -------------------------------- ### trim_start Source: https://docs.rs/numtoa/1.0.0/numtoa/struct.AsciiNumber.html?search= Returns a string slice with leading whitespace removed, based on Unicode's White_Space property. The definition of 'start' depends on text directionality. ```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. The definition of `start` depends on text directionality. ### Method `trim_start(&self) -> &str` ### Examples ```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()); ``` ``` -------------------------------- ### Base 10 Number to String Conversion with Assertions Source: https://docs.rs/numtoa/1.0.0/index.html Provides examples of converting various integer types (u32, i32, i8, i16, u64) to their base 10 string representations using a mutable byte buffer. It includes assertions to verify the correctness of the conversions and demonstrates writing to stdout. ```rust use numtoa::NumToA; use std::io::{self, Write}; let stdout = io::stdout(); let mut stdout = stdout.lock(); let mut buffer = [0u8; 20]; let number: u32 = 162392; let _ = stdout.write(number.numtoa(10, &mut buffer)); let _ = stdout.write(b"\n"); assert_eq!(number.numtoa(10, &mut buffer), b"162392"); let number: i32 = -6235; let _ = stdout.write(number.numtoa(10, &mut buffer)); let _ = stdout.write(b"\n"); assert_eq!(number.numtoa(10, &mut buffer), b"-6235"); let number: i8 = -128; let _ = stdout.write(number.numtoa(10, &mut buffer)); let _ = stdout.write(b"\n"); assert_eq!(number.numtoa(10, &mut buffer), b"-128"); let number: i8 = 53; let _ = stdout.write(number.numtoa(10, &mut buffer)); let _ = stdout.write(b"\n"); assert_eq!(number.numtoa(10, &mut buffer), b"53"); let number: i16 = -256; let _ = stdout.write(number.numtoa(10, &mut buffer)); let _ = stdout.write(b"\n"); assert_eq!(number.numtoa(10, &mut buffer), b"-256"); let number: i16 = -32768; let _ = stdout.write(number.numtoa(10, &mut buffer)); let _ = stdout.write(b"\n"); assert_eq!(number.numtoa(10, &mut buffer), b"-32768"); let number: u64 = 35320842; let _ = stdout.write(number.numtoa(10, &mut buffer)); let _ = stdout.write(b"\n"); assert_eq!(number.numtoa(10, &mut buffer), b"35320842"); let number: u64 = 18446744073709551615; let _ = stdout.write(number.numtoa(10, &mut buffer)); let _ = stdout.write(b"\n"); assert_eq!(number.numtoa(10, &mut buffer), b"18446744073709551615"); ``` -------------------------------- ### starts_with Source: https://docs.rs/numtoa/1.0.0/numtoa/struct.AsciiNumber.html?search= Checks if the string slice starts with a given pattern. The pattern can be a string slice, a character, a slice of characters, or a closure that determines if a character matches. ```APIDOC ## pub fn starts_with

(&self, pat: P) -> bool where P: Pattern, ### Description Returns `true` if the given pattern matches a prefix of this string slice. Returns `false` if it does not. The pattern can be a `&str`, in which case this function will return true if the `&str` is a prefix of this string slice. The pattern can also be a `char`, a slice of `char`s, or a function or closure that determines if a character matches. These will only be checked against the first character of this string slice. ### Examples ```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'])); ``` ``` -------------------------------- ### AsciiNumber as_ptr Example Source: https://docs.rs/numtoa/1.0.0/numtoa/struct.AsciiNumber.html?search= Obtains a raw pointer to the first byte of a string slice. This pointer must not be written to. ```rust let s = "Hello"; let ptr = s.as_ptr(); ``` -------------------------------- ### Trim End Directionality Examples Source: https://docs.rs/numtoa/1.0.0/numtoa/struct.AsciiNumber.html?search= Shows how trim_end handles trailing whitespace in both left-to-right and right-to-left text. ```rust let s = " English "; assert!(Some('h') == s.trim_end().chars().rev().next()); let s = " עברית "; assert!(Some('ת') == s.trim_end().chars().rev().next()); ``` -------------------------------- ### NumToA Trait Example: Writing to stdout Source: https://docs.rs/numtoa/latest/src/numtoa/numtoa_trait.rs.html?search=std%3A%3Avec Demonstrates using the `numtoa` method to write number conversions directly to standard output. Shows buffer reuse for efficiency. ```rust use numtoa::NumToA; use std::io::{self, Write}; let stdout = io::stdout(); let stdout = &mut io::stdout(); // Allocate a buffer that will be reused in each iteration. let mut buffer = [0u8; 20]; let number = 15325; let _ = stdout.write(number.numtoa(10, &mut buffer)); let number = 1241; let _ = stdout.write(number.numtoa(10, &mut buffer)); assert_eq!(12345.numtoa(10, &mut buffer), b"12345"); ``` -------------------------------- ### Base-2 Integer to String Conversion Source: https://docs.rs/numtoa/1.0.0/src/numtoa/numtoa_const.rs.html?search= Tests the conversion of an i32 integer to its base-2 string representation. This is a basic example of the `as_str()` functionality for binary conversion. ```rust assert_eq!("111110100001111011", BaseN::<2>::i32(256123).as_str()); ``` -------------------------------- ### NumToA Trait - Convenience Method Example Source: https://docs.rs/numtoa/1.0.0/src/numtoa/numtoa_trait.rs.html?search= Demonstrates the usage of the `numtoa_str` convenience method for obtaining a string slice directly from a number. ```rust #[test] fn str_convenience_trait() { assert_eq!("256123", 256123.numtoa_str(10, &mut [0u8; 20])); } ``` -------------------------------- ### AsciiNumber get Subslice Example Source: https://docs.rs/numtoa/1.0.0/numtoa/struct.AsciiNumber.html?search= Safely retrieves a subslice of a string slice using an index, returning None if the index is invalid or not on a UTF-8 character boundary. ```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()); ``` -------------------------------- ### AsciiNumber ceil_char_boundary Example Source: https://docs.rs/numtoa/1.0.0/numtoa/struct.AsciiNumber.html?search= Finds the closest character boundary not below a given byte index, useful for ensuring a string slice starts at a valid UTF-8 character boundary. ```rust let s = "❤️🧡💛💚💙💜"; assert_eq!(s.len(), 26); assert!(!s.is_char_boundary(13)); let closest = s.ceil_char_boundary(13); assert_eq!(closest, 14); assert_eq!(&s[..closest], "❤️🧡💛"); ``` -------------------------------- ### Base-N Convenience Functions for i32 Source: https://docs.rs/numtoa/latest/src/numtoa/numtoa_const.rs.html?search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Demonstrates the use of convenience functions for converting i32 integers to strings in different bases (binary, octal, decimal, hexadecimal). ```rust #[test] fn str_convenience_base2() { assert_eq!("111110100001111011", BaseN::<2>::i32(256123).as_str()); } ``` ```rust #[test] fn str_convenience_base8() { assert_eq!("764173", BaseN::<8>::i32(256123).as_str()); } ``` ```rust #[test] fn str_convenience_base10() { assert_eq!("256123", BaseN::<10>::i32(256123).as_str()); } ``` ```rust #[test] fn str_convenience_base16() { assert_eq!("3E87B", BaseN::<16>::i32(256123).as_str()); } ``` -------------------------------- ### Padded Base-N Convenience Functions for i32 Source: https://docs.rs/numtoa/latest/src/numtoa/numtoa_const.rs.html?search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Shows how to use padded convenience functions to format i32 integers into strings with a specified width and padding character. ```rust #[test] fn str_convenience_base10_padded() { assert_eq!("00000000000000256123", BaseN::<10>::i32_padded::<20>(256123, b'0').as_str()); } ``` ```rust #[test] fn str_convenience_base16_padded() { assert_eq!("0000000000000003E87B", BaseN::<16>::i32_padded::<20>(256123, b'0').as_str()); } ``` -------------------------------- ### Any::type_id Source: https://docs.rs/numtoa/latest/numtoa/struct.AsciiNumber.html Gets the TypeId of the AsciiNumber. ```APIDOC ## fn type_id(&self) -> TypeId ### Description Gets the `TypeId` of `self`. ### Method `type_id` ### Parameters - `&self` (T) - The value to get the TypeId from. ### Returns TypeId - The TypeId of the value. ``` -------------------------------- ### T::type_id Source: https://docs.rs/numtoa/latest/numtoa/struct.AsciiNumber.html?search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Gets the `TypeId` of a type. ```APIDOC ## T::type_id ### Description Gets the `TypeId` of `self`. ### Method `fn type_id(&self) -> TypeId` ``` -------------------------------- ### Any type_id Method Source: https://docs.rs/numtoa/1.0.0/numtoa/struct.AsciiNumber.html?search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Gets the TypeId of a value implementing the Any trait. ```rust fn type_id(&self) -> TypeId ``` -------------------------------- ### impl Any for T Source: https://docs.rs/numtoa/1.0.0/numtoa/struct.BaseN.html?search=std%3A%3Avec Provides the `type_id` method to get the `TypeId` of an object. ```APIDOC ## fn type_id(&self) -> TypeId ### Description Gets the `TypeId` of `self`. ### Method `type_id` ### Parameters None ### Return Value `TypeId` - The unique identifier for the type of `self`. ``` -------------------------------- ### Wacky Padding and Filling with Base-N Source: https://docs.rs/numtoa/latest/src/numtoa/numtoa_const.rs.html?search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Demonstrates the flexibility of padding and filling functions with unusual characters and negative numbers for base-16 and base-10 conversions. ```rust #[test] fn str_convenience_wacky_padding() { assert_eq!("##############-3E87B", BaseN::<16>::i32_padded::<20>(-256123, b'#').as_str()); assert_eq!("@@@@@@@@@@@-111", BaseN::<10>::i8_padded::<15>(-111, b'@').as_str()); } ``` ```rust #[test] fn str_convenience_wacky_filling() { assert_eq!("##-3E87B", BaseN::<16>::i32_filled::<8>(-256123, b'#').as_str()); assert_eq!("@-3", BaseN::<10>::i8_filled::<3>(-3, b'@').as_str()); assert_eq!("-11", BaseN::<10>::i8_filled::<3>(-11, b'@').as_str()); } ``` -------------------------------- ### AsciiNumber is_empty Example Source: https://docs.rs/numtoa/1.0.0/numtoa/struct.AsciiNumber.html?search= Checks if a string slice has a length of zero bytes. ```rust let s = ""; assert!(s.is_empty()); let s = "not empty"; assert!(!s.is_empty()); ``` -------------------------------- ### i64 to Base 10 Conversion with Buffer Source: https://docs.rs/numtoa/1.0.0/src/numtoa/numtoa_trait.rs.html?search=u32+-%3E+bool Demonstrates converting an i64 to its base 10 string representation using a mutable byte buffer. Ensure the buffer is of sufficient size to hold the converted number. ```rust let mut buffer = [0u8; 19]; let _ = 0i64.numtoa(10, &mut buffer); ``` ```rust let mut buffer = [0u8; 20]; let _ = 0i64.numtoa(10, &mut buffer); ``` -------------------------------- ### AsciiNumber as_bytes Example Source: https://docs.rs/numtoa/1.0.0/numtoa/struct.AsciiNumber.html?search= Converts a string slice into its underlying byte slice representation. ```rust let bytes = "bors".as_bytes(); assert_eq!(b"bors", bytes); ``` -------------------------------- ### i64 Base 10 Conversion with Buffer Source: https://docs.rs/numtoa/1.0.0/src/numtoa/numtoa_trait.rs.html?search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Demonstrates converting an i64 to a base-10 string using a mutable byte buffer. Ensure the buffer is of sufficient size to avoid panics in debug mode. ```rust let mut buffer = [0u8; 19]; let _ = 0i64.numtoa(10, &mut buffer); ``` ```rust let mut buffer = [0u8; 20]; let _ = 0i64.numtoa(10, &mut buffer); ``` -------------------------------- ### trim_end: Directionality Example (Hebrew) Source: https://docs.rs/numtoa/latest/numtoa/struct.AsciiNumber.html?search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Demonstrates removing trailing whitespace considering text directionality for Hebrew. ```Rust let s = " עברית "; assert!(Some('ת') == s.trim_end().chars().rev().next()); ``` -------------------------------- ### Filled Base-N Convenience Functions for i32 Source: https://docs.rs/numtoa/latest/src/numtoa/numtoa_const.rs.html?search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Illustrates the usage of filled convenience functions for formatting i32 integers, ensuring a minimum width with a specified fill character. ```rust #[test] fn str_convenience_base10_filled() { assert_eq!("12", BaseN::<10>::i32_filled::<1>(12, b'0').as_str()); assert_eq!("00012", BaseN::<10>::i32_filled::<5>(12, b'0').as_str()); assert_eq!("123456", BaseN::<10>::i32_filled::<5>(123456, b'0').as_str()); } ``` ```rust #[test] fn str_convenience_base16_filled() { assert_eq!("7B", BaseN::<16>::i32_filled::<1>(123, b'0').as_str()); assert_eq!("0007B", BaseN::<16>::i32_filled::<5>(123, b'0').as_str()); assert_eq!("BC614E", BaseN::<16>::i32_filled::<5>(12345678, b'0').as_str()); } ``` -------------------------------- ### trim_end: Directionality Example (English) Source: https://docs.rs/numtoa/latest/numtoa/struct.AsciiNumber.html?search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Demonstrates removing trailing whitespace considering text directionality for English. ```Rust let s = " English "; assert!(Some('h') == s.trim_end().chars().rev().next()); ``` -------------------------------- ### Rust parse failing example Source: https://docs.rs/numtoa/1.0.0/numtoa/struct.AsciiNumber.html?search=u32+-%3E+bool Demonstrates a failed parse operation when the string cannot be converted to the target type. ```rust let nope = "j".parse::(); assert!(nope.is_err()); ``` -------------------------------- ### BaseN<2> Conversions for i32 Source: https://docs.rs/numtoa/latest/numtoa/struct.BaseN.html?search=u32+-%3E+bool Provides constants for the required space and functions to convert i32 to its ASCII representation in base 2. ```APIDOC ## BaseN<2> Conversions for i32 ### Description Functions to convert an `i32` to its ASCII representation in base 2. Includes constants for required space. ### Constants * `REQUIRED_SPACE_I32`: `usize` - The number of bytes required to convert an arbitrary `i32` to its ASCII representation in base 2. ``` -------------------------------- ### AsciiNumber as_str Method Source: https://docs.rs/numtoa/1.0.0/numtoa/struct.AsciiNumber.html?search= Shows how to get a string slice representation of an AsciiNumber. This is a nightly-only experimental API. ```rust /// Returns the same string as a string slice `&str`. /// This method is redundant when used directly on `&str`, but it helps dereferencing other string-like types to string slices, for example references to `Box` or `Arc`. ``` -------------------------------- ### BaseN<2> Conversions for i64 Source: https://docs.rs/numtoa/latest/numtoa/struct.BaseN.html?search=u32+-%3E+bool Provides constants for the required space and functions to convert i64 to its ASCII representation in base 2. ```APIDOC ## BaseN<2> Conversions for i64 ### Description Functions to convert an `i64` to its ASCII representation in base 2. Includes constants for required space. ### Constants * `REQUIRED_SPACE_I64`: `usize` - The number of bytes required to convert an arbitrary `i64` to its ASCII representation in base 2. ``` -------------------------------- ### starts_with Source: https://docs.rs/numtoa/latest/numtoa/struct.AsciiNumber.html?search= Checks if the string slice begins with the given pattern. ```APIDOC ## starts_with ### Description Returns `true` if the given pattern matches a prefix of this string slice. Returns `false` if it does not. The pattern can be a `&str`, `char`, a slice of `char`s, or a function or closure that determines if a character matches. For `char` or `&[char]`, only the first character of the string slice is checked. ### Method `starts_with

(&self, pat: P) -> bool` where `P: Pattern` ### Parameters * `pat` (P): The pattern to check against the prefix. Can be `&str`, `char`, `&[char]`, or a closure `FnMut(char) -> bool`. ### Response Returns `bool`: `true` if the string starts with the pattern, `false` otherwise. ### Examples ```rust let bananas = "bananas"; assert!(bananas.starts_with("bana")); assert!(!bananas.starts_with("nana")); ``` ```rust let bananas = "bananas"; assert!(bananas.starts_with(&['b', 'a', 'n', 'a'])); assert!(bananas.starts_with(&['a', 'b', 'c', 'd'])); ``` ``` -------------------------------- ### AsciiNumber::into_inner method Source: https://docs.rs/numtoa/1.0.0/src/numtoa/numtoa_const.rs.html?search=std%3A%3Avec Consumes the `AsciiNumber` to return the underlying byte buffer and the starting position of the string. ```rust pub const fn into_inner(self) -> ([u8; N], usize) { (self.string, self.start) } ``` -------------------------------- ### u64 Base 10 Conversion with Buffer Source: https://docs.rs/numtoa/1.0.0/src/numtoa/numtoa_trait.rs.html?search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Shows how to convert a u64 to a base-10 string using a mutable byte buffer. In debug builds, providing a buffer that is too small will cause a panic. ```rust let mut buffer = [0u8; 19]; let _ = 0u64.numtoa(10, &mut buffer); ``` ```rust let mut buffer = [0u8; 20]; let _ = 0u64.numtoa(10, &mut buffer); ``` -------------------------------- ### trim_start Source: https://docs.rs/numtoa/1.0.0/numtoa/struct.AsciiNumber.html?search=u32+-%3E+bool Returns a string slice with leading whitespace removed. ```APIDOC ## pub fn trim_start(&self) -> &str ### 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. ### Text directionality A string is a sequence of bytes. `start` in this context means the first position of that byte string; for a left-to-right language like English or Russian, this will be left side, and for right-to-left languages like Arabic or Hebrew, this will be the right side. ### Examples Basic usage: ```rust let s = "\n Hello\tworld\t\n"; assert_eq!("Hello\tworld\t\n", s.trim_start()); ``` Directionality: ```rust let s = " English "; assert!(Some('E') == s.trim_start().chars().next()); ``` ``` -------------------------------- ### match_indices Source: https://docs.rs/numtoa/1.0.0/numtoa/struct.AsciiNumber.html?search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E 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 ## match_indices

(&self, pat: P) -> MatchIndices<'_, P> ### Description Returns an iterator over the disjoint matches of a pattern within this string slice as well as the index that the match starts at. For matches of `pat` within `self` that overlap, only the indices corresponding to the first match are returned. The pattern can be a `&str`, `char`, a slice of `char`s, or a function or closure that determines if a character matches. ### Iterator behavior The returned iterator will be a `DoubleEndedIterator` if the pattern allows a reverse search and forward/reverse search yields the same elements. This is true for, e.g., `char`, but not for `&str`. If the pattern allows a reverse search but its results might differ from a forward search, the `rmatch_indices` method can be used. ### Examples ```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")]); // only the first `aba` ``` ``` -------------------------------- ### match_indices Source: https://docs.rs/numtoa/1.0.0/numtoa/struct.AsciiNumber.html?search=u32+-%3E+bool 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 ## pub fn match_indices

(&self, pat: P) -> MatchIndices<'_, P> ### Description Returns an iterator over the disjoint matches of a pattern within this string slice as well as the index that the match starts at. For matches of `pat` within `self` that overlap, only the indices corresponding to the first match are returned. The pattern can be a `&str`, `char`, a slice of `char`s, or a function or closure that determines if a character matches. ### Iterator behavior The returned iterator will be a `DoubleEndedIterator` if the pattern allows a reverse search and forward/reverse search yields the same elements. This is true for, e.g., `char`, but not for `&str`. If the pattern allows a reverse search but its results might differ from a forward search, the `rmatch_indices` method can be used. ### Examples ```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")]); // only the first `aba` ``` ``` -------------------------------- ### AsciiNumber ZERO constant Source: https://docs.rs/numtoa/1.0.0/src/numtoa/numtoa_const.rs.html?search=std%3A%3Avec Provides a const-initialized `AsciiNumber` representing zero, with the buffer pre-filled and the start index set. ```rust pub const ZERO: AsciiNumber = { let mut string = [0_u8; N]; string[N - 1] = b'0'; let start = N - 1; AsciiNumber { string, start } }; ``` -------------------------------- ### CloneToUninit CloneToUninit Method Source: https://docs.rs/numtoa/1.0.0/numtoa/struct.AsciiNumber.html?search= Performs copy-assignment from self to a raw pointer destination. This is a nightly-only experimental API. ```rust /// Performs copy-assignment from `self` to `dest`. Read more ``` -------------------------------- ### trim_right: Directionality Example (Hebrew) Source: https://docs.rs/numtoa/latest/numtoa/struct.AsciiNumber.html?search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Demonstrates removing trailing whitespace considering text directionality for Hebrew. This method is deprecated. ```Rust let s = "עברית "; assert!(Some('ת') == s.trim_right().chars().rev().next()); ``` -------------------------------- ### CloneToUninit::clone_to_uninit Source: https://docs.rs/numtoa/latest/numtoa/struct.AsciiNumber.html Performs copy-assignment from self to an uninitialized destination. 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 `clone_to_uninit` ### Parameters - `&self` (T) - The value to copy. - `dest` (*mut u8) - A mutable pointer to the uninitialized destination memory. ### Safety This method is unsafe because it requires `dest` to be a valid, writable pointer to enough memory to hold a `T`. ``` -------------------------------- ### trim_right: Directionality Example (English) Source: https://docs.rs/numtoa/latest/numtoa/struct.AsciiNumber.html?search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Demonstrates removing trailing whitespace considering text directionality for English. This method is deprecated. ```Rust let s = "English "; assert!(Some('h') == s.trim_right().chars().rev().next()); ``` -------------------------------- ### trim_left: Directionality Example (Hebrew) Source: https://docs.rs/numtoa/latest/numtoa/struct.AsciiNumber.html?search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Demonstrates removing leading whitespace considering text directionality for Hebrew. This method is deprecated. ```Rust let s = " עברית"; assert!(Some('ע') == s.trim_left().chars().next()); ``` -------------------------------- ### BaseN<2> Conversions for u32 Source: https://docs.rs/numtoa/1.0.0/numtoa/struct.BaseN.html?search=u32+-%3E+bool Provides constants and functions for converting u32 to its ASCII representation in base 2. Includes functions for direct conversion, left-padded conversion, and left-filled conversion. ```APIDOC ## BaseN<2>::REQUIRED_SPACE_U32 ### Description The number of bytes required to convert an arbitrary u32 to its ASCII representation in base 2. ## BaseN<2>::u32 ### Description Converts the specified u32 to its ASCII representation in base 2. ### Parameters - `num` (u32) - The unsigned 32-bit integer to convert. ### Returns An AsciiNumber with the required space for the base 2 representation. ## BaseN<2>::u32_padded ### Description Converts the specified u32 to its ASCII representation in base 2, left-padded to the specified length with the provided padding byte. ### Parameters - `num` (u32) - The unsigned 32-bit integer to convert. - `padding` (u8) - The byte to use for left-padding. ### Returns An AsciiNumber of the specified LENGTH. ## BaseN<2>::u32_filled ### Description Converts the specified u32 to its ASCII representation in base 2, left-filled to the specified length with the provided byte. ### Parameters - `num` (u32) - The unsigned 32-bit integer to convert. - `fill` (u8) - The byte to use for left-filling. ### Returns An AsciiNumber with the required space for the base 2 representation. ``` -------------------------------- ### Trim Left Directionality Examples (Deprecated) Source: https://docs.rs/numtoa/1.0.0/numtoa/struct.AsciiNumber.html?search= Demonstrates removing leading whitespace, considering text directionality. This method is deprecated. ```rust let s = " English"; assert!(Some('E') == s.trim_left().chars().next()); let s = " עברית"; assert!(Some('ע') == s.trim_left().chars().next()); ``` -------------------------------- ### BaseN<2> Conversions for i16 Source: https://docs.rs/numtoa/latest/numtoa/struct.BaseN.html?search=u32+-%3E+bool Provides constants for the required space and functions to convert i16 to its ASCII representation in base 2. ```APIDOC ## BaseN<2> Conversions for i16 ### Description Functions to convert an `i16` to its ASCII representation in base 2. Includes constants for required space. ### Constants * `REQUIRED_SPACE_I16`: `usize` - The number of bytes required to convert an arbitrary `i16` to its ASCII representation in base 2. ``` -------------------------------- ### BaseN<2> Conversions for u64 Source: https://docs.rs/numtoa/1.0.0/numtoa/struct.BaseN.html?search=u32+-%3E+bool Provides constants and functions for converting u64 to its ASCII representation in base 2. Includes functions for direct conversion, left-padded conversion, and left-filled conversion. ```APIDOC ## BaseN<2>::REQUIRED_SPACE_U64 ### Description The number of bytes required to convert an arbitrary u64 to its ASCII representation in base 2. ## BaseN<2>::u64 ### Description Converts the specified u64 to its ASCII representation in base 2. ### Parameters - `num` (u64) - The unsigned 64-bit integer to convert. ### Returns An AsciiNumber with the required space for the base 2 representation. ## BaseN<2>::u64_padded ### Description Converts the specified u64 to its ASCII representation in base 2, left-padded to the specified length with the provided padding byte. ### Parameters - `num` (u64) - The unsigned 64-bit integer to convert. - `padding` (u8) - The byte to use for left-padding. ### Returns An AsciiNumber of the specified LENGTH. ## BaseN<2>::u64_filled ### Description Converts the specified u64 to its ASCII representation in base 2, left-filled to the specified length with the provided byte. ### Parameters - `num` (u64) - The unsigned 64-bit integer to convert. - `fill` (u8) - The byte to use for left-filling. ### Returns An AsciiNumber with the required space for the base 2 representation. ``` -------------------------------- ### Trim Matches Example Source: https://docs.rs/numtoa/1.0.0/numtoa/struct.AsciiNumber.html?search=std%3A%3Avec Removes all prefixes and suffixes that match a given pattern repeatedly. The pattern can be a char, a slice of chars, or a closure. ```rust assert_eq!("11foo1bar11".trim_matches('1'), "foo1bar"); ``` ```rust assert_eq!("123foo1bar123".trim_matches(char::is_numeric), "foo1bar"); ``` ```rust let x: &[_] = &['1', '2']; assert_eq!("12foo1bar12".trim_matches(x), "foo1bar"); ``` ```rust assert_eq!("1foo1barXX".trim_matches(|c| c == '1' || c == 'X'), "foo1bar"); ``` -------------------------------- ### BaseN<2> Conversions for i8 Source: https://docs.rs/numtoa/latest/numtoa/struct.BaseN.html?search=u32+-%3E+bool Provides constants for the required space and functions to convert i8 to its ASCII representation in base 2. ```APIDOC ## BaseN<2> Conversions for i8 ### Description Functions to convert an `i8` to its ASCII representation in base 2. Includes constants for required space. ### Constants * `REQUIRED_SPACE_I8`: `usize` - The number of bytes required to convert an arbitrary `i8` to its ASCII representation in base 2. ``` -------------------------------- ### BaseN<2> Implementations Source: https://docs.rs/numtoa/1.0.0/numtoa/struct.BaseN.html This section details the implementations for BaseN with base 2, including constants for required space and conversion functions for various unsigned and signed integer types. ```APIDOC ## BaseN<2> ### Description API to convert numbers into ascii string in base 2. Infallible & const-friendly. Returns an AsciiNumber of fixed size based on the selected base and numeric type. ### Constants - **REQUIRED_SPACE_U8**: `usize` - The number of bytes required to convert an arbitrary u8 to its ASCII representation in base 2. - **REQUIRED_SPACE_U16**: `usize` - The number of bytes required to convert an arbitrary u16 to its ASCII representation in base 2. - **REQUIRED_SPACE_U32**: `usize` - The number of bytes required to convert an arbitrary u32 to its ASCII representation in base 2. - **REQUIRED_SPACE_U64**: `usize` - The number of bytes required to convert an arbitrary u64 to its ASCII representation in base 2. - **REQUIRED_SPACE_U128**: `usize` - The number of bytes required to convert an arbitrary u128 to its ASCII representation in base 2. - **REQUIRED_SPACE_USIZE**: `usize` - The number of bytes required to convert an arbitrary usize to its ASCII representation in base 2. - **REQUIRED_SPACE_I8**: `usize` - The number of bytes required to convert an arbitrary i8 to its ASCII representation in base 2. - **REQUIRED_SPACE_I16**: `usize` - The number of bytes required to convert an arbitrary i16 to its ASCII representation in base 2. - **REQUIRED_SPACE_I32**: `usize` - The number of bytes required to convert an arbitrary i32 to its ASCII representation in base 2. - **REQUIRED_SPACE_I64**: `usize` - The number of bytes required to convert an arbitrary i64 to its ASCII representation in base 2. - **REQUIRED_SPACE_I128**: `usize` - The number of bytes required to convert an arbitrary i128 to its ASCII representation in base 2. - **REQUIRED_SPACE_ISIZE**: `usize` - The number of bytes required to convert an arbitrary isize to its ASCII representation in base 2. ### Functions #### `u8(num: u8) -> AsciiNumber<{ Self::REQUIRED_SPACE_U8 }>` Converts the specified u8 to its ASCII representation in base 2. #### `u8_padded(num: u8, padding: u8) -> AsciiNumber` Converts the specified u8 to its ASCII representation in base 2, left-padded to the specified length with the provided byte. #### `u8_filled(num: u8, fill: u8) -> AsciiNumber<{ Self::REQUIRED_SPACE_U8 }>` Converts the specified u8 to its ASCII representation in base 2, left-filled to the specified length with the provided byte. #### `u16(num: u16) -> AsciiNumber<{ Self::REQUIRED_SPACE_U16 }>` Converts the specified u16 to its ASCII representation in base 2. #### `u16_padded(num: u16, padding: u8) -> AsciiNumber` Converts the specified u16 to its ASCII representation in base 2, left-padded to the specified length with the provided byte. #### `u16_filled(num: u16, fill: u8) -> AsciiNumber<{ Self::REQUIRED_SPACE_U16 }>` Converts the specified u16 to its ASCII representation in base 2, left-filled to the specified length with the provided byte. #### `u32(num: u32) -> AsciiNumber<{ Self::REQUIRED_SPACE_U32 }>` Converts the specified u32 to its ASCII representation in base 2. #### `u32_padded(num: u32, padding: u8) -> AsciiNumber` Converts the specified u32 to its ASCII representation in base 2, left-padded to the specified length with the provided byte. #### `u32_filled(num: u32, fill: u8) -> AsciiNumber<{ Self::REQUIRED_SPACE_U32 }>` Converts the specified u32 to its ASCII representation in base 2, left-filled to the specified length with the provided byte. #### `u64(num: u64) -> AsciiNumber<{ Self::REQUIRED_SPACE_U64 }>` Converts the specified u64 to its ASCII representation in base 2. #### `u64_padded(num: u64, padding: u8) -> AsciiNumber` Converts the specified u64 to its ASCII representation in base 2, left-padded to the specified length with the provided byte. #### `u64_filled(num: u64, fill: u8) -> AsciiNumber<{ Self::REQUIRED_SPACE_U64 }>` Converts the specified u64 to its ASCII representation in base 2, left-filled to the specified length with the provided byte. #### `u128(num: u128) -> AsciiNumber<{ Self::REQUIRED_SPACE_U128 }>` Converts the specified u128 to its ASCII representation in base 2. ``` -------------------------------- ### Trim Right Directionality Examples (Deprecated) Source: https://docs.rs/numtoa/1.0.0/numtoa/struct.AsciiNumber.html?search= Shows how trim_right handles trailing whitespace in different text directions. This method is deprecated. ```rust let s = "English "; assert!(Some('h') == s.trim_right().chars().rev().next()); let s = "עברית "; assert!(Some('ת') == s.trim_right().chars().rev().next()); ```