### Find Encapsulated Section Start Source: https://docs.rs/icaparse/0.2.0/src/icaparse/lib.rs.html Locates the starting index of a specific section within an encapsulated header string. ```rust fn find_section_start(encapsulated: &str, section: &str) -> Option { if let Some(x) = encapsulated.find(section) { let start = x + section.len(); let end = match encapsulated[start..encapsulated.len()].find(",") { Some(i) => start + i, None => encapsulated.len() }; encapsulated[start..end].parse::().ok() } else { None } } ``` -------------------------------- ### Implement Any for T Source: https://docs.rs/icaparse/0.2.0/icaparse/enum.SectionType.html Provides runtime type information for any type T. Use this to get the TypeId of a value. ```rust fn type_id(&self) -> TypeId ``` -------------------------------- ### Collect Iterator of Results with Underflow Check Source: https://docs.rs/icaparse/0.2.0/icaparse/type.Result.html Collects an iterator of Results into a single Result, returning the first Err encountered. This example checks for underflow during subtraction. ```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!")); ``` -------------------------------- ### Implement CloneToUninit for T Source: https://docs.rs/icaparse/0.2.0/icaparse/enum.SectionType.html Nightly-only experimental API for copying data to uninitialized memory. Use with caution. ```rust unsafe fn clone_to_uninit(&self, dest: *mut u8) ``` -------------------------------- ### Initialize and parse Response Source: https://docs.rs/icaparse/0.2.0/icaparse/struct.Response.html Methods for creating a new Response instance and parsing byte buffers into it. ```rust pub fn new(headers: &'h mut [Header<'b>]) -> Response<'h, 'b> ``` ```rust pub fn parse(&mut self, buf: &'b [u8]) -> Result ``` -------------------------------- ### Define EncapsulationSection Source: https://docs.rs/icaparse/0.2.0/src/icaparse/lib.rs.html Structure representing a section of encapsulated data with its type and start position. ```rust #[derive(Debug, Hash, PartialEq, Eq)] pub struct EncapsulationSection { /// The type of data in the section name: SectionType, /// The start of the section start: usize } impl EncapsulationSection { /// provides a constructor for method for the type pub fn new(name: SectionType, start: usize) -> EncapsulationSection { EncapsulationSection { name: name, start: start } } } ``` -------------------------------- ### Response Struct Initialization Source: https://docs.rs/icaparse/0.2.0/icaparse/struct.Response.html Creates a new instance of the Response struct using a pre-allocated slice of headers. ```APIDOC ## pub fn new(headers: &'h mut [Header<'b>]) -> Response<'h, 'b> ### Description Creates a new `Response` using a slice of `Header`s you have allocated. ### Parameters - **headers** (&'h mut [Header<'b>]) - Required - A mutable slice of Header objects to store parsed headers. ``` -------------------------------- ### into_ok Source: https://docs.rs/icaparse/0.2.0/icaparse/type.Result.html Returns the contained `Ok` value, but never panics. This is an experimental API. ```APIDOC ## into_ok ### Description Returns the contained `Ok` value, but never panics. This is a nightly-only experimental API. ### Method `into_ok` ### Request Example ```rust fn only_good_news() -> Result { Ok("this is fine".into()) } let s: String = only_good_news().into_ok(); println!("{s}"); ``` ``` -------------------------------- ### Unwrap Err Value Unchecked Source: https://docs.rs/icaparse/0.2.0/icaparse/type.Result.html Use this method to get the contained Err value without checking if it's an Ok. Calling on an Ok is 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"); ``` -------------------------------- ### Unwrap Result Value Unchecked Source: https://docs.rs/icaparse/0.2.0/icaparse/type.Result.html Use this method to get the contained Ok value without checking if it's an Err. Calling on an Err is 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! ``` -------------------------------- ### icaparse Crate Overview Source: https://docs.rs/icaparse/0.2.0/icaparse/index.html Provides an overview of the icaparse crate, its purpose, and its core components. ```APIDOC ## Crate icaparse A push library for parsing ICAP/1.0 requests and responses. ### Summary The focus is on speed and safety. Unsafe code is used to keep parsing fast, but unsafety is contained in a submodule, with invariants enforced. The parsing internals use an `Iterator` instead of direct indexing, while skipping bounds checks. This parser is based heavily on the httparse HTTP parsing library. ### Structs * **EncapsulationSection**: Describes a section of the encapsulated data as listed in the Encapsulated header. * **Header**: Represents a parsed header. * **InvalidChunkSize**: An error in parsing a chunk size. * **Request**: A parsed Request. * **Response**: A parsed Response. ### Enums * **Error**: An error in parsing. * **SectionType**: Possible sections of the encapsulated ICAP data. * **Status**: The result of a successful parse pass. ### Constants * **EMPTY_HEADER**: An empty header, useful for constructing a `Header` array to pass in for parsing. ### Functions * **parse_chunk_size**: Parse a buffer of bytes as a chunk size. * **parse_headers**: Parse a buffer of bytes as headers. ### Type Aliases * **Result**: A Result of any parsing action. ``` -------------------------------- ### icaparse Crate Overview Source: https://docs.rs/icaparse/0.2.0/icaparse Provides an overview of the icaparse crate, its purpose, and its core components. ```APIDOC ## Crate icaparse A push library for parsing ICAP/1.0 requests and responses. **Focus**: Speed and safety. Unsafe code is used for performance but is contained and invariants are enforced. **Parsing Internals**: Uses an `Iterator` instead of direct indexing to skip bounds checks. **Inspiration**: Heavily based on the `httparse` HTTP parsing library. ### Structs * `EncapsulationSection`: Describes a section of the encapsulated data. * `Header`: Represents a parsed header. * `InvalidChunkSize`: An error in parsing a chunk size. * `Request`: A parsed Request. * `Response`: A parsed Response. ### Enums * `Error`: An error in parsing. * `SectionType`: Possible sections of the encapsulated ICAP data. * `Status`: The result of a successful parse pass. ### Constants * `EMPTY_HEADER`: An empty header, useful for constructing a `Header` array for parsing. ### Functions * `parse_chunk_size`: Parse a buffer of bytes as a chunk size. * `parse_headers`: Parse a buffer of bytes as headers. ### Type Aliases * `Result`: A `Result` of any parsing action. ``` -------------------------------- ### Collect Iterator of Results Source: https://docs.rs/icaparse/0.2.0/icaparse/type.Result.html Collects an iterator of Results into a single Result. If any element is an Err, it's returned immediately. Otherwise, a container with Ok values is returned. This example demonstrates checking for overflow during addition. ```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])); ``` -------------------------------- ### Sum of Results - Rust Source: https://docs.rs/icaparse/0.2.0/icaparse/type.Result.html Calculates the sum of elements in an iterator where each element is a Result. If any element is an Err, the iteration stops and that Err is returned. Otherwise, the sum of all Ok values is returned. This example demonstrates summing integers, with a closure that returns an Err for negative numbers. ```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)); ``` ```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, Err("Negative element found")); ``` -------------------------------- ### icaparse Crate Overview Source: https://docs.rs/icaparse/0.2.0/index.html Provides an overview of the icaparse crate, its purpose, and its underlying principles. ```APIDOC ## Crate icaparse A push library for parsing ICAP/1.0 requests and responses. **Focus:** Speed and safety. Unsafe code is used but contained within a submodule with enforced invariants. **Parsing Internals:** Uses an `Iterator` instead of direct indexing, skipping bounds checks. **Inspiration:** Heavily based on the `httparse` HTTP parsing library. ``` -------------------------------- ### Fallback to alternative with or Source: https://docs.rs/icaparse/0.2.0/icaparse/type.Result.html Returns the provided result if the original is Err, otherwise returns the Ok value. Arguments are eagerly evaluated. ```rust let x: Result = Ok(2); let y: Result = Err("late error"); assert_eq!(x.or(y), Ok(2)); let x: Result = Err("early error"); let y: Result = Ok(2); assert_eq!(x.or(y), Ok(2)); let x: Result = Err("not a 2"); let y: Result = Err("late error"); assert_eq!(x.or(y), Err("late error")); let x: Result = Ok(2); let y: Result = Ok(100); assert_eq!(x.or(y), Ok(2)); ``` -------------------------------- ### Initialize header array Source: https://docs.rs/icaparse/0.2.0/icaparse/constant.EMPTY_HEADER.html Use the constant to initialize an array of headers for parsing. ```rust let headers = [icaparse::EMPTY_HEADER; 64]; ``` -------------------------------- ### Provide default value with unwrap_or Source: https://docs.rs/icaparse/0.2.0/icaparse/type.Result.html Returns the contained Ok value or a provided default. Arguments are eagerly evaluated. ```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); ``` -------------------------------- ### and Source: https://docs.rs/icaparse/0.2.0/icaparse/type.Result.html Returns the second Result if the first is Ok, otherwise returns the first Result's error. ```APIDOC ## and ### Description Returns `res` if the result is `Ok`, otherwise returns the `Err` value of `self`. Arguments passed to `and` are eagerly evaluated. ### Method `and(res: Result) -> Result` ### Parameters - **res** (Result) - The second Result to evaluate. ### Request Example ```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")); ``` ### Response - **Result** - The resulting Result after evaluation. ``` -------------------------------- ### Create New ICAP Request Source: https://docs.rs/icaparse/0.2.0/icaparse/struct.Request.html Initializes a new `Request` instance, requiring a mutable slice of headers. This is used to prepare for parsing incoming request data. ```rust pub fn new(headers: &'h mut [Header<'b>]) -> Request<'h, 'b> ``` -------------------------------- ### Constants in icaparse Source: https://docs.rs/icaparse/0.2.0/index.html Details on the constants provided by the icaparse crate. ```APIDOC ## Constants ### EMPTY_HEADER An empty header, useful for constructing a `Header` array to pass in for parsing. ``` -------------------------------- ### unwrap_or Source: https://docs.rs/icaparse/0.2.0/icaparse/type.Result.html Returns the contained Ok value or a provided default. ```APIDOC ## unwrap_or ### Description Returns the contained `Ok` value or a provided default. Arguments passed to `unwrap_or` are eagerly evaluated. ### Method `unwrap_or(default: T) -> T` ### Parameters - **default** (T) - The default value to return if the Result is Err. ### Request Example ```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); ``` ### Response - **T** - The contained Ok value or the default value. ``` -------------------------------- ### Trait Implementations Source: https://docs.rs/icaparse/0.2.0/icaparse/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 - `from_iter(iter: I) -> Result`: Takes each element in the Iterator; if it is an Err, no further elements are taken, and the Err is returned. ### Hash - `hash<__H>(&self, state: &mut __H)`: Feeds this value into the given Hasher. - `hash_slice(data: &[Self], state: &mut H)`: Feeds a slice of this type into the given Hasher. ### IntoIterator - `into_iter(self) -> IntoIter`: Returns a consuming iterator over the possibly contained value. ### Ord - `cmp(&self, other: &Result) -> Ordering`: Returns an Ordering between self and other. - `max(self, other: Self) -> Self`: Compares and returns the maximum of two values. ``` -------------------------------- ### unwrap Source: https://docs.rs/icaparse/0.2.0/icaparse/type.Result.html Returns the contained `Ok` value, consuming the `self` value. Panics if the value is an `Err`. ```APIDOC ## unwrap ### Description Returns the contained `Ok` value, consuming the `self` value. This method may panic. ### Method `unwrap` ### Panics Panics if the value is an `Err`, with a panic message provided by the `Err`’s value. ### Request Example ```rust let x: Result = Ok(2); assert_eq!(x.unwrap(), 2); let x: Result = Err("emergency failure"); x.unwrap(); // panics with `emergency failure` ``` ``` -------------------------------- ### Reference Conversion Source: https://docs.rs/icaparse/0.2.0/icaparse/type.Result.html Methods to convert Result references. ```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); ``` -------------------------------- ### Unwrap with a default value Source: https://docs.rs/icaparse/0.2.0/icaparse/type.Result.html Returns the Ok value or a default value if the result is 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); ``` -------------------------------- ### Implement is_complete for Status Source: https://docs.rs/icaparse/0.2.0/src/icaparse/lib.rs.html Provides a convenience method `is_complete` for the `Status` enum. It returns `true` if the status is `Complete` and `false` if it is `Partial`. ```rust pub fn is_complete(&self) -> bool { match *self { Status::Complete(..) => true, Status::Partial => false } } ``` -------------------------------- ### Define EMPTY_HEADER constant Source: https://docs.rs/icaparse/0.2.0/icaparse/constant.EMPTY_HEADER.html The constant definition for an empty header. ```rust pub const EMPTY_HEADER: Header<'static>; ``` -------------------------------- ### or Source: https://docs.rs/icaparse/0.2.0/icaparse/type.Result.html Returns the second Result if the first is Err, otherwise returns the first Result's Ok value. ```APIDOC ## or ### Description Returns `res` if the result is `Err`, otherwise returns the `Ok` value of `self`. Arguments passed to `or` are eagerly evaluated. ### Method `or(res: Result) -> Result` ### Parameters - **res** (Result) - The second Result to evaluate. ### Request Example ```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)); ``` ### Response - **Result** - The resulting Result after evaluation. ``` -------------------------------- ### Implement PartialEq for SectionType Source: https://docs.rs/icaparse/0.2.0/icaparse/enum.SectionType.html Enables equality comparison for SectionType values. Use this to check if two section types are the same. ```rust fn eq(&self, other: &SectionType) -> bool ``` ```rust fn ne(&self, other: &Rhs) -> bool ``` -------------------------------- ### expect Source: https://docs.rs/icaparse/0.2.0/icaparse/type.Result.html Returns the contained `Ok` value, consuming the `self` value. Panics if the value is an `Err`. ```APIDOC ## expect ### Description Returns the contained `Ok` value, consuming the `self` value. This method may panic. ### Method `expect` ### Parameters - **msg** (str) - Required - The message to display if the `Result` is an `Err`. ### Panics Panics if the value is an `Err`, with a panic message including the passed message, and the content of the `Err`. ### Request Example ```rust let x: Result = Err("emergency failure"); x.expect("Testing expect"); // panics with `Testing expect: emergency failure` ``` ### Recommended Message Style Messages should describe why the `Result` is expected to be `Ok`. ```rust let path = std::env::var("IMPORTANT_PATH") .expect("env variable `IMPORTANT_PATH` should be set by `wrapper_script.sh`"); ``` ``` -------------------------------- ### Product Implementation for Result Source: https://docs.rs/icaparse/0.2.0/icaparse/type.Result.html Calculates the product of an iterator of Results, returning the first Err encountered or the product of all Ok values. ```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 #### Request Body - **iter** (Iterator>) - Required - An iterator of Result values to multiply. ### Response #### Success Response (200) - **Result** - The product of all Ok values or the first Err encountered. ``` -------------------------------- ### Create New ICAP Response Source: https://docs.rs/icaparse/0.2.0/src/icaparse/lib.rs.html Creates a new `Response` object with a mutable slice of headers. Initializes version, code, and reason to `None`. ```rust pub fn new(headers: &'h mut [Header<'b>]) -> Response<'h, 'b> { Response { version: None, code: None, reason: None, headers: headers, } } ``` -------------------------------- ### Memory and Byte Validation Utilities Source: https://docs.rs/icaparse/0.2.0/src/icaparse/lib.rs.html Helper functions for safe slice manipulation and byte-based token validation. ```rust #[inline] fn shrink(slice: &mut &mut [T], len: usize) { debug_assert!(slice.len() >= len); let ptr = slice.as_mut_ptr(); *slice = unsafe { slice::from_raw_parts_mut(ptr, len) }; } ``` ```rust #[inline] fn is_token(b: u8) -> bool { b > 0x1F && b < 0x7F } ``` ```rust macro_rules! byte_map { ($($flag:expr,)*) => ([ $($flag != 0,)* ]) } ``` -------------------------------- ### map_or_default Source: https://docs.rs/icaparse/0.2.0/icaparse/type.Result.html Maps a `Result` to a `U` by applying a function `f` if `Ok`, otherwise returns the default value for `U`. This is a nightly-only experimental API. ```APIDOC ## pub const fn map_or_default(self, f: F) -> U where F: FnOnce(T) -> U, U: Default, ### Description Maps a `Result` to a `U` by applying function `f` to the contained value if the result is `Ok`, otherwise if `Err`, returns the default value for the type `U`. This is a nightly-only experimental API. ### Examples ``` #![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); ``` ``` -------------------------------- ### Implement TryInto for T Source: https://docs.rs/icaparse/0.2.0/icaparse/enum.SectionType.html Enables fallible conversion from type T into type U. Use this for conversions that might fail. ```rust type Error = >::Error ``` ```rust fn try_into(self) -> Result>::Error> ``` -------------------------------- ### unwrap_or_default Source: https://docs.rs/icaparse/0.2.0/icaparse/type.Result.html Returns the contained `Ok` value or a default value if the `Result` is an `Err`. ```APIDOC ## unwrap_or_default ### Description Consumes the `self` argument then, if `Ok`, returns the contained value, otherwise if `Err`, returns the default value for that type. ### Method `unwrap_or_default` ### 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); ``` ``` -------------------------------- ### unwrap_or_else Source: https://docs.rs/icaparse/0.2.0/icaparse/type.Result.html Returns the contained Ok value or computes it from a closure. ```APIDOC ## unwrap_or_else ### Description Returns the contained `Ok` value or computes it from a closure. This function can be used for control flow based on result values. ### Method `unwrap_or_else(op: F) -> T` where `F: FnOnce(E) -> T` ### Parameters - **op** (FnOnce(E) -> T) - A closure that takes the Err value and returns a computed value of type T. ### Request Example ```rust fn count(x: &str) -> usize { x.len() } assert_eq!(Ok(2).unwrap_or_else(count), 2); assert_eq!(Err("foo").unwrap_or_else(count), 3); ``` ### Response - **T** - The contained Ok value or the computed value from the closure. ``` -------------------------------- ### Header Token Validation Maps Source: https://docs.rs/icaparse/0.2.0/src/icaparse/lib.rs.html Static lookup tables for validating header names and values. ```rust static HEADER_NAME_MAP: [bool; 256] = byte_map![ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 1, 1, 1, 1, 0, 0, 1, 1, 0, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, ]; ``` ```rust static HEADER_VALUE_MAP: [bool; 256] = byte_map![ 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, ]; ``` -------------------------------- ### Implement Into for T Source: https://docs.rs/icaparse/0.2.0/icaparse/enum.SectionType.html Enables conversion from type T into type U, provided U implements From. Use this for type conversions. ```rust fn into(self) -> U ``` -------------------------------- ### Chain results with and Source: https://docs.rs/icaparse/0.2.0/icaparse/type.Result.html Returns the second result if the first is Ok, otherwise returns the Err value of the first. Note that arguments are eagerly evaluated. ```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")); ``` -------------------------------- ### Request Parsing Structure Source: https://docs.rs/icaparse/0.2.0/src/icaparse/lib.rs.html Defines the structure of an ICAP request and how to initialize it for parsing. ```APIDOC ## Request Structure ### Description Represents a parsed ICAP request. The fields are optional, allowing for partial parsing results if the input buffer is incomplete. ### Fields - **method** (Option<&str>) - The request method (e.g., RESPMOD). - **path** (Option<&str>) - The request path. - **version** (Option) - The ICAP version. - **headers** (&mut [Header]) - The request headers. - **encapsulated_sections** (Option>>) - Sections of the encapsulated body. ### Initialization Example ```rust let mut headers = [icaparse::EMPTY_HEADER; 16]; let mut req = icaparse::Request::new(&mut headers); ``` ``` -------------------------------- ### Implement TryFrom for T Source: https://docs.rs/icaparse/0.2.0/icaparse/enum.SectionType.html Enables fallible conversion from type U into type T. Use this for conversions that might fail. ```rust type Error = Infallible ``` ```rust fn try_from(value: U) -> Result>::Error> ``` -------------------------------- ### Parsing Control Macros Source: https://docs.rs/icaparse/0.2.0/src/icaparse/lib.rs.html Macros for handling whitespace and newline sequences during the parsing process. ```rust macro_rules! space { ($bytes:ident or $err:expr) => ({ expect!($bytes.next() == b' ' => Err($err)); $bytes.slice(); }) } ``` ```rust macro_rules! newline { ($bytes:ident) => ({ match next!($bytes) { b'\r' => { expect!($bytes.next() == b'\n' => Err(Error::NewLine)); $bytes.slice(); }, b'\n' => { $bytes.slice(); }, _ => return Err(Error::NewLine) } }) } ``` -------------------------------- ### inspect Source: https://docs.rs/icaparse/0.2.0/icaparse/type.Result.html Calls a function with a reference to the contained value if `Ok`. Returns the original result. ```APIDOC ## pub fn inspect(self, f: F) -> Result where F: FnOnce(&T), ### Description Calls a function with a reference to the contained value if `Ok`. Returns the original result. ### Examples ``` let x: u8 = "4" .parse::() .inspect(|x| println!("original: {x}")) .map(|x| x.pow(3)) .expect("failed to parse number"); ``` ``` -------------------------------- ### Expect a Result value Source: https://docs.rs/icaparse/0.2.0/icaparse/type.Result.html Extracts the Ok value or panics with a custom 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`"); ``` -------------------------------- ### Implement From for T Source: https://docs.rs/icaparse/0.2.0/icaparse/enum.SectionType.html Provides a trivial conversion from a value to itself. Use this when a type needs to satisfy the From trait. ```rust fn from(t: T) -> T ``` -------------------------------- ### Inspect Ok Value with inspect Source: https://docs.rs/icaparse/0.2.0/icaparse/type.Result.html Executes a function with a reference to the Ok value without modifying the result. ```rust let x: u8 = "4" .parse::() .inspect(|x| println!("original: {x}")) .map(|x| x.pow(3)) .expect("failed to parse number"); ``` -------------------------------- ### Response Parsing Source: https://docs.rs/icaparse/0.2.0/icaparse/struct.Response.html Parses a raw byte buffer into the Response struct. ```APIDOC ## pub fn parse(&mut self, buf: &'b [u8]) -> Result ### Description Try to parse a buffer of bytes into this `Response`. ### Parameters - **buf** (&'b [u8]) - Required - The raw byte buffer containing the ICAP response data. ### Response - **Result** - Returns the number of bytes consumed if successful, or an error if parsing fails. ``` -------------------------------- ### Type Aliases in icaparse Source: https://docs.rs/icaparse/0.2.0/index.html Details on the type aliases provided by the icaparse crate. ```APIDOC ## Type Aliases ### Result A Result of any parsing action. ``` -------------------------------- ### Structs in icaparse Source: https://docs.rs/icaparse/0.2.0/index.html Details on the data structures (structs) available in the icaparse crate for representing parsed ICAP data. ```APIDOC ## Structs ### EncapsulationSection Describes a section of the encapsulated data as listed in the Encapsulated header. ### Header Represents a parsed header. ### InvalidChunkSize An error in parsing a chunk size. ### Request A parsed Request. ### Response A parsed Response. ``` -------------------------------- ### Define ICAP Response Test Macro Source: https://docs.rs/icaparse/0.2.0/src/icaparse/test.rs.html The res! macro simplifies the creation of unit tests for ICAP response parsing, allowing for buffer input, expected status, and validation closures. ```rust macro_rules! res { ($name:ident, $buf:expr, |$arg:ident| $body:expr) => ( res! {$name, $buf, Ok(Status::Complete($buf.len())), |$arg| $body } ); ($name:ident, $buf:expr, $len:expr, |$arg:ident| $body:expr) => ( #[test] fn $name() { let mut headers = [EMPTY_HEADER; NUM_OF_HEADERS]; let mut res = Response::new(&mut headers[..]); let status = res.parse($buf.as_ref()); assert_eq!(status, $len); closure(res); fn closure($arg: Response) { $body } } ) } ``` ```rust res! { test_response_simple, b"ICAP/1.0 200 OK\r\n\r\n", |res| { assert_eq!(res.version.unwrap(), 1); assert_eq!(res.code.unwrap(), 200); assert_eq!(res.reason.unwrap(), "OK"); } } ``` ```rust res! { test_response_newlines, b"ICAP/1.0 403 Forbidden\nServer: foo.bar\n\n", |_r| {} } ``` ```rust res! { test_response_reason_missing, b"ICAP/1.0 200 \r\n\r\n", |res| { assert_eq!(res.version.unwrap(), 1); assert_eq!(res.code.unwrap(), 200); assert_eq!(res.reason.unwrap(), ""); } } ``` ```rust res! { test_response_reason_missing_no_space, b"ICAP/1.0 200\r\n\r\n", |res| { assert_eq!(res.version.unwrap(), 1); assert_eq!(res.code.unwrap(), 200); assert_eq!(res.reason.unwrap(), ""); } } ``` ```rust res! { test_response_reason_with_space_and_tab, b"ICAP/1.0 101 Switching Protocols\t\r\n\r\n", |res| { assert_eq!(res.version.unwrap(), 1); assert_eq!(res.code.unwrap(), 101); assert_eq!(res.reason.unwrap(), "Switching Protocols\t"); } } ``` ```rust static RESPONSE_REASON_WITH_OBS_TEXT_BYTE: &'static [u8] = b"ICAP/1.0 200 X\xFFZ\r\n\r\n"; res! { test_response_reason_with_obsolete_text_byte, RESPONSE_REASON_WITH_OBS_TEXT_BYTE, Err(::Error::Status), |_res| {} } ``` ```rust res! { test_response_reason_with_nul_byte, b"ICAP/1.0 200 \x00\r\n\r\n", Err(::Error::Status), |_res| {} } ``` ```rust res! { test_response_version_missing_space, b"ICAP/1.0", Ok(Status::Partial), |_res| {} } ``` ```rust res! { test_response_code_missing_space, b"ICAP/1.0 200", Ok(Status::Partial), |_res| {} } ``` ```rust res! { test_response_empty_lines_prefix_lf_only, b"\n\nICAP/1.0 200 OK\n\n", |_res| {} } ``` -------------------------------- ### Define Response struct Source: https://docs.rs/icaparse/0.2.0/icaparse/struct.Response.html The structure definition for a parsed ICAP response. ```rust pub struct Response<'headers, 'buf: 'headers> { pub version: Option, pub code: Option, pub reason: Option<&'buf str>, pub headers: &'headers mut [Header<'buf>], } ``` -------------------------------- ### Implement is_partial for Status Source: https://docs.rs/icaparse/0.2.0/src/icaparse/lib.rs.html Provides a convenience method `is_partial` for the `Status` enum. It returns `true` if the status is `Partial` and `false` if it is `Complete`. ```rust pub fn is_partial(&self) -> bool { match *self { Status::Complete(..) => false, Status::Partial => true } } ``` -------------------------------- ### Implement Clone for SectionType Source: https://docs.rs/icaparse/0.2.0/icaparse/enum.SectionType.html Provides methods to clone SectionType values. This allows creating copies of section types. ```rust fn clone(&self) -> SectionType ``` ```rust fn clone_from(&mut self, source: &Self) ``` -------------------------------- ### Define ICAP Request Test Macro Source: https://docs.rs/icaparse/0.2.0/src/icaparse/test.rs.html The req! macro facilitates testing ICAP request parsing by providing a buffer, expected result, and a closure for assertions. ```rust req! { test_request_with_invalid_token_delimiter, b"RESPMOD\n/ ICAP/1.0\r\nHost: foo.bar\r\n\r\n", Err(::Error::Token), |_r| {} } ``` -------------------------------- ### Implement unwrap for Status Source: https://docs.rs/icaparse/0.2.0/src/icaparse/lib.rs.html Provides a convenience method `unwrap` for the `Status` enum. It returns the contained value if the status is `Complete`, otherwise it panics with a descriptive message. ```rust pub fn unwrap(self) -> T { match self { Status::Complete(t) => t, Status::Partial => panic!("Tried to unwrap Status::Partial") } } ``` -------------------------------- ### as_deref_mut Source: https://docs.rs/icaparse/0.2.0/icaparse/type.Result.html Converts from `Result` to `Result<&mut ::Target, &mut E>` by coercing the `Ok` variant via `DerefMut`. ```APIDOC ## pub fn as_deref_mut(&mut self) -> Result<&mut ::Target, &mut E> where T: DerefMut, ### Description Converts from `Result` (or `&mut Result`) to `Result<&mut ::Target, &mut E>`. Coerces the `Ok` variant of the original `Result` via `DerefMut` and returns the new `Result`. ### Examples ``` 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); ``` ``` -------------------------------- ### Map Result to Default with map_or_default Source: https://docs.rs/icaparse/0.2.0/icaparse/type.Result.html Maps Ok to a value or returns the default for the type if Err. Requires the result_option_map_or_default feature. ```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); ``` -------------------------------- ### Unwrap a Result value Source: https://docs.rs/icaparse/0.2.0/icaparse/type.Result.html Extracts the Ok value or panics if the result is Err. ```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_or Source: https://docs.rs/icaparse/0.2.0/icaparse/type.Result.html Returns the provided default (if `Err`), or applies a function to the contained value (if `Ok`). Arguments are eagerly evaluated. ```APIDOC ## pub fn map_or(self, default: U, f: F) -> U where F: FnOnce(T) -> U, ### Description Returns the provided default (if `Err`), or applies a function to the contained value (if `Ok`). Arguments passed to `map_or` are eagerly evaluated; if you are passing the result of a function call, it is recommended to use `map_or_else`, which is lazily evaluated. ### Examples ``` 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); ``` ```