pub trait FileContext: Sized + Debug {
    type File: Read;

    fn find_file(
        &self,
        url: &str
    ) -> Result<Option<(String, Self::File)>, Error>; fn find_file_import(
        &self,
        url: &str,
        from: SourcePos
    ) -> Result<Option<SourceFile>, Error> { ... } fn find_file_use(
        &self,
        url: &str,
        from: SourcePos
    ) -> Result<Option<SourceFile>, Error> { ... } }
Expand description

A file context manages finding and loading files.

Example

use std::collections::HashMap;
use rsass::{FileContext, Error};

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

impl<'a> FileContext for StaticFileContext<'a> {
    type File = &'a [u8];

    fn find_file(
        &self, name: &str
    ) -> Result<Option<(String, Self::File)>, Error> {
        if let Some(file) = self.files.get(name).map(|data| *data) {
            Ok(Some((name.to_string(), file)))
        } else {
            Ok(None)
        }
    }
}

Required Associated Types

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

Required Methods

Find a file.

If the file is imported from another file, the argument is the exact string specified in the import declaration.

The official Sass spec 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.

Provided Methods

Find a file for @import

This includes “import-only” filenames, otherwise the same as [#find_file_use].

Find a file for @use

Implementors