Trait rsass::FileContext[][src]

pub trait FileContext: Sized + Debug {
    type File: Read;
    fn find_file(
        &self,
        url: &str
    ) -> Result<Option<(Self, String, Self::File)>, Error>; }

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<(Self, String, Self::File)>, Error> {
        if let Some(file) = self.files.get(name).map(|data| *data) {
            Ok(Some((self.clone(), name.to_string(), file)))
        } else {
            Ok(None)
        }
    }
}

Associated Types

type File: Read[src]

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

Loading content...

Required methods

fn find_file(
    &self,
    url: &str
) -> Result<Option<(Self, String, Self::File)>, Error>
[src]

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.

Loading content...

Implementors

impl FileContext for FsFileContext[src]

type File = File

Loading content...