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>; fn find_file_import(
        &self,
        url: &str
    ) -> Result<Option<(Self, String, Self::File)>, Error> { ... }
fn find_file_use(
        &self,
        url: &str
    ) -> Result<Option<(Self, String, Self::File)>, 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<(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.

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.

Provided methods

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

Find a file for @import

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

Find a file for @import

Implementors

impl FileContext for FsFileContext[src]

type File = File

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