### Accessing Metadata with `and_then` Source: https://docs.rs/signifix/0.10.1/signifix/metric/type.Result.html This example demonstrates chaining fallible operations using `and_then` to get file metadata and modified time. It handles potential errors like file not found. ```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); ``` -------------------------------- ### into_ok() - Get Ok value, never panics Source: https://docs.rs/signifix/0.10.1/signifix/binary/type.Result.html Returns the contained Ok value. This method is guaranteed not to panic. ```APIDOC ## into_ok() ### Description Returns the contained `Ok` value, but never panics. This method is known to never panic on the result types it is implemented for. ### Method `into_ok` ### Parameters None ### Request Example ```rust fn only_good_news() -> Result { Ok("this is fine".into()) } let s: String = only_good_news().into_ok(); println!("{s}"); ``` ### Response #### Success Response (T) - The contained `Ok` value. #### Response Example ```rust // If Ok(value), returns value // This method is designed for Result types where the Err variant is unreachable (!). ``` ``` -------------------------------- ### Handling File Metadata Operations with `Result` Source: https://docs.rs/signifix/0.10.1/signifix/binary/type.Result.html Demonstrates using `Result` and `and_then` for file system operations like getting metadata, which can fail due to path errors or permissions. Note that path interpretation can be OS-dependent. ```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); ``` -------------------------------- ### Undefined Behavior Example: `unwrap_err_unchecked` on Ok Source: https://docs.rs/signifix/0.10.1/signifix/metric/type.Result.html Demonstrates the undefined behavior that occurs when `unwrap_err_unchecked` is called on a `Result` that is `Ok`. ```rust let x: Result = Ok(2); unsafe { x.unwrap_err_unchecked() }; // Undefined behavior! ``` -------------------------------- ### Collect Results with Underflow Check Source: https://docs.rs/signifix/0.10.1/signifix/metric/type.Result.html This example shows `collect` used with `checked_sub` to detect underflow. The operation stops and returns the first `Err` encountered. ```rust let v = vec![1, 2, 0]; let res: Result, &'static str> = v.iter().map(|x: &u32| x.checked_sub(1).ok_or("Underflow!") ).collect(); assert_eq!(res, Err("Underflow!")); ``` -------------------------------- ### unwrap_or_default() - Get Ok value or default Source: https://docs.rs/signifix/0.10.1/signifix/binary/type.Result.html Returns the contained Ok value or the default value for the type if the Result is Err. ```APIDOC ## unwrap_or_default() ### Description Returns the contained `Ok` value or a default value for the type if `self` is `Err`. ### Method `unwrap_or_default` ### Parameters None ### Request Example ```rust let good_year_from_input = "1909"; let bad_year_from_input = "190blarg"; let good_year = good_year_from_input.parse::().unwrap_or_default(); let bad_year = bad_year_from_input.parse::().unwrap_or_default(); assert_eq!(1909, good_year); assert_eq!(0, bad_year); ``` ### Response #### Success Response (T) - The contained `Ok` value or the default value of type `T`. #### Response Example ```rust // If Ok(value), returns value // If Err, returns default::default() ``` ``` -------------------------------- ### unwrap() - Get Ok value or panic Source: https://docs.rs/signifix/0.10.1/signifix/binary/type.Result.html Retrieves the value from an Ok variant. Panics if the Result is an Err, using the error's value as the panic message. ```APIDOC ## unwrap() ### Description Returns the contained `Ok` value. Panics if the `self` is `Err`. ### Method `unwrap` ### Parameters None ### Request Example ```rust let x: Result = Ok(2); assert_eq!(x.unwrap(), 2); ``` ### Response #### Success Response (T) - The contained `Ok` value. #### Response Example ```rust // If Ok(2), returns 2 // If Err("message"), panics with "message" ``` ``` -------------------------------- ### into_err() - Get Err value, never panics Source: https://docs.rs/signifix/0.10.1/signifix/binary/type.Result.html Returns the contained Err value. This method is guaranteed not to panic. ```APIDOC ## into_err() ### Description Returns the contained `Err` value, but never panics. This method is known to never panic on the result types it is implemented for. ### Method `into_err` ### Parameters None ### Request Example ```rust fn only_bad_news() -> Result { Err("Oops, it failed".into()) } let error: String = only_bad_news().into_err(); println!("{error}"); ``` ### Response #### Success Response (E) - The contained `Err` value. #### Response Example ```rust // If Err(value), returns value // This method is designed for Result types where the Ok variant is unreachable (!). ``` ``` -------------------------------- ### Format numbers with Signifix notations Source: https://docs.rs/signifix/0.10.1/signifix/index.html Demonstrates how to use metric and binary prefixes to format numbers into fixed-width strings. ```rust use std::convert::TryFrom; use signifix::{metric, binary, Result}; let metric = |number| -> Result<(String, String)> { let number = metric::Signifix::try_from(number)?; Ok((format!("{}", number), format!("{:#}", number))) }; let binary = |number| -> Result { let number = binary::Signifix::try_from(number)?; Ok(format!("{}", number)) }; // Three different decimal mark positions covering the three powers of ten // of a particular metric prefix. assert_eq!(metric(1E-04), Ok(("100.0 µ".into(), "100µ0".into()))); // 3rd assert_eq!(metric(1E-03), Ok(("1.000 m".into(), "1m000".into()))); // 1st assert_eq!(metric(1E-02), Ok(("10.00 m".into(), "10m00".into()))); // 2nd assert_eq!(metric(1E-01), Ok(("100.0 m".into(), "100m0".into()))); // 3rd assert_eq!(metric(1E+00), Ok(("1.000 ".into(), "1#000".into()))); // 1st assert_eq!(metric(1E+01), Ok(("10.00 ".into(), "10#00".into()))); // 2nd assert_eq!(metric(1E+02), Ok(("100.0 ".into(), "100#0".into()))); // 3rd assert_eq!(metric(1E+03), Ok(("1.000 k".into(), "1k000".into()))); // 1st assert_eq!(metric(1E+04), Ok(("10.00 k".into(), "10k00".into()))); // 2nd assert_eq!(metric(1E+05), Ok(("100.0 k".into(), "100k0".into()))); // 3rd assert_eq!(metric(1E+06), Ok(("1.000 M".into(), "1M000".into()))); // 1st // Three different decimal mark positions and a thousands separator covering // the four powers of ten of a particular binary prefix. assert_eq!(binary(1_024f64.powi(0) * 1E+00), Ok("1.000 ".into())); // 1st assert_eq!(binary(1_024f64.powi(0) * 1E+01), Ok("10.00 ".into())); // 2nd assert_eq!(binary(1_024f64.powi(0) * 1E+02), Ok("100.0 ".into())); // 3rd assert_eq!(binary(1_024f64.powi(0) * 1E+03), Ok("1 000 ".into())); // 4th assert_eq!(binary(1_024f64.powi(1) * 1E+00), Ok("1.000 Ki".into())); // 1st assert_eq!(binary(1_024f64.powi(1) * 1E+01), Ok("10.00 Ki".into())); // 2nd assert_eq!(binary(1_024f64.powi(1) * 1E+02), Ok("100.0 Ki".into())); // 3rd assert_eq!(binary(1_024f64.powi(1) * 1E+03), Ok("1 000 Ki".into())); // 4th assert_eq!(binary(1_024f64.powi(2) * 1E+00), Ok("1.000 Mi".into())); // 1st // Rounding over prefixes is safe against floating-point inaccuracies. assert_eq!(metric(999.949_999_999_999_8), Ok(("999.9 ".into(), "999#9".into()))); assert_eq!(metric(999.949_999_999_999_9), Ok(("1.000 k".into(), "1k000".into()))); assert_eq!(binary(1_023.499_999_999_999_94), Ok("1 023 ".into())); assert_eq!(binary(1_023.499_999_999_999_95), Ok("1.000 Ki".into())); ``` -------------------------------- ### impl Product> for Result Source: https://docs.rs/signifix/0.10.1/signifix/type.Result.html Provides the Product implementation for Result, allowing multiplication of Results if T implements Product. ```APIDOC ## Product> for Result ### Description This implementation allows for the multiplication of `Result` types, provided that the `Ok` type `T` implements the `Product` trait for the `Ok` type `U`. ### Method `product` (from the `Product` trait) ### Endpoint N/A (Implementation detail) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```rust // Example requires T to implement Product // For instance, if T is Vec let results: Vec> = vec![Ok(2), Ok(3)]; let product_result: Result = results.into_iter().product(); assert_eq!(product_result, Ok(6)); let results_with_err: Vec> = vec![Ok(2), Err("error"), Ok(3)]; let product_result_err: Result = results_with_err.into_iter().product(); assert_eq!(product_result_err, Err("error")); ``` ### Response #### Success Response (200) - **Result** (type) - The product of the `Ok` values if all elements are `Ok`, otherwise the first `Err` encountered. #### Response Example ```rust // Ok(6) // Err("error") ``` ``` -------------------------------- ### into_ok() Source: https://docs.rs/signifix/0.10.1/signifix/type.Result.html Returns the contained `Ok` value. This is a nightly-only experimental API that is guaranteed not to panic. ```APIDOC ## into_ok() ### Description Returns the contained `Ok` value. This is a nightly-only experimental API that is guaranteed not to panic. ### Method `into_ok()` ### Parameters None ### Request Example ```rust fn only_good_news() -> Result { Ok("this is fine".into()) } let s: String = only_good_news().into_ok(); println!("{s}"); ``` ### Response #### Success Response (T) Returns the contained `Ok` value. #### Response Example ```rust // If Ok(value), returns value. ``` ``` -------------------------------- ### Undefined Behavior Example: `unwrap_unchecked` on Err Source: https://docs.rs/signifix/0.10.1/signifix/metric/type.Result.html Demonstrates the undefined behavior that occurs when `unwrap_unchecked` is called on a `Result` that is `Err`. ```rust let x: Result = Err("emergency failure"); unsafe { x.unwrap_unchecked() }; // Undefined behavior! ``` -------------------------------- ### Convert Result to Iterator (Ok Case) Source: https://docs.rs/signifix/0.10.1/signifix/metric/type.Result.html When a `Result` is `Ok`, `into_iter` yields a single element containing the value. This example collects the value into a vector. ```rust let x: Result = Ok(5); let v: Vec = x.into_iter().collect(); assert_eq!(v, [5]); ``` -------------------------------- ### Signifix Crate Overview Source: https://docs.rs/signifix/0.10.1/signifix/binary/index.html Provides an overview of the signifix crate's main components and their functionalities. ```APIDOC ## Module signifix Formatter of Signifix default notation with binary prefix. ### Structs #### Signifix Intermediate implementor type of this module’s `TryFrom` and `Display` trait implementations. Former tries to convert a given number into this type by determining the appropriate binary prefix, the normalized significand, and the decimal mark position while latter uses this type’s fields to format the number as a string of four significant figures inclusive the binary prefix symbol. ### Enums #### Error An error arising from this module’s `TryFrom` trait implementation for its `Signifix` type. ### Constants #### DEF_MAX_LEN Number of characters in default notation when a sign is prefixed. #### DEF_MIN_LEN Number of characters in default notation when no sign is prefixed. #### FACTORS Binary prefix factors from `1 024 ^ 1` to `1 024 ^ 8` indexed from `1` to `8`, or `1 024 ^ 0` indexed at `0`. #### SYMBOLS Binary prefix symbols from `Some("Ki")` to `Some("Yi")` indexed from `1` to `8`, or `None` indexed at `0`. ### Type Aliases #### Result The canonical `Result` type using this module’s `Error` type. ``` -------------------------------- ### Customize Output via Parts Source: https://docs.rs/signifix/0.10.1/signifix/index.html Extracts integer and fractional parts from Signifix to build custom formatted tables. ```rust use std::convert::TryFrom; use signifix::metric::{Signifix, Result}; struct SignifixTable<'a>(&'a[Signifix]); impl<'a> std::fmt::Display for SignifixTable<'a> { fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { f.pad(" Int Fra 10³\n")?; f.pad("---- ---- ----\n")?; for entry in self.0 { let (integer, fractional) = entry.parts(); f.pad(&format!("{:4} {:<3} {:2}\n", integer, fractional, entry.prefix() as i32 - 8))?; } Ok(()) } } let customization = |entries: &[_]| -> Result { let mut table = Vec::with_capacity(entries.len()); for entry in entries { table.push(Signifix::try_from(*entry)?); } Ok(SignifixTable(&table).to_string()) }; assert_eq!(customization(&[ 1.234E-06, 12.34E+00, -123.4E+24, ]), Ok(concat!( " Int Fra 10³\n", "---- ---- ----\n", " 1 234 -2\n", " 12 34 0\n", "-123 4 8\n", ).into())); ``` -------------------------------- ### try_into Conversion Method Source: https://docs.rs/signifix/0.10.1/signifix/metric/struct.Signifix.html Documentation for the try_into conversion method used for type transformation. ```APIDOC ## fn try_into(self) -> Result>::Error> ### Description Performs the conversion from one type to another, returning a Result to handle potential conversion errors. ### Parameters - **self** (T) - Required - The instance to be converted. ### Response - **Result>::Error>** - Returns the converted type U on success, or an error defined by the TryFrom implementation on failure. ``` -------------------------------- ### unwrap_err() - Get Err value Source: https://docs.rs/signifix/0.10.1/signifix/binary/type.Result.html Retrieves the error from an Err variant. Panics if the Result is an Ok, using the Ok's value as the panic message. ```APIDOC ## unwrap_err() ### Description Returns the contained `Err` value, consuming the `self` value. Panics if the value is an `Ok`. ### Method `unwrap_err` ### Parameters None ### Request Example ```rust let x: Result = Err("emergency failure"); assert_eq!(x.unwrap_err(), "emergency failure"); ``` ### Response #### Success Response (E) - The contained `Err` value. #### Response Example ```rust // If Err("message"), returns "message" // If Ok(2), panics with "2" ``` ``` -------------------------------- ### Display transfer rates in terminal Source: https://docs.rs/signifix/0.10.1/signifix/index.html Shows how to format transfer rates with custom handling for slow, idle, or error states. ```rust use std::convert::TryFrom; use std::f64; use std::time::Duration; use signifix::metric::{Signifix, Error, DEF_MIN_LEN}; let transfer_rate = |bytes: u64, duration: Duration| -> String { let seconds = duration.as_secs() as f64 + duration.subsec_nanos() as f64 * 1E-09; let bytes_per_second = bytes as f64 / seconds; let unit = "B/s"; let rate = match Signifix::try_from(bytes_per_second) { Ok(rate) => if rate.factor() < 1E+00 { " - slow - ".into() // instead of mB/s, µB/s, ... } else { format!("{}{}", rate, unit) // normal rate }, Err(case) => match case { Error::OutOfLowerBound(rate) => if rate == 0f64 { " - idle - " // no progress at all } else { " - slow - " // almost no progress }, Error::OutOfUpperBound(rate) => if rate == f64::INFINITY { " - ---- - " // zero nanoseconds } else { " - fast - " // awkwardly fast }, Error::Nan => " - ---- - ", // zero bytes in zero nanoseconds }.into(), }; debug_assert_eq!(rate.chars().count(), DEF_MIN_LEN + unit.chars().count()); rate }; assert_eq!(transfer_rate(42_667, Duration::from_secs(300)), "142.2 B/s"); assert_eq!(transfer_rate(42_667, Duration::from_secs(030)), "1.422 kB/s"); assert_eq!(transfer_rate(42_667, Duration::from_secs(003)), "14.22 kB/s"); assert_eq!(transfer_rate(00_001, Duration::from_secs(003)), " - slow - "); assert_eq!(transfer_rate(00_000, Duration::from_secs(003)), " - idle - "); assert_eq!(transfer_rate(42_667, Duration::from_secs(000)), " - ---- - "); ``` -------------------------------- ### Convert Result to Iterator (Err Case) Source: https://docs.rs/signifix/0.10.1/signifix/metric/type.Result.html When a `Result` is `Err`, `into_iter` yields no elements. This example shows collecting an `Err` result, which results in an empty vector. ```rust let x: Result = Err("nothing!"); let v: Vec = x.into_iter().collect(); assert_eq!(v, []); ``` -------------------------------- ### Visualize Filesize Differences Source: https://docs.rs/signifix/0.10.1/signifix/index.html Uses the metric module to format numeric differences with a plus sign for positive values and a constant indicator for zero. ```rust use std::convert::TryFrom; use signifix::metric::{Signifix, Error, Result}; let filesize_diff = |curr, prev| -> Result { Signifix::try_from(curr - prev).map(|diff| format!("{:+#}", diff)) .or_else(|case| if case == Error::OutOfLowerBound(0f64) { Ok("=const".into()) } else { Err(case) }) }; assert_eq!(filesize_diff(78_346, 57_393), Ok("+20k95".into())); assert_eq!(filesize_diff(93_837, 93_837), Ok("=const".into())); assert_eq!(filesize_diff(27_473, 36_839), Ok("-9k366".into())); ``` -------------------------------- ### Calculate Boundary Statistics Source: https://docs.rs/signifix/0.10.1/signifix/index.html Utilizes the binary module to represent memory usage as a percentage of a total size, handling small values with a specific threshold. ```rust use std::convert::TryFrom; use signifix::binary::{Signifix, Error, Result}; let boundary_stat = |used: u64, size: u64| -> Result { if used == 0 { let size = Signifix::try_from(size)?; return Ok(format!(" 0 B ( 0 %) of {}B", size)); } let p100 = Signifix::try_from(used as f64 / size as f64 * 100.0) .map(|p100| format!("{:.*} %", p100.exponent(), p100.significand())) .or_else(|error| if let Error::OutOfLowerBound(_) = error { Ok(" < 1 %".into()) } else { Err(error) })?; let used = Signifix::try_from(used)?; let size = Signifix::try_from(size)?; Ok(format!("{}B ({}) of {}B", used, p100, size)) }; assert_eq!(boundary_stat(0_000u64.pow(1), 1_024u64.pow(3)), Ok(" 0 B ( 0 %) of 1.000 GiB".into())); assert_eq!(boundary_stat(1_024u64.pow(2), 1_024u64.pow(3)), Ok("1.000 MiB ( < 1 %) of 1.000 GiB".into())); assert_eq!(boundary_stat(3_292u64.pow(2), 1_024u64.pow(3)), Ok("10.34 MiB (1.009 %) of 1.000 GiB".into())); assert_eq!(boundary_stat(8_192u64.pow(2), 1_024u64.pow(3)), Ok("64.00 MiB (6.250 %) of 1.000 GiB".into())); assert_eq!(boundary_stat(1_000u64.pow(3), 1_024u64.pow(3)), Ok("953.7 MiB (93.13 %) of 1.000 GiB".into())); assert_eq!(boundary_stat(1_024u64.pow(3), 1_024u64.pow(3)), Ok("1.000 GiB (100.0 %) of 1.000 GiB".into())); ``` -------------------------------- ### expect_err() - Get Err value or panic Source: https://docs.rs/signifix/0.10.1/signifix/binary/type.Result.html Retrieves the error from an Err variant. Panics if the Result is an Ok, including the provided message and the Ok's content in the panic message. ```APIDOC ## expect_err() ### Description Returns the contained `Err` value, consuming the `self` value. Panics if the value is an `Ok`. ### Method `expect_err` ### Parameters - **msg** (string) - Required - The message to include in the panic if the Result is `Ok`. ### Request Example ```rust let x: Result = Ok(10); x.expect_err("Testing expect_err"); // panics with `Testing expect_err: 10` ``` ### Response #### Success Response (E) - The contained `Err` value. #### Response Example ```rust // If Err("message"), returns "message" // If Ok(10), panics with "Testing expect_err: 10" ``` ``` -------------------------------- ### fn product Source: https://docs.rs/signifix/0.10.1/signifix/binary/type.Result.html Calculates the product of elements in an iterator of Results, short-circuiting on the first Err encountered. ```APIDOC ## fn product(iter: I) -> Result ### Description Takes each element in the Iterator: if it is an Err, no further elements are taken, and the Err is returned. Should no Err occur, the product of all elements is returned. ### Parameters #### Path Parameters - **iter** (Iterator>) - Required - The iterator containing Result values to multiply. ``` -------------------------------- ### Collect Results from Iterator Source: https://docs.rs/signifix/0.10.1/signifix/metric/type.Result.html Use `collect` to aggregate results from an iterator. If any element is an Err, it's returned immediately. Otherwise, a container with all Ok values is returned. This example demonstrates checking for overflow. ```rust let v = vec![1, 2]; let res: Result, &'static str> = v.iter().map(|x: &u32| x.checked_add(1).ok_or("Overflow!") ).collect(); assert_eq!(res, Ok(vec![2, 3])); ``` -------------------------------- ### Signifix Formatting Source: https://docs.rs/signifix/0.10.1/signifix/binary/struct.Signifix.html Custom formatting method for localized output. ```APIDOC ## fmt ### Description Format trait implementation allowing explicit localization of the output string. ### Parameters - **decimal_mark** (str) - The character used as the decimal separator. - **grouping_sep** (str) - The character used as the grouping separator. ### Response - **Result** - Returns the formatted string representation of the Signifix value. ``` -------------------------------- ### Constant DEF_MIN_LEN Source: https://docs.rs/signifix/0.10.1/signifix/metric/constant.DEF_MIN_LEN.html Documentation for the DEF_MIN_LEN constant used in signifix::metric. ```APIDOC ## CONSTANT DEF_MIN_LEN ### Description Number of characters in default notation when no sign is prefixed. ### Definition `pub const DEF_MIN_LEN: usize = 7;` ``` -------------------------------- ### Constant DEF_MAX_LEN Source: https://docs.rs/signifix/0.10.1/signifix/binary/constant.DEF_MAX_LEN.html Documentation for the DEF_MAX_LEN constant used in the signifix crate. ```APIDOC ## Constant: DEF_MAX_LEN ### Description Represents the number of characters in the default notation when a sign is prefixed. ### Value 9 (usize) ``` -------------------------------- ### TryInto Trait Methods Source: https://docs.rs/signifix/0.10.1/signifix/binary/struct.Signifix.html Documentation for the try_into conversion method and its associated error type. ```APIDOC ## try_into ### Description Performs the conversion from one type to another, returning a Result containing the converted type or an error. ### Method Rust Trait Method ### Parameters - **self** (T) - Required - The instance to be converted. ### Response #### Success Response - **Result** - Returns the converted type U or the associated conversion error. ``` -------------------------------- ### Convert Result to reference with as_ref Source: https://docs.rs/signifix/0.10.1/signifix/metric/type.Result.html Produces a new Result containing references to the original values. ```rust let x: Result = Ok(2); assert_eq!(x.as_ref(), Ok(&2)); let x: Result = Err("Error"); assert_eq!(x.as_ref(), Err(&"Error")); ``` -------------------------------- ### Result::unwrap Source: https://docs.rs/signifix/0.10.1/signifix/type.Result.html Returns the contained Ok value or panics. ```APIDOC ## unwrap(self) -> T ### Description Returns the contained `Ok` value, consuming the `self` value. Panics if the value is an `Err`. ``` -------------------------------- ### impl PartialEq for Result Source: https://docs.rs/signifix/0.10.1/signifix/type.Result.html Provides equality comparison for Result types if both T and E implement PartialEq. ```APIDOC ## fn eq(&self, other: &Result) -> bool ### Description Tests for `self` and `other` values to be equal, and is used by `==`. ### Method `eq` ### Endpoint N/A (Implementation detail) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```rust let res1: Result = Ok(10); let res2: Result = Ok(10); assert!(res1 == res2); let res3: Result = Err("error"); let res4: Result = Err("error"); assert!(res3 == res4); let res5: Result = Ok(10); let res6: Result = Ok(20); assert!(res5 != res6); let res7: Result = Ok(10); let res8: Result = Err("error"); assert!(res7 != res8); ``` ### Response #### Success Response (200) - **bool** (type) - `true` if the Results are equal, `false` otherwise. #### Response Example ```rust // true // false ``` ``` ```APIDOC ## fn ne(&self, other: &Rhs) -> bool ### Description Tests for `!=`. ### Method `ne` ### Endpoint N/A (Implementation detail) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```rust let res1: Result = Ok(10); let res2: Result = Ok(20); assert!(res1 != res2); let res3: Result = Err("error1"); let res4: Result = Err("error2"); assert!(res3 != res4); let res5: Result = Ok(10); let res6: Result = Ok(10); assert!(res5 == res6); // Demonstrating the opposite of ne ``` ### Response #### Success Response (200) - **bool** (type) - `true` if the Results are not equal, `false` otherwise. #### Response Example ```rust // true // false ``` ``` -------------------------------- ### TryFrom Numeric Conversions for Signifix Source: https://docs.rs/signifix/0.10.1/signifix/metric/struct.Signifix.html Endpoints representing the conversion of various numeric types into a Signifix instance. ```APIDOC ## TryFrom for Signifix ### Description Converts a numeric value into a Signifix instance. Returns a Result containing the Signifix instance or an Error if the conversion fails. ### Parameters #### Request Body - **number** (f64, i128, i16, i32, i64, i8, isize, u128, u16, u32, u64, u8, usize) - Required - The numeric value to convert. ### Response #### Success Response (200) - **Signifix** (Object) - The successfully converted Signifix instance. #### Error Response - **Error** (Type) - The error returned in the event of a conversion failure. ``` -------------------------------- ### Implement Custom Localizations Source: https://docs.rs/signifix/0.10.1/signifix/index.html Wraps Signifix in newtypes to implement locale-specific formatting by overriding the Display trait and using the fmt method. ```rust use std::convert::TryFrom; use signifix::binary::{Signifix, Result}; struct SignifixSi(Signifix); // English SI style (default) struct SignifixEn(Signifix); // English locale (whitespace -> comma) struct SignifixDe(Signifix); // German locale (comma <-> point) impl std::fmt::Display for SignifixSi { fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { std::fmt::Display::fmt(&self.0, f) } } impl std::fmt::Display for SignifixEn { fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { self.0.fmt(f, ".", ",") } } impl std::fmt::Display for SignifixDe { fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { self.0.fmt(f, ",", ".") } } let localizations = |number| -> Result<(String, String, String)> { Signifix::try_from(number).map(|number| ( format!("{}", SignifixSi(number)), format!("{}", SignifixEn(number)), format!("{}", SignifixDe(number)), )) }; assert_eq!(localizations(999.9f64 * 1_024f64), Ok(("999.9 Ki".into(), "999.9 Ki".into(), "999,9 Ki".into()))); assert_eq!(localizations(1_000f64 * 1_024f64), Ok(("1 000 Ki".into(), "1,000 Ki".into(), "1.000 Ki".into()))); ``` -------------------------------- ### Unwrap or Default Value Source: https://docs.rs/signifix/0.10.1/signifix/metric/type.Result.html Returns the Ok value or the default value of the type if the result is an Err. ```rust let good_year_from_input = "1909"; let bad_year_from_input = "190blarg"; let good_year = good_year_from_input.parse().unwrap_or_default(); let bad_year = bad_year_from_input.parse().unwrap_or_default(); assert_eq!(1909, good_year); assert_eq!(0, bad_year); ``` -------------------------------- ### Collect Result Iterators Source: https://docs.rs/signifix/0.10.1/signifix/type.Result.html Demonstrates how to collect an iterator of Results into a Result containing a collection, stopping at the first error. ```rust let v = vec![1, 2]; let res: Result, &'static str> = v.iter().map(|x: &u32| x.checked_add(1).ok_or("Overflow!") ).collect(); assert_eq!(res, Ok(vec![2, 3])); ``` ```rust let v = vec![1, 2, 0]; let res: Result, &'static str> = v.iter().map(|x: &u32| x.checked_sub(1).ok_or("Underflow!") ).collect(); assert_eq!(res, Err("Underflow!")); ``` ```rust let v = vec![3, 2, 1, 10]; let mut shared = 0; let res: Result, &'static str> = v.iter().map(|x: &u32| { shared += x; x.checked_sub(2).ok_or("Underflow!") }).collect(); assert_eq!(res, Err("Underflow!")); assert_eq!(shared, 6); ``` -------------------------------- ### Signifix Struct Methods Source: https://docs.rs/signifix/0.10.1/signifix/binary/struct.Signifix.html Methods available on the Signifix struct for accessing normalized numerical components and binary prefix information. ```APIDOC ## Signifix Methods ### Description Methods to retrieve normalized significand components, binary prefix factors, and symbols from a Signifix instance. ### Methods - **significand()** (f64) - Returns the signed significand normalized from ±1.000 to ±999.9. - **numerator()** (i32) - Returns the signed significand numerator from ±1 000 to ±9 999. - **denominator()** (i32) - Returns the significand denominator (1, 10, 100, or 1 000). - **exponent()** (usize) - Returns the exponent of the significand denominator (0 to 3). - **integer()** (i32) - Returns the signed integer part of the significand. - **fractional()** (i32) - Returns the fractional part of the significand. - **parts()** ((i32, i32)) - Returns the signed integer and fractional part as a tuple. - **prefix()** (usize) - Returns the binary prefix index (0 to 8). - **symbol()** (Option<&str>) - Returns the binary prefix symbol (e.g., "Ki"). - **factor()** (f64) - Returns the binary prefix factor (1 024 ^ 0 to 1 024 ^ 8). ``` -------------------------------- ### Trait Implementations Source: https://docs.rs/signifix/0.10.1/signifix/metric/type.Result.html Standard trait implementations for the Result type. ```APIDOC ## Trait Implementations ### Clone - `clone(&self) -> Result`: Returns a duplicate of the value. - `clone_from(&mut self, source: &Result)`: Performs copy-assignment from `source`. ### Debug - `fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>`: Formats the value using the given formatter. ### FromIterator - `FromIterator> for Result`: Allows collection of results. ``` -------------------------------- ### Constant FACTORS Source: https://docs.rs/signifix/0.10.1/signifix/metric/constant.FACTORS.html Documentation for the FACTORS constant used for metric prefix scaling. ```APIDOC ## Constant: FACTORS ### Description Metric prefix factors ranging from 1E-24 to 1E-03 (indices 0-7), 1E+00 (index 8), and 1E+03 to 1E+24 (indices 9-16). ### Definition `pub const FACTORS: [f64; 17];` ``` -------------------------------- ### Signifix Methods Source: https://docs.rs/signifix/0.10.1/signifix/metric/struct.Signifix.html Methods available on the Signifix struct to access its components. ```APIDOC ## impl Signifix ### `fn significand(&self) -> f64` Signed significand normalized from `±1.000` to `±999.9`. ### `fn numerator(&self) -> i32` Signed significand numerator from `±1 000` to `±9 999`. ### `fn denominator(&self) -> i32` Significand denominator of either `10`, `100`, or `1 000`. ### `fn exponent(&self) -> usize` Exponent of significand denominator of either `1`, `2`, or `3`. ### `fn integer(&self) -> i32` Signed integer part of significand from `±1` to `±999`. ### `fn fractional(&self) -> i32` Fractional part of significand from `0` to `999`. ### `fn parts(&self) -> (i32, i32)` Signed integer and fractional part at once, in given order. ### `fn prefix(&self) -> usize` Metric prefix as `NAMES`, `SYMBOLS`, and `FACTORS` array index from `0` to `16`. ### `fn symbol(&self) -> Option<&str>` Symbol of metric prefix from `Some("y")` to `Some("Y")`, or `None`. ### `fn factor(&self) -> f64` Factor of metric prefix from `1E-24` to `1E+24`, or `1E+00`. ### `fn fmt(&self, f: &mut Formatter<'_>, decimal_mark: &str) -> Result` Format trait implementation allowing explicit localization. Until there is a recommended and possibly implicit localization system for Rust, explicit localization can be achieved by wrapping the `Signifix` type into a locale-sensitive newtype which implements the `Display` trait via this method. Used by this type’s `Display` trait implementation with a decimal point as `decimal_mark`. The `decimal_mark` must be of a single character. ``` -------------------------------- ### Product Operation on Iterators Source: https://docs.rs/signifix/0.10.1/signifix/type.Result.html Demonstrates the `product` method for iterators yielding `Result` types. It computes the product of elements, short-circuiting on the first `Err`. ```APIDOC ## fn product(iter: I) -> Result ### Description Takes each element in the `Iterator`: if it is an `Err`, no further elements are taken, and the `Err` is returned. Should no `Err` occur, the product of all elements is returned. ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example None ### Response #### Success Response (200) - **product** (Result) - The product of all elements in the iterator, or the first Err encountered. #### Response Example ```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()); ``` ``` -------------------------------- ### impl Product> for Result Source: https://docs.rs/signifix/0.10.1/signifix/binary/type.Result.html Implementation of the Product trait for Result, allowing the product of an iterator of Results to be computed. If any element is an Err, that Err is returned. ```APIDOC ## Product Implementation for Result ### Description This implementation allows computing the product of an iterator of `Result` values, where the accumulator `T` also implements `Product`. If any element in the iterator is an `Err`, that `Err` is returned immediately, short-circuiting the computation. If all elements are `Ok`, the product of the contained values is returned within an `Ok`. ### Method `product` (from the `Product` trait) ### Endpoint N/A (This is a trait implementation, not an HTTP endpoint) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```rust // Example requires an iterator of Results and a type T that implements Product // For instance, if T is Result and U is i32: let values = vec![Ok(2), Ok(3), Ok(4)]; let product_result: Result = values.into_iter().product(); assert_eq!(product_result, Ok(24)); let values_with_err = vec![Ok(2), Err("multiplication error"), Ok(4)]; let product_result_err: Result = values_with_err.into_iter().product(); assert_eq!(product_result_err, Err("multiplication error")); ``` ### Response #### Success Response (200) - **Result** (type) - The product of the `Ok` values, or the first `Err` encountered. #### Response Example ```rust // See request example for detailed response values. ``` ``` -------------------------------- ### impl FromResidual> for Result Source: https://docs.rs/signifix/0.10.1/signifix/type.Result.html Nightly-only experimental API for constructing a Result from a Yeet residual type. ```APIDOC ## fn from_residual(_: Yeet) -> Result ### Description Nightly-only experimental API (`try_trait_v2`). Constructs the type from a compatible `Residual` type. ### Method `from_residual` ### Endpoint N/A (Implementation detail) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```rust // Example usage would depend on the context of try_trait_v2 ``` ### Response #### Success Response (200) - **Result** (type) - The constructed Result. #### Response Example ```rust // Example response would depend on the context of try_trait_v2 ``` ``` -------------------------------- ### Constant ALT_MAX_LEN Source: https://docs.rs/signifix/0.10.1/signifix/metric/constant.ALT_MAX_LEN.html Documentation for the ALT_MAX_LEN constant used in signifix::metric. ```APIDOC ## CONSTANT ALT_MAX_LEN ### Description Defines the number of characters in alternate notation when a sign is prefixed. ### Value 6 (usize) ```