### AxoClient::load_and_write_to_dir Source: https://docs.rs/axoasset/2.0.1/axoasset/remote/struct.AxoClient.html Performs a GET request to the URL and writes the bytes to a local directory. ```APIDOC ## pub async fn load_and_write_to_dir(&self, url: &UrlStr, dest_dir: impl AsRef) -> Result ### Description GETs the URL and writes its bytes to the given local dir. The filename used will be computed from the url/mime, and the resulting filepath will be returned. ``` -------------------------------- ### AxoClient::load_and_write_to_file Source: https://docs.rs/axoasset/2.0.1/axoasset/remote/struct.AxoClient.html Performs a GET request to the URL and writes the bytes to a local file. ```APIDOC ## pub async fn load_and_write_to_file(&self, url: &UrlStr, dest_file: impl AsRef) -> Result<()> ### Description GETs the URL and writes its bytes to the given local file. ``` -------------------------------- ### AxoClient::load_string Source: https://docs.rs/axoasset/2.0.1/axoasset/remote/struct.AxoClient.html Performs a GET request to the URL and returns the body as a String. ```APIDOC ## pub async fn load_string(&self, url: &UrlStr) -> Result ### Description GETs the URL and returns its body as a String. ``` -------------------------------- ### AxoClient::load_source Source: https://docs.rs/axoasset/2.0.1/axoasset/remote/struct.AxoClient.html Performs a GET request to the URL and returns a SourceFile containing the body. ```APIDOC ## pub async fn load_source(&self, url: &UrlStr) -> Result ### Description GETs the URL and returns a crate::SourceFile containing its body. ``` -------------------------------- ### AxoClient::get Source: https://docs.rs/axoasset/2.0.1/axoasset/remote/struct.AxoClient.html Performs a GET request to the URL and returns the raw reqwest::Response. ```APIDOC ## pub async fn get(&self, url: &UrlStr) -> Result ### Description GETs the URL and returns the raw reqwest::Response. ``` -------------------------------- ### Get filename from path Source: https://docs.rs/axoasset/2.0.1/axoasset/local/fn.filename.html Extracts the filename component from a provided Utf8Path. ```rust pub fn filename(origin_path: &Utf8Path) -> Result ``` -------------------------------- ### Get String capacity Source: https://docs.rs/axoasset/2.0.1/axoasset/remote/type.UrlString.html Returns the capacity of the String in bytes. ```rust let s = String::with_capacity(10); assert!(s.capacity() >= 10); ``` -------------------------------- ### AxoClient::load_bytes Source: https://docs.rs/axoasset/2.0.1/axoasset/remote/struct.AxoClient.html Performs a GET request to the URL and returns the body as a vector of bytes. ```APIDOC ## pub async fn load_bytes(&self, url: &UrlStr) -> Result> ### Description GETs the URL and returns its body as a Vec. ``` -------------------------------- ### Create new SourceFile instances Source: https://docs.rs/axoasset/2.0.1/axoasset/source/struct.SourceFile.html?search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Methods to initialize a SourceFile, either empty or with existing content. ```rust pub fn new_empty(origin_path: &str) -> Self ``` ```rust pub fn new(origin_path: &str, contents: String) -> Self ``` -------------------------------- ### Load SourceFile from local path Source: https://docs.rs/axoasset/2.0.1/axoasset/source/struct.SourceFile.html?search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Loads a SourceFile from a local path, acting as the equivalent of LocalAsset::load_asset. ```rust pub fn load_local(origin_path: impl AsRef) -> Result ``` -------------------------------- ### LocalAsset::new Source: https://docs.rs/axoasset/2.0.1/axoasset/local/struct.LocalAsset.html?search= Creates a new LocalAsset instance with a specified path and byte contents without performing IO. ```APIDOC ## pub fn new(origin_path: impl AsRef, contents: Vec) -> Result ### Description A new asset is created with a claimed path on the local filesystem and a vector of bytes representing its contents. This does not perform IO operations. ``` -------------------------------- ### Convert Cow<'a, str> to String Source: https://docs.rs/axoasset/2.0.1/axoasset/remote/type.UrlString.html Shows how to convert a clone-on-write string into an owned String, which may involve heap allocation. ```rust // If the string is not owned... let cow: Cow<'_, str> = Cow::Borrowed("eggplant"); // It will allocate on the heap and copy the string. let owned: String = String::from(cow); assert_eq!(&owned[..], "eggplant"); ``` -------------------------------- ### into_ok Source: https://docs.rs/axoasset/2.0.1/axoasset/error/type.Result.html?search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Returns the contained Ok value without panicking. ```APIDOC ## pub const fn into_ok(self) -> T ### Description Returns the contained `Ok` value, but never panics. This is a nightly-only experimental API. ``` -------------------------------- ### Create a new String Source: https://docs.rs/axoasset/2.0.1/axoasset/remote/type.UrlString.html Creates an empty String without initial allocation. ```rust let s = String::new(); ``` -------------------------------- ### pub fn filename(origin_path: &Utf8Path) -> Result Source: https://docs.rs/axoasset/2.0.1/axoasset/local/fn.filename.html?search= Retrieves the filename from a provided path or returns a descriptive error if the operation fails. ```APIDOC ## pub fn filename(origin_path: &Utf8Path) -> Result ### Description Get the filename of a path, or a pretty error. ### Signature `pub fn filename(origin_path: &Utf8Path) -> Result` ### Parameters - **origin_path** (&Utf8Path) - Required - The path from which to extract the filename. ### Returns - **Result** - Returns the filename as a String on success, or an error if the path is invalid or the filename cannot be determined. ``` -------------------------------- ### LocalAsset::load_asset Source: https://docs.rs/axoasset/2.0.1/axoasset/local/struct.LocalAsset.html?search= Loads an asset from a path on the local filesystem. ```APIDOC ## pub fn load_asset(origin_path: impl AsRef) -> Result ### Description Loads an asset from a path on the local filesystem, returning a LocalAsset struct. ``` -------------------------------- ### AxoClient::with_reqwest Source: https://docs.rs/axoasset/2.0.1/axoasset/remote/struct.AxoClient.html Creates a new instance of AxoClient using an existing reqwest::Client. ```APIDOC ## pub fn with_reqwest(client: Client) -> Self ### Description Creates an AxoClient with the given reqwest::Client. ``` -------------------------------- ### Access SourceFile metadata and content Source: https://docs.rs/axoasset/2.0.1/axoasset/source/struct.SourceFile.html?search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Methods to retrieve the filename, origin path, and file contents. ```rust pub fn filename(&self) -> &str ``` ```rust pub fn origin_path(&self) -> &str ``` ```rust pub fn as_str(&self) -> &str ``` ```rust pub fn contents(&self) -> &str ``` -------------------------------- ### Into Ok Source: https://docs.rs/axoasset/2.0.1/axoasset/error/type.Result.html?search=u32+-%3E+bool Extracts the Ok value without panicking, intended for infallible results. ```rust fn only_good_news() -> Result { Ok("this is fine".into()) } let s: String = only_good_news().into_ok(); println!("{s}"); ``` -------------------------------- ### Create a String with capacity Source: https://docs.rs/axoasset/2.0.1/axoasset/remote/type.UrlString.html Creates an empty String with a pre-allocated buffer to reduce reallocations. ```rust let mut s = String::with_capacity(10); // The String contains no chars, even though it has capacity for more assert_eq!(s.len(), 0); // These are all done without reallocating... let cap = s.capacity(); for _ in 0..10 { s.push('a'); } assert_eq!(s.capacity(), cap); // ...but this may make the string reallocate s.push('a'); ``` -------------------------------- ### Calculate Product of Result Iterator Source: https://docs.rs/axoasset/2.0.1/axoasset/error/type.Result.html?search= Demonstrates using the product method on an iterator of Results, which short-circuits on the first Err encountered. ```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()); ``` -------------------------------- ### pub fn filename(origin_path: &Utf8Path) -> Result Source: https://docs.rs/axoasset/2.0.1/axoasset/local/fn.filename.html Retrieves the filename from a provided Utf8Path. Returns a Result containing the filename string or an error. ```APIDOC ## Function: filename ### Description Get the filename of a path, or a pretty error. ### Signature `pub fn filename(origin_path: &Utf8Path) -> Result` ### Parameters - **origin_path** (&Utf8Path) - Required - The path from which to extract the filename. ``` -------------------------------- ### Fallback to alternative Result with or Source: https://docs.rs/axoasset/2.0.1/axoasset/error/type.Result.html?search=u32+-%3E+bool Returns the current Result if it is Ok, otherwise returns the provided alternative Result. ```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)); ``` -------------------------------- ### Concatenate Strings using the Add trait Source: https://docs.rs/axoasset/2.0.1/axoasset/remote/type.UrlString.html Demonstrates different ways to concatenate strings, including moving ownership or cloning to preserve the original string. ```rust let a = String::from("hello"); let b = String::from(" world"); let c = a + &b; // `a` is moved and can no longer be used here. ``` ```rust let a = String::from("hello"); let b = String::from(" world"); let c = a.clone() + &b; // `a` is still valid here. ``` ```rust let a = "hello"; let b = " world"; let c = a.to_string() + b; ``` -------------------------------- ### Reserve exact capacity for String Source: https://docs.rs/axoasset/2.0.1/axoasset/remote/type.UrlString.html Reserves the minimum required capacity without deliberate over-allocation. ```rust let mut s = String::new(); s.reserve_exact(10); assert!(s.capacity() >= 10); ``` ```rust let mut s = String::with_capacity(10); s.push('a'); s.push('b'); // s now has a length of 2 and a capacity of at least 10 let capacity = s.capacity(); assert_eq!(2, s.len()); assert!(capacity >= 10); // Since we already have at least an extra 8 capacity, calling this... s.reserve_exact(8); // ... doesn't actually increase. assert_eq!(capacity, s.capacity()); ``` -------------------------------- ### SourceFile Methods Source: https://docs.rs/axoasset/2.0.1/axoasset/source/struct.SourceFile.html?search=std%3A%3Avec Methods available for interacting with the SourceFile struct. ```APIDOC ## pub fn new_empty(origin_path: &str) -> Self Create an empty SourceFile with the given name. ## pub fn new(origin_path: &str, contents: String) -> Self Create a new source file with the given name and contents. ## pub fn load_local(origin_path: impl AsRef) -> Result SourceFile equivalent of LocalAsset::load_asset. ## pub fn filename(&self) -> &str Get the filename of a SourceFile. ## pub fn origin_path(&self) -> &str Get the origin_path of a SourceFile. ## pub fn as_str(&self) -> &str Get the contents of a SourceFile. ## pub fn contents(&self) -> &str Get the contents of a SourceFile (alias for as_str). ## pub fn span_for_line_col(&self, line: usize, col: usize) -> Option Gets a proper SourceSpan from a line-and-column representation (1-based). ## pub fn span_for_substr(&self, substr: &str) -> Option Creates a span for an item using a substring of contents. ``` -------------------------------- ### AxoClient::head Source: https://docs.rs/axoasset/2.0.1/axoasset/remote/struct.AxoClient.html Performs a HEAD request to the URL and returns the raw reqwest::Response. ```APIDOC ## pub async fn head(&self, url: &UrlStr) -> Result ### Description HEADs the URL and returns the raw reqwest::Response. ``` -------------------------------- ### try_reserve_exact Source: https://docs.rs/axoasset/2.0.1/axoasset/remote/type.UrlString.html?search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Tries to reserve the minimum capacity for at least `additional` bytes more than the current length without deliberate over-allocation. ```APIDOC ## pub fn try_reserve_exact(&mut self, additional: usize) -> Result<(), TryReserveError> ### Description Tries to reserve the minimum capacity for at least `additional` bytes more than the current length. Unlike `try_reserve`, this will not deliberately over-allocate to speculatively avoid frequent allocations. ### Parameters - **additional** (usize) - The number of additional bytes to reserve. ``` -------------------------------- ### Create String from Raw Parts Source: https://docs.rs/axoasset/2.0.1/axoasset/remote/type.UrlString.html Constructs a String from a raw pointer, length, and capacity. This is highly unsafe and requires strict adherence to memory safety invariants. ```rust unsafe { let s = String::from("hello"); // Deconstruct the String into parts. let (ptr, len, capacity) = s.into_raw_parts(); let s = String::from_raw_parts(ptr, len, capacity); assert_eq!(String::from("hello"), s); } ``` -------------------------------- ### LocalAsset::write_to_dir Source: https://docs.rs/axoasset/2.0.1/axoasset/local/struct.LocalAsset.html?search= Writes an asset to a directory on the local filesystem. ```APIDOC ## pub fn write_to_dir(&self, dest_dir: impl AsRef) -> Result ### Description Writes an asset to a path on the local filesystem, determining the filename from the origin path. ``` -------------------------------- ### Convert Box to String Source: https://docs.rs/axoasset/2.0.1/axoasset/remote/type.UrlString.html Demonstrates converting an owned boxed string slice into a String. ```rust let s1: String = String::from("hello world"); let s2: Box = s1.into_boxed_str(); let s3: String = String::from(s2); assert_eq!("hello world", s3) ``` -------------------------------- ### pub fn filename(origin_url: &UrlStr, headers: &HeaderMap) -> Result Source: https://docs.rs/axoasset/2.0.1/axoasset/remote/fn.filename.html?search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Attempts to extract or generate a filename from an asset's origin URL and associated response headers. ```APIDOC ## Function: filename ### Description This function takes an asset's origin path and attempts to identify if the final segment of the URL is a filename. If no filename is found, it drops the host from the origin URL, slugifies the path, and appends an extension based on the Mime type found in the provided response headers. ### Signature `pub fn filename(origin_url: &UrlStr, headers: &HeaderMap) -> Result` ### Parameters - **origin_url** (&UrlStr) - The origin URL of the asset. - **headers** (&HeaderMap) - The response headers associated with the asset, used for Mime type detection if a filename cannot be parsed directly. ### Returns - **Result** - Returns the identified or generated filename as a String, or an error if the operation fails. ``` -------------------------------- ### Unwrap Result or Default Source: https://docs.rs/axoasset/2.0.1/axoasset/error/type.Result.html?search= 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); ``` -------------------------------- ### unwrap Source: https://docs.rs/axoasset/2.0.1/axoasset/error/type.Result.html?search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Returns the contained Ok value, consuming the self value. Panics if the value is an Err. ```APIDOC ## pub fn unwrap(self) -> T ### Description Returns the contained `Ok` value, consuming the `self` value. Panics if the value is an `Err`. ### Examples ```rust let x: Result = Ok(2); assert_eq!(x.unwrap(), 2); ``` ``` -------------------------------- ### Query String length Source: https://docs.rs/axoasset/2.0.1/axoasset/remote/type.UrlString.html Returns the length of the string in bytes. Note that this may differ from the number of characters. ```rust let a = String::from("foo"); assert_eq!(a.len(), 3); let fancy_f = String::from("ƒoo"); assert_eq!(fancy_f.len(), 4); assert_eq!(fancy_f.chars().count(), 3); ``` -------------------------------- ### RemoteAsset Methods Source: https://docs.rs/axoasset/2.0.1/axoasset/remote/struct.RemoteAsset.html?search= Methods available on the RemoteAsset struct for accessing asset data and writing to the filesystem. ```APIDOC ## pub fn filename(&self) -> &str ### Description Gets the filename of the RemoteAsset. The filename may be computed based on factors like mimetypes and does not necessarily reflect the raw URL's path. ## pub fn origin_path(&self) -> &str ### Description Gets the origin_path of the RemoteAsset. This is an alias for the URL. ## pub fn url(&self) -> &str ### Description Gets the URL of the RemoteAsset. ## pub fn as_bytes(&self) -> &[u8] ### Description Gets the bytes of the RemoteAsset as a slice. ## pub fn into_bytes(self) -> Vec ### Description Gets the bytes of the RemoteAsset by-value as a vector. ## pub async fn write_to_dir(&self, dest_dir: impl AsRef) -> Result ### Description Writes the RemoteAsset's bytes to the given local directory. The filename used will be the one returned by `RemoteAsset::filename`, and the resulting file path will be returned. ## pub async fn write_to_file(&self, dest_file: impl AsRef) -> Result<()> ### Description Writes the RemoteAsset's bytes to the given local filepath. Unlike `write_to_dir`, this method ignores the computed `RemoteAsset::filename` and uses the provided path instead. ``` -------------------------------- ### LocalAsset::copy_file_to_dir Source: https://docs.rs/axoasset/2.0.1/axoasset/local/struct.LocalAsset.html?search=u32+-%3E+bool Copies a file to a directory, preserving the original filename. ```APIDOC ## pub fn copy_file_to_dir(origin_path: impl AsRef, dest_dir: impl AsRef) -> Result ### Description Copies an asset from one location on the local filesystem to the given directory. The destination will use the same file name as the origin has. ``` -------------------------------- ### AxoClient::load_asset Source: https://docs.rs/axoasset/2.0.1/axoasset/remote/struct.AxoClient.html Loads an asset from a URL and returns a RemoteAsset containing its body. ```APIDOC ## pub async fn load_asset(&self, url: &UrlStr) -> Result ### Description Loads an asset from a URL and returns a RemoteAsset containing its body. ``` -------------------------------- ### Reserve exact capacity for String Source: https://docs.rs/axoasset/2.0.1/axoasset/remote/type.UrlString.html Use try_reserve_exact to allocate memory without speculative over-allocation. Returns an error if allocation fails. ```rust use std::collections::TryReserveError; fn process_data(data: &str) -> Result { let mut output = String::new(); // Pre-reserve the memory, exiting if we can't output.try_reserve_exact(data.len())?; // Now we know this can't OOM in the middle of our complex work output.push_str(data); Ok(output) } ``` -------------------------------- ### with_subscriber(self, subscriber: S) -> WithDispatch Source: https://docs.rs/axoasset/2.0.1/axoasset/spanned/struct.Spanned.html?search=std%3A%3Avec Attaches the provided Subscriber to the current type, returning a WithDispatch wrapper. ```APIDOC ## fn with_subscriber(self, subscriber: S) -> WithDispatch ### Description Attaches the provided `Subscriber` to this type, returning a `WithDispatch` wrapper. ### Parameters - **subscriber** (S) - Required - The subscriber to attach, which must implement `Into`. ``` -------------------------------- ### Try to reserve capacity Source: https://docs.rs/axoasset/2.0.1/axoasset/remote/type.UrlString.html Attempts to reserve capacity, returning an error if allocation fails or capacity overflows. ```rust use std::collections::TryReserveError; fn process_data(data: &str) -> Result { let mut output = String::new(); // Pre-reserve the memory, exiting if we can't output.try_reserve(data.len())?; // Now we know this can't OOM in the middle of our complex work output.push_str(data); Ok(output) } ``` -------------------------------- ### Convert owned UTF-8 bytes to String Source: https://docs.rs/axoasset/2.0.1/axoasset/remote/type.UrlString.html Experimental nightly API to convert a Vec to a String, substituting invalid sequences. ```rust #![feature(string_from_utf8_lossy_owned)] // some bytes, in a vector let sparkle_heart = vec![240, 159, 146, 150]; let sparkle_heart = String::from_utf8_lossy_owned(sparkle_heart); assert_eq!(String::from("💖"), sparkle_heart); ``` ```rust #![feature(string_from_utf8_lossy_owned)] // some invalid bytes let input: Vec = b"Hello \xF0\x90\x80World".into(); let output = String::from_utf8_lossy_owned(input); assert_eq!(String::from("Hello World"), output); ``` -------------------------------- ### Define SourceFile struct Source: https://docs.rs/axoasset/2.0.1/axoasset/source/struct.SourceFile.html?search=std%3A%3Avec The definition of the SourceFile struct. ```rust pub struct SourceFile { /* private fields */ } ``` -------------------------------- ### And Result Chaining Source: https://docs.rs/axoasset/2.0.1/axoasset/error/type.Result.html?search= Returns the provided result if the current result is Ok, otherwise returns the Err. ```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")); ``` -------------------------------- ### Split String at index Source: https://docs.rs/axoasset/2.0.1/axoasset/remote/type.UrlString.html Splits the string into two at the given byte index, returning a new String containing the remainder. ```rust let mut hello = String::from("Hello, World!"); let world = hello.split_off(7); assert_eq!(hello, "Hello, "); assert_eq!(world, "World!"); ``` -------------------------------- ### unwrap_or_default Source: https://docs.rs/axoasset/2.0.1/axoasset/error/type.Result.html?search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Returns the contained Ok value or the default value for the type if it is an Err. ```APIDOC ## pub fn unwrap_or_default(self) -> T ### Description Consumes the `self` argument then, if `Ok`, returns the contained value, otherwise if `Err`, returns the default value for that type. ``` -------------------------------- ### Provide default values with unwrap_or and unwrap_or_else Source: https://docs.rs/axoasset/2.0.1/axoasset/error/type.Result.html?search= Returns the contained value or a default, with unwrap_or_else allowing for lazy computation of the default value. ```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); ``` ```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); ``` -------------------------------- ### And Then Result Chaining Source: https://docs.rs/axoasset/2.0.1/axoasset/error/type.Result.html?search= Calls a function to produce a new Result if the current result is Ok. ```rust fn sq_then_to_string(x: u32) -> Result { x.checked_mul(x).map(|sq| sq.to_string()).ok_or("overflowed") } ``` -------------------------------- ### fn filename Source: https://docs.rs/axoasset/2.0.1/axoasset/remote/fn.filename.html?search= Attempts to extract or generate a filename from an asset's origin URL and response headers. ```APIDOC ## fn filename ### Description Takes an asset's origin path and attempts to identify if the final segment of the URL is a filename. If no filename is found, it drops the host, slugifies the path, and appends an extension based on the Mime type in the provided headers. ### Signature `pub fn filename(origin_url: &UrlStr, headers: &HeaderMap) -> Result` ### Parameters - **origin_url** (&UrlStr) - The origin URL of the asset. - **headers** (&HeaderMap) - The response headers containing Mime type information. ### Returns - **Result** - Returns the identified or generated filename, or an error if the operation fails. ``` -------------------------------- ### Check String length and emptiness Source: https://docs.rs/axoasset/2.0.1/axoasset/remote/type.UrlString.html?search=std%3A%3Avec Returns the length in bytes or checks if the string is empty. Note that length is measured in bytes, not characters. ```rust let a = String::from("foo"); assert_eq!(a.len(), 3); let fancy_f = String::from("ƒoo"); assert_eq!(fancy_f.len(), 4); assert_eq!(fancy_f.chars().count(), 3); ``` ```rust let mut v = String::new(); assert!(v.is_empty()); v.push('a'); assert!(!v.is_empty()); ``` -------------------------------- ### Access String as Slice Source: https://docs.rs/axoasset/2.0.1/axoasset/remote/type.UrlString.html Returns a string slice containing the entire contents of the String. ```rust let s = String::from("foo"); assert_eq!("foo", s.as_str()); ``` -------------------------------- ### as_bytes Source: https://docs.rs/axoasset/2.0.1/axoasset/remote/type.UrlString.html?search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Returns a byte slice of the String's contents. ```APIDOC ## pub const fn as_bytes(&self) -> &[u8] ### Description Returns a byte slice of this `String`’s contents. ``` -------------------------------- ### Copying Result Contents Source: https://docs.rs/axoasset/2.0.1/axoasset/error/type.Result.html?search= Maps a Result<&T, E> or Result<&mut T, E> to a Result by copying the Ok value. ```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 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)); ``` -------------------------------- ### LocalAsset::search_ancestors Source: https://docs.rs/axoasset/2.0.1/axoasset/local/struct.LocalAsset.html?search= Searches for a file in the current directory or its ancestors. ```APIDOC ## pub fn search_ancestors(start_dir: impl AsRef, desired_filename: &str) -> Result ### Description Find a desired file in the provided directory or an ancestor of it. Returns the path to the found file on success. ``` -------------------------------- ### Inspect Result Ok Source: https://docs.rs/axoasset/2.0.1/axoasset/error/type.Result.html?search= Executes a closure 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"); ``` -------------------------------- ### Expect Result Value Source: https://docs.rs/axoasset/2.0.1/axoasset/error/type.Result.html?search= Returns the Ok value or panics with a 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`"); ``` -------------------------------- ### Generate SourceSpan from coordinates or substrings Source: https://docs.rs/axoasset/2.0.1/axoasset/source/struct.SourceFile.html?search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Methods to locate specific spans within the source file. Note that span_for_line_col is a heavy-weight operation. ```rust pub fn span_for_line_col(&self, line: usize, col: usize) -> Option ``` ```rust pub fn span_for_substr(&self, substr: &str) -> Option ``` -------------------------------- ### fn filename Source: https://docs.rs/axoasset/2.0.1/axoasset/remote/fn.filename.html?search=std%3A%3Avec Extracts or generates a filename from a URL and associated headers. ```APIDOC ## pub fn filename(origin_url: &UrlStr, headers: &HeaderMap) -> Result ### Description This function takes an asset's origin path and attempts to identify if the final segment of the URL is a filename. If no filename is found, it drops the host from the origin URL, slugifies the path, and appends an extension based on the MIME type found in the provided response headers. ### Parameters - **origin_url** (&UrlStr) - The origin URL of the asset. - **headers** (&HeaderMap) - The response headers associated with the asset, used to determine the file extension if necessary. ### Returns - **Result** - Returns the identified or generated filename, or an error if the operation fails. ``` -------------------------------- ### Convert Result to Option Source: https://docs.rs/axoasset/2.0.1/axoasset/error/type.Result.html?search= Methods to convert Result into Option by either keeping the Ok value or the Err value. ```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")); ``` -------------------------------- ### and_then Source: https://docs.rs/axoasset/2.0.1/axoasset/error/type.Result.html?search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Calls the provided function if the result is Ok, otherwise returns the Err. ```APIDOC ## pub fn and_then(self, op: F) -> Result ### Description Calls `op` if the result is `Ok`, otherwise returns the `Err` value of `self`. This function can be used for control flow based on `Result` values. ``` -------------------------------- ### Convert Result to References Source: https://docs.rs/axoasset/2.0.1/axoasset/error/type.Result.html?search= Methods to obtain references to the inner values of a Result. ```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); ``` -------------------------------- ### Function Signature for filename Source: https://docs.rs/axoasset/2.0.1/axoasset/remote/fn.filename.html The function signature for extracting a filename from a URL and header map. ```rust pub fn filename(origin_url: &UrlStr, headers: &HeaderMap) -> Result ``` -------------------------------- ### Cloning Result Contents Source: https://docs.rs/axoasset/2.0.1/axoasset/error/type.Result.html?search= Maps a Result<&T, E> or Result<&mut T, E> to a Result by cloning the Ok value. ```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 cloned = x.cloned(); assert_eq!(cloned, Ok(12)); ``` -------------------------------- ### and Source: https://docs.rs/axoasset/2.0.1/axoasset/error/type.Result.html?search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Returns the provided result if the current result is Ok, otherwise returns the Err. ```APIDOC ## pub fn and(self, res: Result) -> Result ### Description Returns `res` if the result is `Ok`, otherwise returns the `Err` value of `self`. ``` -------------------------------- ### with_current_subscriber(self) -> WithDispatch Source: https://docs.rs/axoasset/2.0.1/axoasset/spanned/struct.Spanned.html?search=std%3A%3Avec Attaches the current default Subscriber to the type, returning a WithDispatch wrapper. ```APIDOC ## fn with_current_subscriber(self) -> WithDispatch ### Description Attaches the current default `Subscriber` to this type, returning a `WithDispatch` wrapper. ``` -------------------------------- ### Re-exporting axoasset components Source: https://docs.rs/axoasset/2.0.1/axoasset/index.html The library re-exports core modules and types for easier access. ```rust pub use error::AxoassetError; ``` ```rust pub use local::LocalAsset; ``` ```rust pub use remote::AxoClient; ``` ```rust pub use source::SourceFile; ``` ```rust pub use spanned::Spanned; ``` ```rust pub use reqwest; ``` -------------------------------- ### Unwrap Result Value Source: https://docs.rs/axoasset/2.0.1/axoasset/error/type.Result.html?search= Extracts the Ok value, panicking if the result is an 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` ``` -------------------------------- ### into_err Source: https://docs.rs/axoasset/2.0.1/axoasset/error/type.Result.html?search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Returns the contained Err value without panicking. ```APIDOC ## pub const fn into_err(self) -> E ### Description Returns the contained `Err` value, but never panics. This is a nightly-only experimental API. ``` -------------------------------- ### Define LocalAsset struct Source: https://docs.rs/axoasset/2.0.1/axoasset/local/struct.LocalAsset.html?search= The definition of the LocalAsset struct. ```rust pub struct LocalAsset { /* private fields */ } ``` -------------------------------- ### Access String as bytes Source: https://docs.rs/axoasset/2.0.1/axoasset/remote/type.UrlString.html Returns the underlying byte slice of the string. ```rust let s = String::from("hello"); assert_eq!(&[104, 101, 108, 108, 111], s.as_bytes()); ``` -------------------------------- ### Into Ok Value Source: https://docs.rs/axoasset/2.0.1/axoasset/error/type.Result.html?search= Extracts the Ok value without risk of panicking, requiring the error type to be uninhabited. ```rust fn only_good_news() -> Result { Ok("this is fine".into()) } let s: String = only_good_news().into_ok(); println!("{s}"); ``` -------------------------------- ### Provide fallback results with or and or_else Source: https://docs.rs/axoasset/2.0.1/axoasset/error/type.Result.html?search= Use or for eager evaluation of fallback results, or or_else for lazy evaluation via a closure. ```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)); ``` ```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)); ``` -------------------------------- ### AxoClient Struct Definition Source: https://docs.rs/axoasset/2.0.1/axoasset/remote/struct.AxoClient.html?search= The primary structure for managing HTTP requests. ```rust pub struct AxoClient { /* private fields */ } ``` -------------------------------- ### push Source: https://docs.rs/axoasset/2.0.1/axoasset/remote/type.UrlString.html?search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Appends a character to the end of the String. ```APIDOC ## pub fn push(&mut self, ch: char) ### Description Appends the given `char` to the end of this `String`. ### Parameters - **ch** (char) - The character to append. ``` -------------------------------- ### Convert char to String Source: https://docs.rs/axoasset/2.0.1/axoasset/remote/type.UrlString.html Allocates a new String containing a single character. ```rust let c: char = 'a'; let s: String = String::from(c); assert_eq!("a", &s[..]); ``` -------------------------------- ### expect_err Source: https://docs.rs/axoasset/2.0.1/axoasset/error/type.Result.html?search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Returns the contained Err value, panicking if the value is an Ok. ```APIDOC ## pub fn expect_err(self, msg: &str) -> E ### Description Returns the contained `Err` value, consuming the `self` value. Panics if the value is an `Ok`, with a panic message including the passed message. ``` -------------------------------- ### Pop character from String Source: https://docs.rs/axoasset/2.0.1/axoasset/remote/type.UrlString.html Removes and returns the last character of the string, or None if empty. ```rust let mut s = String::from("abč"); assert_eq!(s.pop(), Some('č')); assert_eq!(s.pop(), Some('b')); assert_eq!(s.pop(), Some('a')); assert_eq!(s.pop(), None); ``` -------------------------------- ### Convert String to Byte Vector Source: https://docs.rs/axoasset/2.0.1/axoasset/remote/type.UrlString.html Consumes the String and returns its underlying byte vector without copying. ```rust let s = String::from("hello"); let bytes = s.into_bytes(); assert_eq!(&[104, 101, 108, 108, 111][..], &bytes[..]); ``` -------------------------------- ### Map Result Values Source: https://docs.rs/axoasset/2.0.1/axoasset/error/type.Result.html?search=std%3A%3Avec Applies a function to the Ok value of a Result. ```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(..) => {} } } ``` -------------------------------- ### shrink_to Source: https://docs.rs/axoasset/2.0.1/axoasset/remote/type.UrlString.html?search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Shrinks the capacity of the String with a lower bound. ```APIDOC ## pub fn shrink_to(&mut self, min_capacity: usize) ### Description Shrinks the capacity of this `String` with a lower bound. The capacity will remain at least as large as both the length and the supplied value. ### Parameters - **min_capacity** (usize) - The minimum capacity to maintain. ``` -------------------------------- ### truncate Source: https://docs.rs/axoasset/2.0.1/axoasset/remote/type.UrlString.html?search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Shortens the String to the specified length. ```APIDOC ## pub fn truncate(&mut self, new_len: usize) ### Description Shortens this `String` to the specified length. ### Parameters - **new_len** (usize) - The new length to truncate to. ``` -------------------------------- ### Compute default value with unwrap_or_else Source: https://docs.rs/axoasset/2.0.1/axoasset/error/type.Result.html?search=u32+-%3E+bool Returns the contained Ok value or computes a default value using the provided closure. ```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); ``` -------------------------------- ### Copying and Cloning Result Contents Source: https://docs.rs/axoasset/2.0.1/axoasset/error/type.Result.html?search=std%3A%3Avec Methods to transform Result<&T, E> or Result<&mut T, E> into Result by copying or cloning the inner value. ```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)); ```