### Chain fallible operations with and_then Source: https://docs.rs/falcompress/0.3.0/falcompress/type.Result.html Use and_then to chain operations that return a Result. The provided examples demonstrate handling successful values, overflow errors, and existing error states. ```rust assert_eq!(Ok(2).and_then(sq_then_to_string), Ok(4.to_string())); assert_eq!(Ok(1_000_000).and_then(sq_then_to_string), Err("overflowed")); assert_eq!(Err("not a number").and_then(sq_then_to_string), Err("not a number")); ``` ```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); ``` -------------------------------- ### pub fn inspect(data: &[u8]) -> Option<(usize, Option)> Source: https://docs.rs/falcompress/0.3.0/falcompress/ed6/fn.inspect.html Analyzes the provided byte slice to determine the size and compression mode of the data. ```APIDOC ## inspect ### Description Analyzes the provided byte slice to determine the size and compression mode of the data. ### Signature `pub fn inspect(data: &[u8]) -> Option<(usize, Option)>` ### Parameters - **data** (&[u8]) - The input byte slice to inspect. ### Returns - **Option<(usize, Option)>** - Returns an Option containing a tuple with the size (usize) and an optional CompressMode, or None if inspection fails. ``` -------------------------------- ### pub fn compress(data: &[u8], mode: CompressMode) -> Vec Source: https://docs.rs/falcompress/0.3.0/falcompress/ed7/fn.compress.html Compresses the provided input data using the specified compression mode and returns the compressed data as a vector of bytes. ```APIDOC ## compress ### Description Compresses a slice of bytes into a new vector of bytes using the specified `CompressMode`. ### Signature `pub fn compress(data: &[u8], mode: CompressMode) -> Vec` ### Parameters - **data** (&[u8]) - The input byte slice to be compressed. - **mode** (CompressMode) - The compression mode to apply during the operation. ``` -------------------------------- ### pub fn compress(input: &[u8], out: &mut Vec, mode: CompressMode) Source: https://docs.rs/falcompress/0.3.0/falcompress/bzip/fn.compress.html Compresses a single chunk of data. Mode 2 is limited to chunks up to 0xFFFF bytes, while mode 1 has no such restriction. ```APIDOC ## Function: compress ### Description Compresses a single chunk of compressed data in the specified mode. Note that mode 2 is limited to chunks no larger than 0xFFFF bytes, while mode 1 has no such restriction. ### Signature `pub fn compress(input: &[u8], out: &mut Vec, mode: CompressMode)` ### Parameters - **input** (&[u8]) - The input data slice to be compressed. - **out** (&mut Vec) - A mutable reference to a vector where the compressed output will be stored. - **mode** (CompressMode) - The compression mode to use for the operation. ``` -------------------------------- ### compress Source: https://docs.rs/falcompress/0.3.0/falcompress/ed7/index.html Compresses data using the ed7 algorithm. ```APIDOC ## compress ### Description Compresses the provided input data using the ed7 compression algorithm. ``` -------------------------------- ### compress Source: https://docs.rs/falcompress/0.3.0/falcompress/ed6/index.html Compresses data using the ed6 algorithm. ```APIDOC ## compress ### Description Compresses the provided input data. ### Signature `pub fn compress(data: &[u8]) -> Vec` ``` -------------------------------- ### Unwrap Result or Default Source: https://docs.rs/falcompress/0.3.0/falcompress/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); ``` -------------------------------- ### pub fn freadp(data: &[u8], out: &mut Vec) -> Result Source: https://docs.rs/falcompress/0.3.0/falcompress/ed7/fn.freadp.html Decompresses the provided data into the output vector. ```APIDOC ## freadp ### Description Decompresses the provided byte slice into the specified output vector. ### Signature `pub fn freadp(data: &[u8], out: &mut Vec) -> Result` ### Parameters - **data** (&[u8]) - The input byte slice containing the compressed data. - **out** (&mut Vec) - A mutable reference to a vector where the decompressed data will be stored. ### Returns - **Result** - Returns the number of bytes written to the output vector, or an error if decompression fails. ``` -------------------------------- ### Provide default value with unwrap_or Source: https://docs.rs/falcompress/0.3.0/falcompress/type.Result.html Returns the contained Ok value or a provided default value if the Result is Err. ```rust let default = 2; let x: Result = Ok(9); assert_eq!(x.unwrap_or(default), 9); let x: Result = Err("error"); assert_eq!(x.unwrap_or(default), default); ``` -------------------------------- ### inspect function signature Source: https://docs.rs/falcompress/0.3.0/falcompress/ed6/fn.inspect.html The function signature for inspecting compressed data. ```rust pub fn inspect(data: &[u8]) -> Option<(usize, Option)> ``` -------------------------------- ### Chain Result with And Source: https://docs.rs/falcompress/0.3.0/falcompress/type.Result.html Returns the provided result if the current result is Ok, otherwise returns the Err value. ```rust let x: Result = Ok(2); let y: Result<&str, &str> = Err("late error"); assert_eq!(x.and(y), Err("late error")); let x: Result = Err("early error"); let y: Result<&str, &str> = Ok("foo"); assert_eq!(x.and(y), Err("early error")); let x: Result = Err("not a 2"); let y: Result<&str, &str> = Err("late error"); assert_eq!(x.and(y), Err("not a 2")); let x: Result = Ok(2); let y: Result<&str, &str> = Ok("different result type"); assert_eq!(x.and(y), Ok("different result type")); ``` -------------------------------- ### pub fn decompress(data: &[u8], out: &mut Vec, mode: u32) -> Result Source: https://docs.rs/falcompress/0.3.0/falcompress/c77/fn.decompress.html Decompresses the provided input data into the specified output vector using the given mode. ```APIDOC ## decompress ### Signature `pub fn decompress(data: &[u8], out: &mut Vec, mode: u32) -> Result` ### Description Decompresses the input byte slice `data` and appends the result to the `out` vector. The `mode` parameter specifies the decompression mode to be used. ### Parameters - **data** (&[u8]) - The compressed input data. - **out** (&mut Vec) - The mutable buffer where decompressed data will be stored. - **mode** (u32) - The decompression mode configuration. ### Returns - **Result** - Returns the number of bytes written to the output buffer on success, or an error if decompression fails. ``` -------------------------------- ### Fallback to alternative Result with or Source: https://docs.rs/falcompress/0.3.0/falcompress/type.Result.html Returns the current Result if it is Ok, otherwise returns the provided alternative Result. Note that arguments are evaluated eagerly. ```rust let x: Result = Ok(2); let y: Result = Err("late error"); assert_eq!(x.or(y), Ok(2)); let x: Result = Err("early error"); let y: Result = Ok(2); assert_eq!(x.or(y), Ok(2)); let x: Result = Err("not a 2"); let y: Result = Err("late error"); assert_eq!(x.or(y), Err("late error")); let x: Result = Ok(2); let y: Result = Ok(100); assert_eq!(x.or(y), Ok(2)); ``` -------------------------------- ### Copying Result Contents Source: https://docs.rs/falcompress/0.3.0/falcompress/type.Result.html Methods to copy or clone the contents of an Ok variant in a Result containing a reference. ```rust let val = 12; let x: Result<&i32, i32> = Ok(&val); assert_eq!(x, Ok(&12)); let copied = x.copied(); assert_eq!(copied, Ok(12)); ``` ```rust let val = 12; let x: Result<&i32, i32> = Ok(&val); assert_eq!(x, Ok(&12)); let cloned = x.cloned(); assert_eq!(cloned, Ok(12)); ``` ```rust let mut val = 12; let x: Result<&mut i32, i32> = Ok(&mut val); assert_eq!(x, Ok(&mut 12)); let copied = x.copied(); assert_eq!(copied, Ok(12)); ``` ```rust let mut val = 12; let x: Result<&mut i32, i32> = Ok(&mut val); assert_eq!(x, Ok(&mut 12)); let cloned = x.cloned(); assert_eq!(cloned, Ok(12)); ``` -------------------------------- ### pub fn decompress(data: &[u8], out: &mut Vec) -> Result Source: https://docs.rs/falcompress/0.3.0/falcompress/ed6/fn.decompress.html Decompresses the provided input data into the specified output vector. ```APIDOC ## decompress ### Signature `pub fn decompress(data: &[u8], out: &mut Vec) -> Result` ### Description Decompresses the input byte slice `data` and appends the result to the mutable vector `out`. ### Parameters - **data** (&[u8]) - The compressed input data. - **out** (&mut Vec) - The destination buffer for the decompressed data. ### Returns - **Result** - Returns the number of bytes decompressed on success, or an error if decompression fails. ``` -------------------------------- ### pub fn compress_inner(input: &[u8], out: &mut Vec) Source: https://docs.rs/falcompress/0.3.0/falcompress/c77/fn.compress_inner.html Compresses the provided input byte slice and appends the result to the provided output vector. ```APIDOC ## Function: compress_inner ### Description Compresses a byte slice and appends the compressed data to a mutable vector. ### Signature `pub fn compress_inner(input: &[u8], out: &mut Vec)` ### Parameters - **input** (&[u8]) - The source data to be compressed. - **out** (&mut Vec) - The destination vector where compressed data will be appended. ``` -------------------------------- ### Expect Value Source: https://docs.rs/falcompress/0.3.0/falcompress/type.Result.html Returns the contained Ok value or panics with the provided message if the result is Err. ```rust let x: Result = Err("emergency failure"); x.expect("Testing expect"); // panics with `Testing expect: emergency failure` ``` ```rust let path = std::env::var("IMPORTANT_PATH") .expect("env variable `IMPORTANT_PATH` should be set by `wrapper_script.sh`"); ``` -------------------------------- ### Reference Result with as_ref and as_mut Source: https://docs.rs/falcompress/0.3.0/falcompress/type.Result.html Converts a Result to a 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")); ``` ```rust fn mutate(r: &mut Result) { match r.as_mut() { Ok(v) => *v = 42, Err(e) => *e = 0, } } let mut x: Result = Ok(2); mutate(&mut x); assert_eq!(x.unwrap(), 42); let mut x: Result = Err(13); mutate(&mut x); assert_eq!(x.unwrap_err(), 0); ``` -------------------------------- ### freadp Source: https://docs.rs/falcompress/0.3.0/falcompress/ed7/index.html Reads data from a file pointer or stream. ```APIDOC ## freadp ### Description Reads data from a file pointer or stream for processing within the ed7 module. ``` -------------------------------- ### compress Source: https://docs.rs/falcompress/0.3.0/falcompress/bzip/index.html Compresses a single chunk of data using the specified mode. Mode 2 is limited to chunks of 0xFFFF bytes or less, while mode 1 has no such restriction. ```APIDOC ## compress ### Description Compresses a single chunk of compressed data, in the specified mode. ### Parameters - **mode** (CompressMode) - Required - The compression mode to use. - **data** (slice) - Required - The input data to compress. ``` -------------------------------- ### Map Result to default or function Source: https://docs.rs/falcompress/0.3.0/falcompress/type.Result.html Maps a Result to a value by applying a function or returning a default. ```rust let x: Result<_, &str> = Ok("foo"); assert_eq!(x.map_or(42, |v| v.len()), 3); let x: Result<&str, _> = Err("bar"); assert_eq!(x.map_or(42, |v| v.len()), 42); ``` ```rust let k = 21; let x : Result<_, &str> = Ok("foo"); assert_eq!(x.map_or_else(|e| k * 2, |v| v.len()), 3); let x : Result<&str, _> = Err("bar"); assert_eq!(x.map_or_else(|e| k * 2, |v| v.len()), 42); ``` ```rust #![feature(result_option_map_or_default)] let x: Result<_, &str> = Ok("foo"); let y: Result<&str, _> = Err("bar"); assert_eq!(x.map_or_default(|x| x.len()), 3); assert_eq!(y.map_or_default(|y| y.len()), 0); ``` -------------------------------- ### inspect Source: https://docs.rs/falcompress/0.3.0/falcompress/ed6/index.html Inspects compressed data to retrieve metadata or information. ```APIDOC ## inspect ### Description Inspects the provided compressed data. ### Signature `pub fn inspect(data: &[u8])` ``` -------------------------------- ### Compute default value with unwrap_or_else Source: https://docs.rs/falcompress/0.3.0/falcompress/type.Result.html Returns the contained Ok value or computes a default value using a closure. ```rust fn count(x: &str) -> usize { x.len() } ``` -------------------------------- ### Collect Result from Iterator Source: https://docs.rs/falcompress/0.3.0/falcompress/type.Result.html Demonstrates how FromIterator short-circuits on the first Err encountered during collection. ```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); ``` -------------------------------- ### compress_inner Source: https://docs.rs/falcompress/0.3.0/falcompress/c77/index.html Compresses data using the internal compression logic. ```APIDOC ## compress_inner ### Description Compresses the provided data using the internal compression algorithm. ### Signature `pub fn compress_inner(data: &[u8]) -> Vec` ``` -------------------------------- ### Check Result with is_err_and Source: https://docs.rs/falcompress/0.3.0/falcompress/type.Result.html Checks if a Result is an Err and matches a specific predicate. ```rust use std::io::{Error, ErrorKind}; let x: Result = Err(Error::new(ErrorKind::NotFound, "!")); assert_eq!(x.is_err_and(|x| x.kind() == ErrorKind::NotFound), true); let x: Result = Err(Error::new(ErrorKind::PermissionDenied, "!")); assert_eq!(x.is_err_and(|x| x.kind() == ErrorKind::NotFound), false); let x: Result = Ok(123); assert_eq!(x.is_err_and(|x| x.kind() == ErrorKind::NotFound), false); let x: Result = Err("ownership".to_string()); assert_eq!(x.as_ref().is_err_and(|x| x.len() > 1), true); println!("still alive {:?}", x); ``` -------------------------------- ### Compress function signature Source: https://docs.rs/falcompress/0.3.0/falcompress/ed7/fn.compress.html The function signature for compressing data into a vector of bytes. ```rust pub fn compress(data: &[u8], mode: CompressMode) -> Vec ⓘ ``` -------------------------------- ### Chain Result with And Then Source: https://docs.rs/falcompress/0.3.0/falcompress/type.Result.html Calls a function if the result is Ok, allowing for lazy evaluation and control flow. ```rust fn sq_then_to_string(x: u32) -> Result { x.checked_mul(x).map(|sq| sq.to_string()).ok_or("overflowed") } ``` -------------------------------- ### freadp function signature Source: https://docs.rs/falcompress/0.3.0/falcompress/ed7/fn.freadp.html The function signature for decompressing data into a provided buffer. ```rust pub fn freadp(data: &[u8], out: &mut Vec) -> Result ``` -------------------------------- ### Convert Result to Option Source: https://docs.rs/falcompress/0.3.0/falcompress/type.Result.html Converts Result to Option, discarding the error or success value respectively. ```rust let x: Result = Ok(2); assert_eq!(x.ok(), Some(2)); let x: Result = Err("Nothing here"); assert_eq!(x.ok(), None); ``` ```rust let x: Result = Ok(2); assert_eq!(x.err(), None); let x: Result = Err("Nothing here"); assert_eq!(x.err(), Some("Nothing here")); ``` -------------------------------- ### Expect Error from Result Source: https://docs.rs/falcompress/0.3.0/falcompress/type.Result.html Returns the Err value or panics if the result is an Ok. ```rust let x: Result = Ok(10); x.expect_err("Testing expect_err"); // panics with `Testing expect_err: 10` ``` -------------------------------- ### Inspect Result Source: https://docs.rs/falcompress/0.3.0/falcompress/type.Result.html Executes a closure with a reference to the contained value if the result is Ok, returning the original result. ```rust let x: u8 = "4" .parse::() .inspect(|x| println!("original: {x}")) .map(|x| x.pow(3)) .expect("failed to parse number"); ``` -------------------------------- ### Unwrap Error from Result Source: https://docs.rs/falcompress/0.3.0/falcompress/type.Result.html Returns the Err value or panics if the result is an Ok. ```rust let x: Result = Ok(2); x.unwrap_err(); // panics with `2` ``` ```rust let x: Result = Err("emergency failure"); assert_eq!(x.unwrap_err(), "emergency failure"); ``` -------------------------------- ### Unwrap Result Value Source: https://docs.rs/falcompress/0.3.0/falcompress/type.Result.html Extracts the Ok value or panics if the result is an Err. Use with caution as it may abort the program. ```rust let x: Result = Ok(2); assert_eq!(x.unwrap(), 2); ``` ```rust let x: Result = Err("emergency failure"); x.unwrap(); // panics with `emergency failure` ``` -------------------------------- ### Map Result values Source: https://docs.rs/falcompress/0.3.0/falcompress/type.Result.html Applies a function to the contained Ok value while leaving Err untouched. ```rust let line = "1\n2\n3\n4\n"; for num in line.lines() { match num.parse::().map(|i| i * 2) { Ok(n) => println!("{n}"), Err(..) => {} } } ``` -------------------------------- ### CompressMode Source: https://docs.rs/falcompress/0.3.0/falcompress/bzip/enum.CompressMode.html The CompressMode enum provides different modes for compression operations. ```APIDOC ## Enum: CompressMode ### Description An enumeration representing the available compression modes used by the library. ### Variants - **Mode1** - **Mode2** ``` -------------------------------- ### decompress Source: https://docs.rs/falcompress/0.3.0/falcompress/ed6/index.html Decompresses data that was compressed with the ed6 algorithm. ```APIDOC ## decompress ### Description Decompresses the provided compressed data. ### Signature `pub fn decompress(data: &[u8]) -> Vec` ``` -------------------------------- ### Infallible Ok Conversion Source: https://docs.rs/falcompress/0.3.0/falcompress/type.Result.html Extracts the Ok value from a Result that is guaranteed not to contain an error. ```rust fn only_good_news() -> Result { Ok("this is fine".into()) } let s: String = only_good_news().into_ok(); println!("{s}"); ``` -------------------------------- ### Transposing Result and Option Source: https://docs.rs/falcompress/0.3.0/falcompress/type.Result.html Transposes a Result of an Option into an Option of a Result. ```rust #[derive(Debug, Eq, PartialEq)] struct SomeErr; let x: Result, SomeErr> = Ok(Some(5)); let y: Option> = Some(Ok(5)); assert_eq!(x.transpose(), y); ``` -------------------------------- ### decompress Source: https://docs.rs/falcompress/0.3.0/falcompress/ed7/index.html Decompresses data that was compressed with the ed7 algorithm. ```APIDOC ## decompress ### Description Decompresses the provided input data using the ed7 decompression algorithm. ``` -------------------------------- ### Inspect Error Source: https://docs.rs/falcompress/0.3.0/falcompress/type.Result.html Executes a closure with a reference to the contained error if the result is Err, returning the original result. ```rust use std::{fs, io}; fn read() -> io::Result { fs::read_to_string("address.txt") .inspect_err(|e| eprintln!("failed to read file: {e}")) } ``` -------------------------------- ### Checking Result Status Source: https://docs.rs/falcompress/0.3.0/falcompress/type.Result.html Methods to check if a Result is Ok or Err, including predicate-based checks. ```rust let x: Result = Ok(-3); assert_eq!(x.is_ok(), true); let x: Result = Err("Some error message"); assert_eq!(x.is_ok(), false); ``` ```rust let x: Result = Ok(2); assert_eq!(x.is_ok_and(|x| x > 1), true); let x: Result = Ok(0); assert_eq!(x.is_ok_and(|x| x > 1), false); let x: Result = Err("hey"); assert_eq!(x.is_ok_and(|x| x > 1), false); let x: Result = Ok("ownership".to_string()); assert_eq!(x.as_ref().is_ok_and(|x| x.len() > 1), true); println!("still alive {:?}", x); ``` ```rust let x: Result = Ok(-3); assert_eq!(x.is_err(), false); let x: Result = Err("Some error message"); assert_eq!(x.is_err(), true); ``` -------------------------------- ### Iterate Result Source: https://docs.rs/falcompress/0.3.0/falcompress/type.Result.html Creates an iterator that yields the contained value if the result is Ok, or nothing if it is Err. ```rust let x: Result = Ok(7); assert_eq!(x.iter().next(), Some(&7)); let x: Result = Err("nothing!"); assert_eq!(x.iter().next(), None); ``` -------------------------------- ### compress_inner function signature Source: https://docs.rs/falcompress/0.3.0/falcompress/c77/fn.compress_inner.html The function signature for compressing input data into a provided output vector. ```rust pub fn compress_inner(input: &[u8], out: &mut Vec) ``` -------------------------------- ### decompress Source: https://docs.rs/falcompress/0.3.0/falcompress/bzip/index.html Decompresses a single chunk of compressed data. Supports both mode 1 and mode 2 with no notable limitations on input or output size. ```APIDOC ## decompress ### Description Decompresses a single chunk of compressed data. ### Parameters - **data** (slice) - Required - The compressed data chunk to decompress. ``` -------------------------------- ### pub unsafe fn unwrap_unchecked(self) -> T Source: https://docs.rs/falcompress/0.3.0/falcompress/type.Result.html Returns the contained Ok value, consuming the self value, without checking that the value is not an Err. Calling this method on an Err is undefined behavior. ```APIDOC ## pub unsafe fn unwrap_unchecked(self) -> T ### Description Returns the contained `Ok` value, consuming the `self` value, without checking that the value is not an `Err`. ### Safety Calling this method on an `Err` is _undefined behavior_. ``` -------------------------------- ### decompress Source: https://docs.rs/falcompress/0.3.0/falcompress/c77/index.html Decompresses data that was previously compressed by the library. ```APIDOC ## decompress ### Description Decompresses the provided byte slice back into its original form. ### Signature `pub fn decompress(data: &[u8]) -> Result, Error>` ``` -------------------------------- ### As Deref Source: https://docs.rs/falcompress/0.3.0/falcompress/type.Result.html Converts a Result containing a dereferenceable type into a Result containing a reference to the target type. ```rust let x: Result = Ok("hello".to_string()); let y: Result<&str, &u32> = Ok("hello"); assert_eq!(x.as_deref(), y); let x: Result = Err(42); let y: Result<&str, &u32> = Err(&42); assert_eq!(x.as_deref(), y); ``` -------------------------------- ### decompress function signature Source: https://docs.rs/falcompress/0.3.0/falcompress/c77/fn.decompress.html The function signature for decompressing data into a mutable vector. ```rust pub fn decompress(data: &[u8], out: &mut Vec, mode: u32) -> Result ``` -------------------------------- ### pub unsafe fn unwrap_err_unchecked(self) -> E Source: https://docs.rs/falcompress/0.3.0/falcompress/type.Result.html Returns the contained Err value, consuming the self value, without checking that the value is not an Ok. Calling this method on an Ok is undefined behavior. ```APIDOC ## pub unsafe fn unwrap_err_unchecked(self) -> E ### Description Returns the contained `Err` value, consuming the `self` value, without checking that the value is not an `Ok`. ### Safety Calling this method on an `Ok` is _undefined behavior_. ``` -------------------------------- ### Calculate Product of Result Iterator Source: https://docs.rs/falcompress/0.3.0/falcompress/type.Result.html Multiplies elements in an iterator of Results, returning the first Err encountered or the product of all Ok values. ```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()); ``` -------------------------------- ### IntoIterator for Result Source: https://docs.rs/falcompress/0.3.0/falcompress/type.Result.html Consuming iterator that yields the contained value if Ok, or nothing if Err. ```rust let x: Result = Ok(5); let v: Vec = x.into_iter().collect(); assert_eq!(v, [5]); let x: Result = Err("nothing!"); let v: Vec = x.into_iter().collect(); assert_eq!(v, []); ``` -------------------------------- ### Calculate Sum of Result Iterator Source: https://docs.rs/falcompress/0.3.0/falcompress/type.Result.html Sums elements in an iterator of Results, returning the first Err encountered or the sum of all Ok values. ```rust let f = |&x: &i32| if x < 0 { Err("Negative element found") } else { Ok(x) }; let v = vec![1, 2]; let res: Result = v.iter().map(f).sum(); assert_eq!(res, Ok(3)); let v = vec![1, -2]; let res: Result = v.iter().map(f).sum(); assert_eq!(res, Err("Negative element found")); ``` -------------------------------- ### CompressMode Enum Definition Source: https://docs.rs/falcompress/0.3.0/falcompress/bzip/enum.CompressMode.html The definition of the CompressMode enum showing its available variants. ```rust pub enum CompressMode { Mode1, Mode2, } ``` -------------------------------- ### Result Type Definition Source: https://docs.rs/falcompress/0.3.0/falcompress/type.Result.html The definition of the Result type alias and the underlying enum structure. ```rust pub type Result = Result; ``` ```rust pub enum Result { Ok(A), Err(E), } ``` -------------------------------- ### Unwrap Result Unchecked Source: https://docs.rs/falcompress/0.3.0/falcompress/type.Result.html Unsafe methods to extract values from Result without runtime checks. Calling these on the wrong variant results in undefined behavior. ```rust let x: Result = Ok(2); assert_eq!(unsafe { x.unwrap_unchecked() }, 2); ``` ```rust let x: Result = Err("emergency failure"); unsafe { x.unwrap_unchecked() }; // Undefined behavior! ``` ```rust let x: Result = Ok(2); unsafe { x.unwrap_err_unchecked() }; // Undefined behavior! ``` ```rust let x: Result = Err("emergency failure"); assert_eq!(unsafe { x.unwrap_err_unchecked() }, "emergency failure"); ``` -------------------------------- ### Fallback to closure result with or_else Source: https://docs.rs/falcompress/0.3.0/falcompress/type.Result.html Calls a closure if the Result is Err, allowing for lazy evaluation of fallback logic. ```rust fn sq(x: u32) -> Result { Ok(x * x) } fn err(x: u32) -> Result { Err(x) } assert_eq!(Ok(2).or_else(sq).or_else(sq), Ok(2)); assert_eq!(Ok(2).or_else(err).or_else(sq), Ok(2)); assert_eq!(Err(3).or_else(sq).or_else(err), Ok(9)); assert_eq!(Err(3).or_else(err).or_else(err), Err(3)); ``` -------------------------------- ### Flattening Nested Results Source: https://docs.rs/falcompress/0.3.0/falcompress/type.Result.html Converts a nested Result into a single-level Result. ```rust let x: Result, u32> = Ok(Ok("hello")); assert_eq!(Ok("hello"), x.flatten()); let x: Result, u32> = Ok(Err(6)); assert_eq!(Err(6), x.flatten()); let x: Result, u32> = Err(6); assert_eq!(Err(6), x.flatten()); ``` ```rust let x: Result, u32>, u32> = Ok(Ok(Ok("hello"))); assert_eq!(Ok(Ok("hello")), x.flatten()); assert_eq!(Ok("hello"), x.flatten().flatten()); ``` -------------------------------- ### Iterate Mutably Source: https://docs.rs/falcompress/0.3.0/falcompress/type.Result.html Creates a mutable iterator that yields a mutable reference to the contained value if the result is Ok. ```rust let mut x: Result = Ok(7); match x.iter_mut().next() { Some(v) => *v = 40, None => {}, } assert_eq!(x, Ok(40)); let mut x: Result = Err("nothing!"); assert_eq!(x.iter_mut().next(), None); ``` -------------------------------- ### As Deref Mut Source: https://docs.rs/falcompress/0.3.0/falcompress/type.Result.html Converts a Result containing a mutable dereferenceable type into a Result containing a mutable reference to the target type. ```rust let mut s = "HELLO".to_string(); let mut x: Result = Ok("hello".to_string()); let y: Result<&mut str, &mut u32> = Ok(&mut s); assert_eq!(x.as_deref_mut().map(|x| { x.make_ascii_uppercase(); x }), y); let mut i = 42; let mut x: Result = Err(42); let y: Result<&mut str, &mut u32> = Err(&mut i); assert_eq!(x.as_deref_mut().map(|x| { x.make_ascii_uppercase(); x }), y); ``` -------------------------------- ### Infallible Error Conversion Source: https://docs.rs/falcompress/0.3.0/falcompress/type.Result.html Extracts the Err value from a Result that is guaranteed not to contain an Ok value. ```rust fn only_bad_news() -> Result { Err("Oops, it failed".into()) } let error: String = only_bad_news().into_err(); println!("{error}"); ``` -------------------------------- ### Define Error Enum Source: https://docs.rs/falcompress/0.3.0/falcompress/enum.Error.html The Error enum structure used for handling library-specific errors. ```rust pub enum Error { Read { pos: usize, }, BadRepeat { count: usize, offset: usize, len: usize, }, BadSize { what: &'static str, expected: usize, actual: usize, }, Custom { message: String, }, } ``` -------------------------------- ### Map Error Source: https://docs.rs/falcompress/0.3.0/falcompress/type.Result.html Transforms the error variant of a Result using a provided function while leaving the Ok variant unchanged. ```rust fn stringify(x: u32) -> String { format!("error code: {x}") } let x: Result = Ok(2); assert_eq!(x.map_err(stringify), Ok(2)); let x: Result = Err(13); assert_eq!(x.map_err(stringify), Err("error code: 13".to_string())); ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.