FileSource

Trait FileSource 

Source
pub trait FileSource<'files>: Sync {
    type Filepath: AsRef<Path>;
    type Contents: AsRef<[u8]>;
    type Entry: Send;
    type State: Send + Clone;
    type Iter: Iterator<Item = Self::Entry> + Send;

    // Required methods
    fn entries(&'files self) -> Result<Self::Iter, Box<dyn ErrorTrait>>;
    fn filepath(
        &'files self,
        entry: &Self::Entry,
        state: &mut Self::State,
    ) -> Result<Self::Filepath, Box<dyn ErrorTrait>>;
    fn contents(
        &'files self,
        entry: &Self::Entry,
        state: &mut Self::State,
    ) -> Result<Self::Contents, Box<dyn ErrorTrait>>;
    fn state(&'files self) -> Result<Self::State, Box<dyn ErrorTrait>>;

    // Provided methods
    fn overrides(
        &self,
        path: impl AsRef<Path>,
        state: &mut Self::State,
    ) -> Overrides { ... }
    fn language_override(
        &self,
        _path: impl AsRef<Path>,
        _state: &mut Self::State,
    ) -> Option<Language> { ... }
    fn is_documentation_override(
        &self,
        _path: impl AsRef<Path>,
        _state: &mut Self::State,
    ) -> Option<bool> { ... }
    fn is_generated_override(
        &self,
        _path: impl AsRef<Path>,
        _state: &mut Self::State,
    ) -> Option<bool> { ... }
    fn is_vendored_override(
        &self,
        _path: impl AsRef<Path>,
        _state: &mut Self::State,
    ) -> Option<bool> { ... }
    fn is_detectable_override(
        &self,
        _path: impl AsRef<Path>,
        _state: &mut Self::State,
    ) -> Option<bool> { ... }
}
Expand description

Provides files and overrides.

Required Associated Types§

Source

type Filepath: AsRef<Path>

Source

type Contents: AsRef<[u8]>

Source

type Entry: Send

Source

type State: Send + Clone

Sometimes it’s necessary to share a state between iterations to reduce expensive commands.

Source

type Iter: Iterator<Item = Self::Entry> + Send

Required Methods§

Source

fn entries(&'files self) -> Result<Self::Iter, Box<dyn ErrorTrait>>

Returns an iterator over the entries use to get filenames and contents.

Source

fn filepath( &'files self, entry: &Self::Entry, state: &mut Self::State, ) -> Result<Self::Filepath, Box<dyn ErrorTrait>>

Gets a filename from an entry.

Source

fn contents( &'files self, entry: &Self::Entry, state: &mut Self::State, ) -> Result<Self::Contents, Box<dyn ErrorTrait>>

Gets file contents from an entry.

Source

fn state(&'files self) -> Result<Self::State, Box<dyn ErrorTrait>>

Gets a state that can be shared between iterations.

Provided Methods§

Source

fn overrides( &self, path: impl AsRef<Path>, state: &mut Self::State, ) -> Overrides

Provides combined overrides for the file.

Source

fn language_override( &self, _path: impl AsRef<Path>, _state: &mut Self::State, ) -> Option<Language>

Provides an optional override for the detected language.

Source

fn is_documentation_override( &self, _path: impl AsRef<Path>, _state: &mut Self::State, ) -> Option<bool>

Provides an optional override for documentation file detection.

Source

fn is_generated_override( &self, _path: impl AsRef<Path>, _state: &mut Self::State, ) -> Option<bool>

Provides an optional override for generated file detection.

Source

fn is_vendored_override( &self, _path: impl AsRef<Path>, _state: &mut Self::State, ) -> Option<bool>

Provides an optional override for vendored file detection.

Source

fn is_detectable_override( &self, _path: impl AsRef<Path>, _state: &mut Self::State, ) -> Option<bool>

Provides an optional override for if the file is detectable.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§

Source§

impl<'files> FileSource<'files> for Directory

Source§

impl<'repo> FileSource<'repo> for Git

Source§

type Entry = &'repo Entry

Source§

type Filepath = Cow<'repo, Path>

Source§

type Contents = Vec<u8>

Source§

type State = (State, Repository)

Source§

type Iter = Iter<'repo>