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
impl FileLoader
pub fn new( cwd: PathBuf, cache_dir: Option<PathBuf>, repo_refs: BTreeMap<String, FilePath>, ) -> Result<Self>
sourcepub fn add_repo_file(&mut self, file: &FilePath) -> Result<()>
pub fn add_repo_file(&mut self, file: &FilePath) -> Result<()>
Load a file containing mapping of repo names to FilePath
s.
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.
sourcepub fn add_repo(&mut self, repo_id: &str, loc: &str) -> Result<()>
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:
- A branch, commit hash or release tag on a remote repository, hosted on Github
- A URL
- A relative path (to the current working directory) to a directory on the local disk.
- An absolute path to a directory on the local disk.
sourcepub fn read_to_string(&self, file: &FilePath) -> Result<String>
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.
pub fn read<T: DeserializeOwned>(&self, file: &FilePath) -> Result<T>
sourcepub fn join(&self, base: &FilePath, f: &str) -> Result<FilePath>
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
.
sourcepub fn file_path(&self, f: &str) -> Result<FilePath>
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
impl Clone for FileLoader
source§fn clone(&self) -> FileLoader
fn clone(&self) -> FileLoader
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moresource§impl Debug for FileLoader
impl Debug for FileLoader
source§impl Drop for FileLoader
impl Drop for FileLoader
source§impl TryFrom<&LoaderConfig> for FileLoader
impl TryFrom<&LoaderConfig> for FileLoader
Auto Trait Implementations§
impl Freeze for FileLoader
impl !RefUnwindSafe for FileLoader
impl Send for FileLoader
impl Sync for FileLoader
impl Unpin for FileLoader
impl !UnwindSafe for FileLoader
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)§impl<T, UT> HandleAlloc<UT> for T
impl<T, UT> HandleAlloc<UT> for T
§fn new_handle(value: Arc<T>) -> Handle
fn new_handle(value: Arc<T>) -> Handle
§unsafe fn clone_handle(handle: Handle) -> Handle
unsafe fn clone_handle(handle: Handle) -> Handle
§unsafe fn consume_handle(handle: Handle) -> Arc<T>
unsafe fn consume_handle(handle: Handle) -> Arc<T>
Arc<>
Read more