Struct nimbus_fml::util::loaders::FileLoader

source ·
pub struct FileLoader { /* private fields */ }
Expand description

Utility class to abstract away the differences between loading from file and network.

With a nod to offline developer experience, files which come from the network are cached on disk.

The cache directory should be in a directory that will get purged on a clean build.

This allows us to import files from another repository (via https) or include files from a local files.

The loader is able to resolve a shortcut syntax similar to other package managers.

By default a prefix of @XXXX/YYYY: resolves to the main branch XXXX/YYYY Github repo.

The config is a map of repository names to paths, URLs or branches.

Config files can be loaded

Implementations§

source§

impl FileLoader

source

pub fn new( cwd: PathBuf, cache_dir: Option<PathBuf>, repo_refs: BTreeMap<String, FilePath> ) -> Result<Self>

source

pub fn add_repo_file(&mut self, file: &FilePath) -> Result<()>

Load a file containing mapping of repo names to FilePaths. Repo files can be JSON or YAML in format. Files are simple key value pair mappings of repo_id to repository locations, where:

  • a repo id is of the format used on Github: $ORGANIZATION/$PROJECT, and
  • location can be
    • a path to a directory on disk, or
    • a ref/branch/tag/commit hash in the repo stored on Github.

Relative paths to on disk directories will be taken as relative to this file.

source

pub fn add_repo(&mut self, repo_id: &str, loc: &str) -> Result<()>

Add a repo and version/tag/ref/location. repo_id is the github $ORGANIZATION/$PROJECT string, e.g. mozilla/application-services. The loc string can be a:

  1. A branch, commit hash or release tag on a remote repository, hosted on Github
  2. A URL
  3. A relative path (to the current working directory) to a directory on the local disk.
  4. An absolute path to a directory on the local disk.
source

pub fn read_to_string(&self, file: &FilePath) -> Result<String>

This loads a text file from disk or the network.

If it’s coming from the network, then cache the file to disk (based on the URL).

We don’t worry about cache invalidation, because a clean build should blow the cache away.

source

pub fn read<T: DeserializeOwned>(&self, file: &FilePath) -> Result<T>

source

pub fn join(&self, base: &FilePath, f: &str) -> Result<FilePath>

Joins a path to a string, to make a new path.

We want to be able to support local and remote files. We also want to be able to support a configurable short cut format. Following a pattern common in other package managers, @XXXX/YYYY is used as short hand for the main branch in github repos.

If f is a relative path, the result is relative to base.

source

pub fn file_path(&self, f: &str) -> Result<FilePath>

Make a new path.

We want to be able to support local and remote files. We also want to be able to support a configurable short cut format. Following a pattern common in other package managers, @XXXX/YYYY is used as short hand for the main branch in github repos.

If f is a relative path, the result is relative to self.cwd.

Trait Implementations§

source§

impl Clone for FileLoader

source§

fn clone(&self) -> FileLoader

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Debug for FileLoader

source§

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

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

impl Drop for FileLoader

source§

fn drop(&mut self)

Executes the destructor for this type. Read more
source§

impl TryFrom<&LoaderConfig> for FileLoader

§

type Error = FMLError

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

fn try_from(loader_config: &LoaderConfig) -> Result<Self, Self::Error>

Performs the conversion.

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.

§

impl<T, UT> HandleAlloc<UT> for T
where T: Send + Sync,

§

fn new_handle(value: Arc<T>) -> Handle

Create a new handle for an Arc value Read more
§

unsafe fn clone_handle(handle: Handle) -> Handle

Clone a handle Read more
§

unsafe fn consume_handle(handle: Handle) -> Arc<T>

Consume a handle, getting back the initial Arc<> Read more
§

unsafe fn get_arc(handle: Handle) -> Arc<Self>

Get a clone of the Arc<> using a “borrowed” handle. Read more
source§

impl<T> Instrument for T

source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> Same for T

§

type Output = T

Should always be Self
source§

impl<T> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

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

§

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>,

§

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.
source§

impl<T> WithSubscriber for T

source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more