### Example of underline() Source: https://docs.rs/rust_decimal/latest/rust_decimal/enum.RoundingStrategy.html?search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Demonstrates how to use the underline() method to apply underline formatting. ```rust println!("{}", value.underline()); ``` -------------------------------- ### Example of bold() Source: https://docs.rs/rust_decimal/latest/rust_decimal/enum.RoundingStrategy.html?search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Demonstrates how to use the bold() method to apply bold formatting. ```rust println!("{}", value.bold()); ``` -------------------------------- ### Example of blink() Source: https://docs.rs/rust_decimal/latest/rust_decimal/enum.RoundingStrategy.html?search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Demonstrates how to use the blink() method to apply blink formatting. ```rust println!("{}", value.blink()); ``` -------------------------------- ### Example of on_magenta() Source: https://docs.rs/rust_decimal/latest/rust_decimal/enum.RoundingStrategy.html?search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Demonstrates how to use the on_magenta() method to set the background color to magenta. ```rust println!("{}", value.on_magenta()); ``` -------------------------------- ### Examples of Product on Result Iterator Source: https://docs.rs/rust_decimal/latest/rust_decimal/type.Result.html?search=std%3A%3Avec Demonstrates using the `product` method on an iterator of `Result`s. The first example shows a successful multiplication, while the second shows an error due to a non-parseable string. ```rust let nums = vec!["5", "10", "1", "2"]; let total: Result = nums.iter().map(|w| w.parse::()).product(); assert_eq!(total, Ok(100)); let nums = vec!["5", "10", "one", "2"]; let total: Result = nums.iter().map(|w| w.parse::()).product(); assert!(total.is_err()); ``` -------------------------------- ### Example of rapid_blink() Source: https://docs.rs/rust_decimal/latest/rust_decimal/enum.RoundingStrategy.html?search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Demonstrates how to use the rapid_blink() method to apply rapid blink formatting. ```rust println!("{}", value.rapid_blink()); ``` -------------------------------- ### Example of on_cyan() Source: https://docs.rs/rust_decimal/latest/rust_decimal/enum.RoundingStrategy.html?search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Demonstrates how to use the on_cyan() method to set the background color to cyan. ```rust println!("{}", value.on_cyan()); ``` -------------------------------- ### Example of on_bright_white() Source: https://docs.rs/rust_decimal/latest/rust_decimal/enum.RoundingStrategy.html?search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Demonstrates how to use the on_bright_white() method to set the background color to bright white. ```rust println!("{}", value.on_bright_white()); ``` -------------------------------- ### Example of on_bright_cyan() Source: https://docs.rs/rust_decimal/latest/rust_decimal/enum.RoundingStrategy.html?search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Demonstrates how to use the on_bright_cyan() method to set the background color to bright cyan. ```rust println!("{}", value.on_bright_cyan()); ``` -------------------------------- ### Example of on_bright_black() Source: https://docs.rs/rust_decimal/latest/rust_decimal/enum.RoundingStrategy.html?search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Demonstrates how to use the on_bright_black() method to set the background color to bright black. ```rust println!("{}", value.on_bright_black()); ``` -------------------------------- ### Example of Rounding to 2 Decimal Places Source: https://docs.rs/rust_decimal/latest/src/rust_decimal/decimal.rs.html?search=u32+-%3E+bool Demonstrates how to use the `round_dp` method to round a Decimal to two decimal places. The example uses the `dec!` macro for easy Decimal creation. ```rust # use rust_decimal::Decimal; # use rust_decimal_macros::dec; # let pi = dec!(3.1415926535897932384626433832); assert_eq!(pi.round_dp(2).to_string(), "3.14"); ``` -------------------------------- ### Example of strike() Source: https://docs.rs/rust_decimal/latest/rust_decimal/enum.RoundingStrategy.html?search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Demonstrates how to use the strike() method to apply strike-through formatting. ```rust println!("{}", value.strike()); ``` -------------------------------- ### Example of on_bright_red() Source: https://docs.rs/rust_decimal/latest/rust_decimal/enum.RoundingStrategy.html?search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Demonstrates how to use the on_bright_red() method to set the background color to bright red. ```rust println!("{}", value.on_bright_red()); ``` -------------------------------- ### Example of on_white() Source: https://docs.rs/rust_decimal/latest/rust_decimal/enum.RoundingStrategy.html?search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Demonstrates how to use the on_white() method to set the background color to white. ```rust println!("{}", value.on_white()); ``` -------------------------------- ### Example of conceal() Source: https://docs.rs/rust_decimal/latest/rust_decimal/enum.RoundingStrategy.html?search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Demonstrates how to use the conceal() method to hide text. ```rust println!("{}", value.conceal()); ``` -------------------------------- ### Example of dim() Source: https://docs.rs/rust_decimal/latest/rust_decimal/enum.RoundingStrategy.html?search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Demonstrates how to use the dim() method to apply dim formatting. ```rust println!("{}", value.dim()); ``` -------------------------------- ### Example of on_blue() Source: https://docs.rs/rust_decimal/latest/rust_decimal/enum.RoundingStrategy.html?search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Demonstrates how to use the on_blue() method to set the background color to blue. ```rust println!("{}", value.on_blue()); ``` -------------------------------- ### Example of on_bright_magenta() Source: https://docs.rs/rust_decimal/latest/rust_decimal/enum.RoundingStrategy.html?search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Demonstrates how to use the on_bright_magenta() method to set the background color to bright magenta. ```rust println!("{}", value.on_bright_magenta()); ``` -------------------------------- ### Example of invert() Source: https://docs.rs/rust_decimal/latest/rust_decimal/enum.RoundingStrategy.html?search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Demonstrates how to use the invert() method to invert the colors. ```rust println!("{}", value.invert()); ``` -------------------------------- ### Example of on_bright_blue() Source: https://docs.rs/rust_decimal/latest/rust_decimal/enum.RoundingStrategy.html?search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Demonstrates how to use the on_bright_blue() method to set the background color to bright blue. ```rust println!("{}", value.on_bright_blue()); ``` -------------------------------- ### Example of italic() Source: https://docs.rs/rust_decimal/latest/rust_decimal/enum.RoundingStrategy.html?search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Demonstrates how to use the italic() method to apply italic formatting. ```rust println!("{}", value.italic()); ``` -------------------------------- ### Create New Painted Example Source: https://docs.rs/rust_decimal/latest/rust_decimal/serde/struct.DecimalFromString.html?search=u32+-%3E+bool Creates a new Painted object with a default style. ```rust Painted::new() ``` -------------------------------- ### Example of on_green() Source: https://docs.rs/rust_decimal/latest/rust_decimal/enum.RoundingStrategy.html?search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Demonstrates how to use the on_green() method to set the background color to green. ```rust println!("{}", value.on_green()); ``` -------------------------------- ### Example of on_bright_green() Source: https://docs.rs/rust_decimal/latest/rust_decimal/enum.RoundingStrategy.html?search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Demonstrates how to use the on_bright_green() method to set the background color to bright green. ```rust println!("{}", value.on_bright_green()); ``` -------------------------------- ### Example of on_yellow() Source: https://docs.rs/rust_decimal/latest/rust_decimal/enum.RoundingStrategy.html?search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Demonstrates how to use the on_yellow() method to set the background color to yellow. ```rust println!("{}", value.on_yellow()); ``` -------------------------------- ### Rust Decimal: Background Color Examples Source: https://docs.rs/rust_decimal/latest/rust_decimal/enum.Error.html Demonstrates setting background colors using `bg()` and `on_red()`. ```rust use yansi::{Paint, Color}; painted.bg(Color::Red); ``` ```rust use yansi::Paint; painted.on_red(); ``` -------------------------------- ### Example of on_bright_yellow() Source: https://docs.rs/rust_decimal/latest/rust_decimal/enum.RoundingStrategy.html?search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Demonstrates how to use the on_bright_yellow() method to set the background color to bright yellow. ```rust println!("{}", value.on_bright_yellow()); ``` -------------------------------- ### Apply Style Wholesale Example Source: https://docs.rs/rust_decimal/latest/rust_decimal/serde/struct.DecimalFromString.html?search=u32+-%3E+bool Applies a given style wholesale to the painted object, replacing any previous style. ```rust painted.paint(style) ``` -------------------------------- ### AwayFromZero Rounding Example Source: https://docs.rs/rust_decimal/latest/rust_decimal/enum.RoundingStrategy.html Demonstrates rounding away from zero, increasing the magnitude of the number. ```rust e.g. -6.8 -> -7, 6.8 -> 7 ``` -------------------------------- ### MidpointAwayFromZero Rounding Example Source: https://docs.rs/rust_decimal/latest/rust_decimal/enum.RoundingStrategy.html Demonstrates MidpointAwayFromZero rounding, where halfway cases are rounded to the number furthest from zero. ```rust e.g. 6.4 -> 6, 6.5 -> 7, -6.5 -> -7 ``` -------------------------------- ### Product of Results Example: Successful Multiplication Source: https://docs.rs/rust_decimal/latest/rust_decimal/type.Result.html?search=u32+-%3E+bool Demonstrates the `product` method on an iterator of `Result`s where all elements are successfully parsed and multiplied. ```rust let nums = vec!["5", "10", "1", "2"]; let total: Result = nums.iter().map(|w| w.parse::()).product(); assert_eq!(total, Ok(100)); ``` -------------------------------- ### Bincode Serialization with Optional String Feature Source: https://docs.rs/rust_decimal/latest/src/rust_decimal/serde.rs.html?search= Handles bincode serialization and deserialization for a struct containing an optional Decimal using the 'str_option' Serde module. This example is incomplete and only shows the setup. ```rust #[cfg(feature = "serde-with-str")] fn with_str_bincode_optional() { use bincode::{deserialize, serialize}; #[derive(Serialize, Deserialize)] struct BincodeExample { #[serde(with = "crate::serde::str_option")] value: Option, } // Some(value) } ``` -------------------------------- ### Get Raw Layout Source: https://docs.rs/rust_decimal/latest/rust_decimal/struct.Decimal.html?search=std%3A%3Avec Gets the raw memory layout of the type. ```APIDOC ## fn layout_raw(_: ::Metadata) -> Result ### Description Gets the layout of the type. ### Parameters - `_`: Metadata related to the pointer. ### Returns - `Result`: Ok containing the `Layout` or Err containing a `LayoutError`. ``` -------------------------------- ### Handle Invalid Decimal Input: Leading Underscore Source: https://docs.rs/rust_decimal/latest/src/rust_decimal/str.rs.html Tests parsing a string that starts with an underscore, which is not a valid start for a decimal number. The function should return an error. ```rust assert_eq!( parse_str_radix_10("_"), Err(Error::from("Invalid decimal: must start lead with a number")) ); ``` -------------------------------- ### Convert Rust Decimal to PostgreSQL Positive Numeric (Second Example) Source: https://docs.rs/rust_decimal/latest/src/rust_decimal/postgres/diesel.rs.html?search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Another example of converting a positive Rust Decimal to PostgreSQL Numeric, demonstrating handling of different digit sequences. ```rust let expected = Decimal::from_str("1.2345678901234567890123456790").unwrap(); let pg_numeric = PgNumeric::Positive { weight: 0, scale: 34, digits: vec![1, 2345, 6789, 0123, 4567, 8901, 2345, 6789, 5000, 0], }; let res: Decimal = pg_numeric.try_into().unwrap(); assert_eq!(res.to_string(), expected.to_string()); ``` -------------------------------- ### LayoutRaw Trait Source: https://docs.rs/rust_decimal/latest/rust_decimal/enum.Error.html?search=u32+-%3E+bool Gets the layout of a type. ```APIDOC ## Trait: LayoutRaw Gets the layout of a type. ### Methods #### `fn layout_raw(_: ::Metadata) -> Result` Gets the layout of the type. ``` -------------------------------- ### layout_raw Source: https://docs.rs/rust_decimal/latest/rust_decimal/struct.Decimal.html?search= Gets the raw memory layout of the type. ```APIDOC ## fn layout_raw(_: ::Metadata) -> Result ### Description Gets the layout of the type. ### Parameters * `_`: Metadata related to the type's pointer. ### Returns A `Result` containing the `Layout` of the type or a `LayoutError`. ``` -------------------------------- ### Layout Raw Source: https://docs.rs/rust_decimal/latest/rust_decimal/struct.Decimal.html Gets the raw memory layout of the type. ```APIDOC ## fn layout_raw(_: ::Metadata) -> Result ### Description Gets the layout of the type. ### Method (Method within `LayoutRaw` trait implementation) ### Parameters - **_**: ::Metadata - Metadata for the type. ### Returns - Result - The layout of the type or a layout error. ``` -------------------------------- ### LayoutRaw for T Source: https://docs.rs/rust_decimal/latest/rust_decimal/serde/struct.DecimalFromString.html?search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Provides a method to get the raw layout of a type `T`. ```APIDOC ## fn layout_raw(_: ::Metadata) -> Result ### Description Gets the raw memory layout of the type `T`. This method requires metadata associated with a pointer to the type. ### Method `layout_raw` ### Parameters - `_`: The metadata associated with a pointer to `T`. ### Returns A `Result` containing the `Layout` of the type on success, or a `LayoutError` on failure. ``` -------------------------------- ### Decimal::declaration Source: https://docs.rs/rust_decimal/latest/rust_decimal/struct.Decimal.html?search=std%3A%3Avec Gets the name of the Decimal type without brackets. ```APIDOC ## declaration ### Description Get the name of the type without brackets. ### Method `declaration` ### Returns - `Declaration` - The declaration of the Decimal type. ``` -------------------------------- ### Get Decimal Scale Source: https://docs.rs/rust_decimal/latest/rust_decimal/struct.Decimal.html Retrieves the scale (exponent) of the Decimal number. ```rust let num = Decimal::new(1234, 3); assert_eq!(num.scale(), 3u32); ``` -------------------------------- ### Get the DecWide one value Source: https://docs.rs/rust_decimal/latest/src/rust_decimal/ops/wide.rs.html?search=std%3A%3Avec Returns a `DecWide` representation of the number one. ```rust pub const fn one() -> DecWide { DecWide::from_decimal(&Decimal::ONE) } ``` -------------------------------- ### Get LayoutRaw for Type Source: https://docs.rs/rust_decimal/latest/rust_decimal/enum.Error.html?search= Retrieves the layout information for a type based on its metadata. ```rust fn layout_raw(_: ::Metadata) -> Result ``` -------------------------------- ### Initialization Source: https://docs.rs/rust_decimal/latest/rust_decimal/struct.Decimal.html?search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Creates a new `Painted` object with a default style. ```APIDOC ## `new()` ### Description Create a new `Painted` with a default `Style`. Read more ### Method `new()` ### Example ```rust // Example usage would go here, assuming 'Painted' is constructible ``` ``` -------------------------------- ### Initialization Source: https://docs.rs/rust_decimal/latest/rust_decimal/struct.Decimal.html?search=u32+-%3E+bool Method to create a new `Painted` object. ```APIDOC ## fn new(self) -> Painted ### Description Create a new `Painted` with a default `Style`. Read more ### Method `new` ### Example ```rust // Example usage would go here, assuming 'self' is a type that can be painted. // For instance, if 'value' is a string or other displayable type: // let painted_value = value.new(); ``` ``` -------------------------------- ### Get Decimal Mantissa Source: https://docs.rs/rust_decimal/latest/rust_decimal/struct.Decimal.html Retrieves the mantissa (the integer part before scaling) of the Decimal number. ```rust let num = dec!(-1.2345678); assert_eq!(num.mantissa(), -12345678i128); assert_eq!(num.scale(), 7); ``` -------------------------------- ### init Source: https://docs.rs/rust_decimal/latest/rust_decimal/struct.Decimal.html?search= Initializes and returns the parsing context for `Self`. ```APIDOC ## fn init ### Description Initializes and returns the parsing context for `Self`. ### Parameters - `opts`: `Options` - The options for initialization. ### Returns - `>::Context`: The initialized parsing context. ``` -------------------------------- ### Creation and Styling Methods Source: https://docs.rs/rust_decimal/latest/rust_decimal/serde/struct.DecimalFromString.html?search= Methods for creating a new Painted instance and applying styles. ```APIDOC ## fn new() ### Description Create a new `Painted` with a default `Style`. ### Method (Called as a constructor) ### Example ```rust // Assuming 'Painted' is in scope let painted_instance = Painted::new(); ``` ## fn paint(style: S) ### Description Apply a style wholesale to `self`. Any previous style is replaced. ### Method (Implicitly called on a `Painted` object) ### Parameters #### Path Parameters - **style** (S: Into