Trait rsass::input::Loader

source ·
pub trait Loader: Sized + Debug {
    type File: Read;

    // Required method
    fn find_file(&self, url: &str) -> Result<Option<Self::File>, LoadError>;
}
Expand description

A file context manages finding and loading files.

§Example

use std::collections::HashMap;
use rsass::input::{Loader, LoadError};

#[derive(Clone, Debug)]
struct MemoryLoader<'a> {
    files: HashMap<String, &'a[u8]>,
}

impl<'a> Loader for MemoryLoader<'a> {
    type File = &'a [u8];

    fn find_file(&self, name: &str) -> Result<Option<Self::File>, LoadError> {
        Ok(self.files.get(name).map(|data| *data))
    }
}

Required Associated Types§

source

type File: Read

Anything that can be read can be a File in an implementation.

Required Methods§

source

fn find_file(&self, url: &str) -> Result<Option<Self::File>, LoadError>

Find a file.

If a file named base/input.scss uses a file named module, the name is converted to base/module.scss and variants by Context::find_file, and this method is called for each variant to check if it exists.

Note that if a file with the given name does not exist, that is not an error. In that case, find_file is expected to return Ok(None). Things like illegal file names (for the given backend) or lacking permissions, are handled as errors.

The official Sass specification prescribes that files are loaded by url instead of by path to ensure universal compatibility of style sheets. This effectively mandates the use of forward slashes on all platforms.

Object Safety§

This trait is not object safe.

Implementors§