### Install and Use Grass as a Binary Source: https://docs.rs/grass/latest/grass/index.html Install the Grass binary using cargo and then use it to compile SCSS files from the command line. ```bash cargo install grass grass input.scss ``` -------------------------------- ### Use as binary Source: https://docs.rs/grass/latest/src/grass/lib.rs.html Instructions for installing and using the `grass` compiler as a command-line binary. ```APIDOC ## Use as binary ```bash cargo install grass grass input.scss ``` ``` -------------------------------- ### Use as library Source: https://docs.rs/grass/latest/src/grass/lib.rs.html Example of using the `grass` crate to compile Sass string to CSS. ```APIDOC ## Use as library ```rust fn main() -> Result<(), Box> { let css = grass::from_string( "a { b { color: &; } }".to_owned(), &grass::Options::default() )?; assert_eq!(css, "a b {\n color: a b;\n}\n"); Ok(()) } ``` ``` -------------------------------- ### Getting File Metadata with and_then Source: https://docs.rs/grass/latest/grass/type.Result.html Shows how to use `and_then` to chain operations that might fail, such as getting file metadata. This example uses `Path::metadata` and `modified`. ```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); ``` -------------------------------- ### Product Implementation for Result Source: https://docs.rs/grass/latest/grass/type.Result.html This example demonstrates how the `Product` trait can be used with `Result`. It shows how to multiply parsed numbers from a vector, returning an `Ok` value if all parsing succeeds, or an `Err` if any parsing fails. ```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()); ``` -------------------------------- ### Including CSS with grass::include! Source: https://docs.rs/grass/latest/grass/macro.include.html Example of using the `grass::include!` macro to embed CSS from a Sass file into a Rust string literal. Ensure the `macro` feature is enabled. ```rust static CSS: &str = grass::include!("../static/_index.scss"); ``` -------------------------------- ### Getting a Default Value with unwrap_or Source: https://docs.rs/grass/latest/grass/type.Result.html Shows how to use `unwrap_or` to get the `Ok` value or a provided default if the `Result` is `Err`. The default value is 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); ``` -------------------------------- ### Sum Implementation for Result Source: https://docs.rs/grass/latest/grass/type.Result.html This example illustrates the use of the `Sum` trait with `Result`. It shows how to sum elements from an iterator, returning an `Ok` value if all elements meet a condition (e.g., non-negative), or an `Err` if any element fails the condition. ```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")); ``` -------------------------------- ### Into Ok Value (Never Panics) Source: https://docs.rs/grass/latest/grass/type.Result.html Use `into_ok()` to get the contained `Ok` value. This is an experimental API that never panics, providing a compile-time safeguard against `Result` types that might later introduce panicking errors. ```rust fn only_good_news() -> Result { Ok("this is fine".into()) } let s: String = only_good_news().into_ok(); println!("{s}"); ``` -------------------------------- ### Result Termination Implementation Source: https://docs.rs/grass/latest/grass/type.Result.html Shows the implementation of the Termination trait for Result, which provides a `report` method to get an ExitCode representation. ```rust impl Termination for Result where T: Termination, E: Debug, ``` -------------------------------- ### impl Any for T Source: https://docs.rs/grass/latest/grass/enum.InputSyntax.html Provides the `type_id` method to get the `TypeId` of `self`. ```APIDOC ## fn type_id(&self) -> TypeId Gets the `TypeId` of `self`. Read more ``` -------------------------------- ### Any::type_id Source: https://docs.rs/grass/latest/grass/struct.Error.html Gets the TypeId of the current type. This is part of the Any trait implementation. ```rust fn type_id(&self) -> TypeId ``` -------------------------------- ### Set Output Style Source: https://docs.rs/grass/latest/grass/struct.Options.html Choose between `Expanded` (default) for readability or `Compressed` for smaller file sizes. ```rust pub const fn style(self, style: OutputStyle) -> Options<'a> ``` -------------------------------- ### Default Options Initialization Source: https://docs.rs/grass/latest/grass/struct.Options.html Use this for the simplest configuration of Sass compilation. ```rust pub struct Options<'a> { /* private fields */ } ``` -------------------------------- ### impl CloneToUninit for T Source: https://docs.rs/grass/latest/grass/enum.InputSyntax.html Provides the `clone_to_uninit` method for performing copy-assignment to uninitialized memory. This is a nightly-only experimental API. ```APIDOC ## unsafe fn clone_to_uninit(&self, dest: *mut u8) 🔬This is a nightly-only experimental API. (`clone_to_uninit`) Performs copy-assignment from `self` to `dest`. Read more ``` -------------------------------- ### CloneToUninit::clone_to_uninit (Experimental) Source: https://docs.rs/grass/latest/grass/struct.Error.html Performs copy-assignment from self to a raw pointer destination. This is a nightly-only experimental API. ```rust unsafe fn clone_to_uninit(&self, dest: *mut u8) ``` -------------------------------- ### Unwrap or Default Value Source: https://docs.rs/grass/latest/grass/type.Result.html Use `unwrap_or_default()` to get the contained `Ok` value or the default value for the type if it's `Err`. This is useful for providing fallback values. ```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); ``` -------------------------------- ### from_path Source: https://docs.rs/grass/latest/grass/fn.from_path.html Compiles CSS from a specified file path. Note that `grass` currently only supports file paths that are valid UTF-8. ```APIDOC ## Function from_path ### Description Compile CSS from a path n.b. `grass` does not currently support files or paths that are not valid UTF-8 ### Signature ```rust pub fn from_path

(p: P, options: &Options<'_>) -> Result> where P: AsRef, ``` ### Example ```rust fn main() -> Result<(), Box> { let css = grass::from_path("input.scss", &grass::Options::default())?; Ok(()) } ``` ``` -------------------------------- ### Macro definition for include Source: https://docs.rs/grass/latest/grass/macro.include.html This shows the basic structure of the `include!` macro. ```rust macro_rules! include { ($path:literal) => { ... }; } ``` -------------------------------- ### Expect Error Value Source: https://docs.rs/grass/latest/grass/type.Result.html Use `expect_err()` to get the contained `Err` value. This method panics if the value is `Ok`, providing a custom message along with the `Ok` value. ```rust let x: Result = Ok(10); x.expect_err("Testing expect_err"); // panics with `Testing expect_err: 10` ``` -------------------------------- ### impl Equivalent for Q Source: https://docs.rs/grass/latest/grass/enum.InputSyntax.html Provides the `equivalent` method to check if a value is equivalent to a given key. ```APIDOC ## fn equivalent(&self, key: &K) -> bool Checks if this value is equivalent to the given key. Read more ``` -------------------------------- ### Unwrap Result Value Source: https://docs.rs/grass/latest/grass/type.Result.html Use `unwrap()` to get the contained `Ok` value. This method panics if the value is `Err`. It is generally discouraged in favor of safer error handling methods. ```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_ok Source: https://docs.rs/grass/latest/grass/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. ### Method `pub const fn into_ok(self) -> T` ### Constraints `where E: Into` ### Notes This is a nightly-only experimental API. ### Examples ```rust fn only_good_news() -> Result { Ok("this is fine".into()) } let s: String = only_good_news().into_ok(); println!("{s}"); ``` ``` -------------------------------- ### Compile SCSS from a file path Source: https://docs.rs/grass/latest/grass/fn.from_path.html This snippet demonstrates how to use the `from_path` function to compile an SCSS file named 'input.scss' using default options. It returns the compiled CSS string or a `grass::Error`. ```rust fn main() -> Result<(), Box> { let css = grass::from_path("input.scss", &grass::Options::default())?; Ok(()) } ``` -------------------------------- ### Unwrap Error Value Source: https://docs.rs/grass/latest/grass/type.Result.html Use `unwrap_err()` to get the contained `Err` value. This method panics if the value is `Ok`, using the `Ok` value in the panic message. It returns the `Err` value if the result is `Err`. ```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"); ``` -------------------------------- ### Error::provide (Experimental) Source: https://docs.rs/grass/latest/grass/struct.Error.html Provides type-based access to context for error reports. This is a nightly-only experimental API. ```rust fn provide<'a>(&'a self, request: &mut Request<'a>) ``` -------------------------------- ### Collecting Results with early Err and side effect Source: https://docs.rs/grass/latest/grass/type.Result.html Shows that `collect` stops processing the iterator as soon as an Err is encountered, even if there are subsequent elements. This example verifies a side effect that only occurs for processed elements. ```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); ``` -------------------------------- ### Options::load_path Source: https://docs.rs/grass/latest/grass/struct.Options.html Appends a single file system path to the list of locations Sass will search for modules. ```APIDOC ## Options::load_path ### Description Appends a single file system path to the list of locations Sass will search for modules. Sass will look in these paths when locating modules. Imports are resolved relative to the current file first, and load paths are used only if no relative file exists. ### Method `pub fn load_path

(self, path: P) -> Options<'a>` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example None ### Response #### Success Response Returns the modified `Options` struct. #### Response Example None ``` -------------------------------- ### Into Err Value (Never Panics) Source: https://docs.rs/grass/latest/grass/type.Result.html Use `into_err()` to get the contained `Err` value. This is an experimental API that never panics, providing a compile-time safeguard against `Result` types that might later introduce panicking `Ok` values. ```rust fn only_bad_news() -> Result { Err("Oops, it failed".into()) } let error: String = only_bad_news().into_err(); println!("{error}"); ``` -------------------------------- ### Compile Sass from a String Source: https://docs.rs/grass/latest/grass Demonstrates how to compile a Sass string to CSS using the `grass::from_string` function. Requires default options. ```rust fn main() -> Result<(), Box> { let css = grass::from_string( "a { b { color: &; } }".to_owned(), &grass::Options::default() )?; assert_eq!(css, "a b { color: a b; } "); Ok(()) } ``` -------------------------------- ### impl From for T Source: https://docs.rs/grass/latest/grass/enum.InputSyntax.html Provides the `from` method, which returns the argument unchanged. ```APIDOC ## fn from(t: T) -> T Returns the argument unchanged. ``` -------------------------------- ### Fs Trait Methods Source: https://docs.rs/grass/latest/grass/trait.Fs.html This section details the methods available within the Fs trait, including required and provided functionalities for file system interactions. ```APIDOC ## Trait Fs A trait to allow replacing the file system lookup mechanisms. ### Required Methods #### fn is_dir(&self, path: &Path) -> bool Returns `true` if the path exists on disk and is pointing at a directory. #### fn is_file(&self, path: &Path) -> bool Returns `true` if the path exists on disk and is pointing at a regular file. #### fn read(&self, path: &Path) -> Result, Error> Read the entire contents of a file into a bytes vector. ### Provided Methods #### fn canonicalize(&self, path: &Path) -> Result Canonicalize a file path ``` -------------------------------- ### NullFs Methods Source: https://docs.rs/grass/latest/grass/struct.NullFs.html Methods available on the NullFs struct for interacting with the file system. ```APIDOC ## NullFs ### Description A file system implementation that acts like it’s completely empty. This may be useful for security as it denies all access to the file system (so `@import` is prevented from leaking anything); you’ll need to use `from_string` for this to make any sense (since `from_path` would fail to find a file). ### Methods #### `is_file(&self, _path: &Path) -> bool` Returns `true` if the path exists on disk and is pointing at a regular file. #### `is_dir(&self, _path: &Path) -> bool` Returns `true` if the path exists on disk and is pointing at a directory. #### `read(&self, _path: &Path) -> Result, Error>` Read the entire contents of a file into a bytes vector. #### `canonicalize(&self, path: &Path) -> Result` Canonicalize a file path ``` -------------------------------- ### Options::style Source: https://docs.rs/grass/latest/grass/struct.Options.html Sets the output style for the compiled Sass. Options are `Expanded` (default) and `Compressed`. ```APIDOC ## Options::style ### Description Sets the output style for the compiled Sass. `grass` currently offers 2 different output styles: `OutputStyle::Expanded` writes each selector and declaration on its own line, while `OutputStyle::Compressed` removes extra characters and writes the entire stylesheet on a single line. By default, output is expanded. ### Method `pub const fn style(self, style: OutputStyle) -> Options<'a>` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example None ### Response #### Success Response Returns the modified `Options` struct. #### Response Example None ``` -------------------------------- ### ok Source: https://docs.rs/grass/latest/grass/type.Result.html Converts a Result into an Option, consuming the Result. ```APIDOC ## pub fn ok(self) -> Option ### Description Converts from `Result` to `Option`. Consumes `self`, converting the error to `None` if any. ### Response #### Success Response (Option) - **Some(T)**: If the result was `Ok(T)`. - **None**: If the result was `Err(E)`. ### Request Example ```rust let x: Result = Ok(2); assert_eq!(x.ok(), Some(2)); let x: Result = Err("Nothing here"); assert_eq!(x.ok(), None); ``` ``` -------------------------------- ### Compile CSS from a String Source: https://docs.rs/grass/latest/grass/fn.from_string.html Use `from_string` to compile SCSS/Sass code provided as a string. It takes the input string and default options. Ensure the input is a `String` or can be converted into one. ```rust fn main() -> Result<(), Box> { let css = grass::from_string("a { b { color: &; } }".to_string(), &grass::Options::default())?; assert_eq!(css, "a b { color: a b; } "); Ok(()) } ``` -------------------------------- ### Options::load_paths Source: https://docs.rs/grass/latest/grass/struct.Options.html Appends multiple file system paths to the list of locations Sass will search for modules. Existing load paths are not removed. ```APIDOC ## Options::load_paths ### Description Appends multiple file system paths to the list of locations Sass will search for modules. This method does not remove existing load paths. See `Options::load_path` for more information about load paths. ### Method `pub fn load_paths

(self, paths: &[P]) -> Options<'a>` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example None ### Response #### Success Response Returns the modified `Options` struct. #### Response Example None ``` -------------------------------- ### Include CSS at compile time Source: https://docs.rs/grass/latest/src/grass/lib.rs.html Demonstrates using the `grass::include!` macro to embed compiled CSS from a Sass file directly into the Rust binary at compile time. This requires the `macro` feature to be enabled. ```APIDOC ## Include CSS in your binary at compile time from a Sass source file `static CSS: &str = grass::include!("../static/_index.scss");` This requires the `"macro"` feature, which is not enabled by default. By default `grass` will track files using [`include_str!`]. This allows incremental compilation to be updated when any Sass files are modified. If compiling with a nightly version of rust, `grass` can make use of [proc_macro::tracked_path](https://github.com/rust-lang/rust/issues/99515) in order to force incremental recompilation, which is more robust and potentially faster. This is enabled by the `"nightly"` feature. ###### Limitations Compilation options are not configurable with this macro. The default values for all options are used, except for output style, which is compressed. ``` -------------------------------- ### Convert Result to Option Source: https://docs.rs/grass/latest/grass/type.Result.html The `ok()` method converts a Result into an Option, consuming the Result. It returns `Some(T)` if the Result was `Ok`, and `None` if it was `Err`. ```rust let x: Result = Ok(2); assert_eq!(x.ok(), Some(2)); let x: Result = Err("Nothing here"); assert_eq!(x.ok(), None); ``` -------------------------------- ### from_string Source: https://docs.rs/grass/latest/grass/fn.from_string.html Compiles CSS from a string. It takes the input CSS string and compilation options, returning the compiled CSS as a string or a SassError. ```APIDOC ## Function from_string ### Description Compiles CSS from a string. It takes the input CSS string and compilation options, returning the compiled CSS as a string or a SassError. ### Signature ```rust pub fn from_string(input: S, options: &Options<'_>) -> Result> where S: Into ``` ### Parameters * `input` (S): The CSS string to compile. This can be any type that can be converted into a String. * `options` (&Options<'_>): A reference to the compilation options. ### Returns * `Result>`: Ok containing the compiled CSS string on success, or an Err containing a boxed SassError on failure. ### Example ```rust fn main() -> Result<(), Box> { let css = grass::from_string("a { b { color: &; } }".to_string(), &grass::Options::default())?; assert_eq!(css, "a b {\n color: a b;\n}\n"); Ok(()) } ``` ``` -------------------------------- ### Options::input_syntax Source: https://docs.rs/grass/latest/grass/struct.Options.html Forces Sass to parse input using a specific syntax. Defaults to inferring from the file extension, or `InputSyntax::Scss` if inference is not possible. This only affects the first file loaded. ```APIDOC ## Options::input_syntax ### Description This option forces Sass to parse input using the given syntax. By default, Sass will attempt to read the file extension to determine the syntax. If this is not possible, it will default to `InputSyntax::Scss`. This flag only affects the first file loaded. Files that are loaded using `@import`, `@use`, or `@forward` will always have their syntax inferred. ### Method `pub const fn input_syntax(self, syntax: InputSyntax) -> Options<'a>` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example None ### Response #### Success Response Returns the modified `Options` struct. #### Response Example None ``` -------------------------------- ### Include Sass in Binary at Compile Time Source: https://docs.rs/grass/latest/src/grass/lib.rs.html Use the `grass::include!` macro to embed compiled CSS from Sass files directly into your binary. This requires the `"macro"` feature. ```rust #[macro_export] #[cfg(any(feature = "macro", doc))] #[cfg_attr(doc_cfg, doc(cfg(feature = "macro")))] macro_rules! include { ($path:literal) => { $crate::__internal::include_sass::include_sass!($path); }; } ``` -------------------------------- ### StdFs is_file Method Source: https://docs.rs/grass/latest/grass/struct.StdFs.html Checks if a given path exists and points to a regular file on the disk. ```rust fn is_file(&self, path: &Path) -> bool ``` -------------------------------- ### Providing a Default Value with or Source: https://docs.rs/grass/latest/grass/type.Result.html Illustrates using `or` to return the `Ok` value if present, or a secondary `Result` if the first is `Err`. 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)); ``` -------------------------------- ### Implement Debug for NullLogger Source: https://docs.rs/grass/latest/grass/struct.NullLogger.html This implementation allows NullLogger instances to be formatted for debugging purposes. The output will indicate that it's a NullLogger. ```rust impl Debug for NullLogger { fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error> { // implementation omitted } } ``` -------------------------------- ### Using unwrap_or_else with Ok and Err Source: https://docs.rs/grass/latest/grass/type.Result.html Demonstrates how unwrap_or_else provides a default value when the Result is an Err. The closure is only executed for Err variants. ```rust assert_eq!(Ok(2).unwrap_or_else(count), 2); assert_eq!(Err("foo").unwrap_or_else(count), 3); ``` -------------------------------- ### impl VZip for T Source: https://docs.rs/grass/latest/grass/enum.InputSyntax.html Provides the `vzip` method for zipping lanes. ```APIDOC ## fn vzip(self) -> V ``` -------------------------------- ### Result Try Trait Implementation (Nightly) Source: https://docs.rs/grass/latest/grass/type.Result.html Details the experimental `Try` trait implementation for Result, including its `Output`, `Residual`, `from_output`, and `branch` methods. This API is nightly-only. ```rust impl Try for Result ``` ```rust type Output = T; ``` ```rust type Residual = Result; ``` ```rust fn from_output(output: as Try>::Output) -> Result ``` ```rust fn branch(self) -> ControlFlow< as Try>::Residual, as Try>::Output> ``` -------------------------------- ### Add Single Load Path Source: https://docs.rs/grass/latest/grass/struct.Options.html Specify a directory for Sass to search for modules. Imports are resolved relative to the current file first. ```rust pub fn load_path

(self, path: P) -> Options<'a> where P: AsRef, ``` -------------------------------- ### Try for Result Source: https://docs.rs/grass/latest/grass/type.Result.html Experimental API for the `?` operator, defining how Result short-circuits and produces output. ```APIDOC ## Try Trait for Result ### Description This implementation of the `Try` trait is part of the nightly-only experimental API (`try_trait_v2`). It defines the behavior of the `?` operator when used with `Result`. ### Type Aliases #### type Output = T - **Description**: The type of the value produced by `?` when not short-circuiting. #### type Residual = Result - **Description**: The type of the value passed to `FromResidual::from_residual` as part of `?` when short-circuiting. ### Methods #### fn from_output(output: as Try>::Output) -> Result - **Description**: Constructs the `Result` type from its `Output` type. #### fn branch(self) -> ControlFlow< as Try>::Residual, as Try>::Output> - **Description**: Used in the `?` operator to decide whether to produce a value (ControlFlow::Continue) or propagate a value back to the caller (ControlFlow::Break). ``` -------------------------------- ### pub fn unwrap_or(self, default: T) -> T Source: https://docs.rs/grass/latest/grass/type.Result.html Returns the contained `Ok` value or a provided default. Arguments passed to `unwrap_or` are eagerly evaluated. ```APIDOC ## pub fn unwrap_or(self, default: T) -> T ### Description Returns the contained `Ok` value or a provided default. Arguments passed to `unwrap_or` are eagerly evaluated; if you are passing the result of a function call, it is recommended to use `unwrap_or_else`, which is lazily evaluated. ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example None ### Response #### Success Response (200) None #### Response Example None ##### §Examples ```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); ``` ``` -------------------------------- ### Convert &Result to Result<&T, &E> Source: https://docs.rs/grass/latest/grass/type.Result.html Use `as_ref()` to obtain references to the contained values without consuming the original Result. This is useful when you need to inspect the values without taking ownership. ```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")); ``` -------------------------------- ### Compile CSS from a path Source: https://docs.rs/grass/latest/index.html Compiles Sass code from a specified file path into CSS. It takes the file path and compilation options as input. ```APIDOC ## from_path ### Description Compile CSS from a path. ### Function Signature ```rust fn from_path(path: impl AsRef, options: &Options) -> Result ``` ### Parameters - **path** (impl AsRef) - The path to the Sass file to compile. - **options** (Options) - Configuration options for the Sass compilation. ### Returns - Result - A Result containing the compiled CSS string on success, or an Error on failure. ``` -------------------------------- ### Include CSS at compile time Source: https://docs.rs/grass/latest/grass Includes CSS in your binary at compile time from a Sass source file using a macro. ```APIDOC ## include! ### Description Include CSS in your binary at compile time from a Sass source file. ### Usage ```rust include!("path/to/your/styles.scss"); ``` ### Parameters - `"path/to/your/styles.scss"`: The relative or absolute path to the Sass source file. ``` -------------------------------- ### as_ref Source: https://docs.rs/grass/latest/grass/type.Result.html Provides a reference to the contained value, converting &Result to Result<&T, &E>. ```APIDOC ## pub const fn as_ref(&self) -> Result<&T, &E> ### Description Converts from `&Result` to `Result<&T, &E>`. Produces a new `Result`, containing a reference into the original, leaving the original in place. ### Response #### Success Response (Result<&T, &E>) - **Ok(&T)**: A reference to the success value if the original result was `Ok`. - **Err(&E)**: A reference to the error value if the original result was `Err`. ### Request Example ```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")); ``` ``` -------------------------------- ### expect Source: https://docs.rs/grass/latest/grass/type.Result.html Returns the contained `Ok` value, consuming the `self` value. Panics if the value is an `Err`. ```APIDOC ## pub fn expect(self, msg: &str) -> T where E: Debug, ### Description Returns the contained `Ok` value, consuming the `self` value. Panics if the value is an `Err`, with a panic message including the passed message and the content of the `Err`. ### Parameters #### Path Parameters - **msg** (&str) - Required - The message to include in the panic if the `Result` is an `Err`. ### Response #### Success Response (T) - Returns the contained `Ok` value. ### Panics Panics if the value is an `Err`. ### Request Example ```rust let x: Result = Err("emergency failure"); x.expect("Testing expect"); // panics with `Testing expect: emergency failure` ``` ### Recommended Message Style We recommend that `expect` messages are used to describe the reason you _expect_ the `Result` should be `Ok`. ```rust let path = std::env::var("IMPORTANT_PATH") .expect("env variable `IMPORTANT_PATH` should be set by `wrapper_script.sh`"); ``` ``` -------------------------------- ### impl Borrow for T Source: https://docs.rs/grass/latest/grass/enum.InputSyntax.html Provides the `borrow` method for immutable borrowing. ```APIDOC ## fn borrow(&self) -> &T Immutably borrows from an owned value. Read more ``` -------------------------------- ### StdFs is_dir Method Source: https://docs.rs/grass/latest/grass/struct.StdFs.html Checks if a given path exists and points to a directory on the disk. ```rust fn is_dir(&self, path: &Path) -> bool ``` -------------------------------- ### Force Input Syntax Source: https://docs.rs/grass/latest/grass/struct.Options.html Manually set the input syntax for the primary file. Sass usually infers this from the file extension, defaulting to `InputSyntax::Scss` if inference fails. This setting does not apply to files imported via `@import`, `@use`, or `@forward`. ```rust pub const fn input_syntax(self, syntax: InputSyntax) -> Options<'a> ``` -------------------------------- ### Add Multiple Load Paths Source: https://docs.rs/grass/latest/grass/struct.Options.html Append several directories to Sass's module search paths. Existing paths are not removed. ```rust pub fn load_paths

(self, paths: &[P]) -> Options<'a> where P: AsRef, ``` -------------------------------- ### From::from Source: https://docs.rs/grass/latest/grass/struct.Error.html Returns the argument unchanged. This is the standard implementation for the From trait. ```rust fn from(t: T) -> T ``` -------------------------------- ### Warning Logging Method Source: https://docs.rs/grass/latest/grass/trait.Logger.html Logs a message from a `@warn` statement. Requires a SpanLoc for location and a message string. ```rust fn warn(&self, location: SpanLoc, message: &str); ``` -------------------------------- ### NullFs Fs Trait Implementation - read Source: https://docs.rs/grass/latest/grass/struct.NullFs.html Implements the `read` method for NullFs. This method always returns an error, as there are no files to read from the empty file system. ```rust fn read(&self, _path: &Path) -> Result, Error> { Err(Error::new("file not found")) } ``` -------------------------------- ### Error::description (Deprecated) Source: https://docs.rs/grass/latest/grass/struct.Error.html Returns a static string description of the error. This method is deprecated and users should prefer the Display implementation or to_string(). ```rust fn description(&self) -> &'static str ``` -------------------------------- ### Chaining Fallible Operations with and_then Source: https://docs.rs/grass/latest/grass/type.Result.html Demonstrates chaining operations that may fail using `and_then`. This is useful for sequential processing where each step can produce an error. ```Rust fn sq_then_to_string(x: u32) -> Result { if x > 1_000_000 { Err("overflowed") } else { Ok((x * x).to_string()) } } 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")); ``` -------------------------------- ### map_or_else Source: https://docs.rs/grass/latest/grass/type.Result.html Maps to a fallback function if Err, or applies a function to the contained Ok value. ```APIDOC ## pub fn map_or_else(self, default: D, f: F) -> U ### Description Maps a `Result` to `U` by applying fallback function `default` to a contained `Err` value, or function `f` to a contained `Ok` value. ### Parameters #### Path Parameters - **default** (D: FnOnce(E) -> U) - Required - The fallback function to apply if the result is `Err`. - **f** (F: FnOnce(T) -> U) - Required - The function to apply if the result is `Ok`. ### Response #### Success Response (U) - **U**: The result of the `default` function if the input was `Err`, otherwise the result of the `f` function. ### Request Example ```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); ``` ``` -------------------------------- ### map_or_default Source: https://docs.rs/grass/latest/grass/type.Result.html Maps to a default value if Err, or applies a function to the contained Ok value. ```APIDOC ## pub fn map_or_default(self, f: F) -> U ### 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`. ### Parameters #### Path Parameters - **f** (F: FnOnce(T) -> U) - Required - The function to apply to the `Ok` value. ### Response #### Success Response (U) - **U**: The result of applying the function `f` if the input was `Ok`, otherwise the default value of type `U`. ### Request Example ```rust 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); ``` ``` -------------------------------- ### Result StructuralPartialEq Implementation Source: https://docs.rs/grass/latest/grass/type.Result.html Implementation of the StructuralPartialEq trait for Result. ```rust impl StructuralPartialEq for Result ``` -------------------------------- ### Compile CSS from a path Source: https://docs.rs/grass/latest/grass Compiles Sass code from a specified file path into CSS. It takes the file path and compilation options as input and returns the compiled CSS string or an error. ```APIDOC ## from_path ### Description Compile CSS from a path. ### Function Signature `fn from_path(path: impl AsRef, options: &Options) -> Result` ### Parameters #### `path` (impl AsRef) - The path to the Sass file to compile. #### `options` (&Options) - Configuration options for the Sass compilation. ### Returns - `Result`: A `Result` containing the compiled CSS string on success, or a `grass::Error` on failure. ``` -------------------------------- ### Compile CSS from a string Source: https://docs.rs/grass/latest/grass Compiles Sass code provided as a string into CSS. It takes the Sass string and compilation options as input and returns the compiled CSS string or an error. ```APIDOC ## from_string ### Description Compile CSS from a string. ### Function Signature `fn from_string(input: String, options: &Options) -> Result` ### Parameters #### `input` (String) - The Sass code to compile. #### `options` (&Options) - Configuration options for the Sass compilation. ### Returns - `Result`: A `Result` containing the compiled CSS string on success, or a `grass::Error` on failure. ``` -------------------------------- ### Compile CSS from a string Source: https://docs.rs/grass/latest/grass/index.html Compiles Sass code provided as a string into CSS. It takes the Sass string and compilation options as input and returns the compiled CSS string or an error. ```APIDOC ## from_string ### Description Compile CSS from a string. ### Function Signature `pub fn from_string(input: String, options: &Options) -> Result` ### Parameters * `input` (String) - The Sass code to compile. * `options` (&Options) - Configuration options for the compilation. ### Returns * `Result` - A `Result` containing the compiled CSS string on success, or a `grass::Error` on failure. ``` -------------------------------- ### impl Result, E>: transpose Source: https://docs.rs/grass/latest/grass/type.Result.html Transposes a `Result` of an `Option` into an `Option` of a `Result`, mapping `Ok(None)` to `None` and other cases accordingly. ```APIDOC ## impl Result, E> ### pub const fn transpose(self) -> Option> **Description**: Transposes a `Result` of an `Option` into an `Option` of a `Result`. `Ok(None)` will be mapped to `None`. `Ok(Some(_))` and `Err(_)` will be mapped to `Some(Ok(_))` and `Some(Err(_))` respectively. **Examples**: ```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); ``` ``` -------------------------------- ### inspect Source: https://docs.rs/grass/latest/grass/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. ### Parameters #### Path Parameters - **f** (FnOnce(&T)) - Required - The function to call with a reference to the `Ok` value. ### Response #### Success Response (Result) - Returns the original `Result`. ### Request Example ```rust let x: u8 = "4" .parse::() .inspect(|x| println!("original: {x}")) .map(|x| x.pow(3)) .expect("failed to parse number"); ``` ``` -------------------------------- ### Converting Result to Iterator (Ok variant) Source: https://docs.rs/grass/latest/grass/type.Result.html Shows that `into_iter` on an Ok Result yields a single-element iterator containing the Ok value. ```rust let x: Result = Ok(5); let v: Vec = x.into_iter().collect(); assert_eq!(v, [5]); ``` -------------------------------- ### NullFs Fs Trait Implementation - canonicalize Source: https://docs.rs/grass/latest/grass/struct.NullFs.html Implements the `canonicalize` method for NullFs. This method always returns an error, as paths cannot be resolved in an empty file system. ```rust fn canonicalize(&self, path: &Path) -> Result { Err(Error::new("file not found")) } ``` -------------------------------- ### impl TryInto for T Source: https://docs.rs/grass/latest/grass/enum.InputSyntax.html Provides the `try_into` method for fallible conversion from type `T` to `U`. ```APIDOC ## type Error = >::Error The type returned in the event of a conversion error. ## fn try_into(self) -> Result>::Error> Performs the conversion. ``` -------------------------------- ### map_or Source: https://docs.rs/grass/latest/grass/type.Result.html Returns a default value if the Result is Err, or applies a function to the contained Ok value. ```APIDOC ## pub fn map_or(self, default: U, f: F) -> 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. ### Parameters #### Path Parameters - **default** (U) - Required - The default value to return if the result is `Err`. - **f** (FnOnce(T) -> U) - Required - The function to apply to the `Ok` value. ### Response #### Success Response (U) - **U**: The result of the function `f` if the input was `Ok`, otherwise the `default` value. ### Request Example ```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); ``` ``` -------------------------------- ### Set Custom File System Source: https://docs.rs/grass/latest/grass/struct.Options.html Control the file system Sass uses for compilation. Defaults to `StdFs` for local file system access. ```rust pub fn fs(self, fs: &'a dyn Fs) -> Options<'a> ``` -------------------------------- ### impl BorrowMut for T Source: https://docs.rs/grass/latest/grass/enum.InputSyntax.html Provides the `borrow_mut` method for mutable borrowing. ```APIDOC ## fn borrow_mut(&mut self) -> &mut T Mutably borrows from an owned value. Read more ``` -------------------------------- ### StdFs read Method Source: https://docs.rs/grass/latest/grass/struct.StdFs.html Reads the entire contents of a file into a byte vector. Ensure the path points to an existing file. ```rust fn read(&self, path: &Path) -> Result, Error> ``` -------------------------------- ### Set Custom Logger Source: https://docs.rs/grass/latest/grass/struct.Options.html Define how log events are handled during compilation. Defaults to `StdLogger` which writes to standard output. ```rust pub fn logger(self, logger: &'a dyn Logger) -> Options<'a> ``` -------------------------------- ### and Source: https://docs.rs/grass/latest/grass/type.Result.html Returns `res` if the result is `Ok`, otherwise returns the `Err` value of `self`. Arguments are eagerly evaluated. ```APIDOC ## and ### Description Returns `res` if the result is `Ok`, otherwise returns the `Err` value of `self`. ### Method `pub fn and(self, res: Result) -> Result` ### Notes Arguments passed to `and` are eagerly evaluated; if you are passing the result of a function call, it is recommended to use `and_then`, which is lazily evaluated. ### Examples ```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")); ``` ``` -------------------------------- ### Define NullFs Struct Source: https://docs.rs/grass/latest/grass/struct.NullFs.html Defines the NullFs struct, which serves as an empty file system implementation. This is useful for security purposes, preventing any file system access. ```rust pub struct NullFs; ``` -------------------------------- ### and_then Source: https://docs.rs/grass/latest/grass/type.Result.html Calls `op` if the result is `Ok`, otherwise returns the `Err` value of `self`. This can be used for control flow based on `Result` values. ```APIDOC ## and_then ### Description Calls `op` if the result is `Ok`, otherwise returns the `Err` value of `self`. ### Method `pub fn and_then(self, op: F) -> Result` ### Constraints `where F: FnOnce(T) -> Result` ### Notes This function can be used for control flow based on `Result` values. ### Examples ```rust fn sq_then_to_string(x: u32) -> Result { x.checked_mul(x).map(|sq| sq.to_string()).ok_or("overflowed") } ``` ``` -------------------------------- ### impl Into for T Source: https://docs.rs/grass/latest/grass/enum.InputSyntax.html Provides the `into` method for converting `self` into type `U`. ```APIDOC ## fn into(self) -> U Calls `U::from(self)`. That is, this conversion is whatever the implementation of `From for U` chooses to do. ```