Skip to main content

FSProvider

Struct FSProvider 

Source
pub struct FSProvider { /* private fields */ }
Expand description

provider that loads declerations from the file system.

this provider syncronously loads decleration files from the file system, and caches them for future use.

this provider works only in a specifed root directory, and loads files of any extension.

it can fails safely when loading.

§example

let provider = FSProvider::new("/path/to/decls").unwrap();

// cache common files
provider.load_file("commons.stomd").unwrap();

// loads other.stomd, commons.stomd is cached
parse(
	"import \"commons.stomd\" import \"other.stomd\" ... ",
	&ParseOptions::default(), &provider
).unwrap();

// fails in loading not_found.stomd
assert!(parse("import \"not_found.stomd\" ... ", &ParseOptions::default(), &provider).is_err() == true);

Implementations§

Source§

impl FSProvider

Source

pub fn new(root: impl Into<PathBuf>) -> Result<Self>

creates a FSProvider working on a given root directory with default options.

Source

pub fn with_options( root: impl Into<PathBuf>, parse_options: ParseOptions, ) -> Result<Self>

creates a FSProvider working on a given root directory with given options.

Source

pub fn load_file<'a>( &'a self, path: impl AsRef<Path>, ) -> Result<&'a DeclFile, LoadFileError>

load a declaration file at a given path.

returns a reference to the cached file if used before, else load it and returns LoadFileError if an error occurs.

Trait Implementations§

Source§

impl Debug for FSProvider

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl DeclProvider for FSProvider

Source§

fn get_by_name<'a>(&'a self, name: &str) -> Option<&'a DeclFile>

gets a decleration file with a given name.

load it if not loaded before, returns None if not found or can not be parsed.

Source§

fn get_by_id(&self, id: u64) -> &DeclFile

get a decleration file by its id. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.