Setup

Struct Setup 

Source
pub struct Setup<'paths> { /* private fields */ }
Expand description

A builder to configure desired test data paths.

This is created through setup! instead of a usual method as it must gather some information from the callers environment first.

This is a builder and after configuration, its Setup::build() method should be called. Note the lifetime on this struct. This is either the lifetime of paths borrowed from the caller, which it will rewrite, or it can be 'static when it owns all of the paths. The latter case requires them to be registered with Setup::add().

On a VCS copy of the surrounding package this will simply collect and validate the information, canonicalizing paths to be interpreted from the Manifest in the process.

However, when executed in the source tree from .crate then it will rewrite them all to refer to a local copy of the data instead. That is, if it is allowed to, since by default we merely provide a detailed report of data paths, repository location, and commit information that would need to be fetched before aborting. When the environment has opted into our access of network (and might have overridden the repository path) then we will perform the actual access, checkout, and rewrite.

Implementations§

Source§

impl<'lt> Setup<'lt>

Source

pub fn rewrite(self, iter: impl IntoIterator<Item = &'lt mut PathBuf>) -> Self

Register some paths to rewrite their location.

The paths should be relative to the crate’s manifest. For example, to refer to data in your tests directory you would use PathBuf::from("tests/data.zip").

The paths will be registered internally. If the repository is local they will be rewritten to be relative to the manifest location. If the repository is a crate distribution then the paths will be sparsely checked out (meaning: only that path will be downloaded from the VCS working dir and you can’t expect any other files to be present).

Those actions will happen when you call Setup::build().

§Example
use std::path::PathBuf;
use xtest_data::setup;

let mut path = PathBuf::from("tests/data.zip");
setup!().rewrite([&mut path]).build();

assert!(path.exists(), "{}", path.display());
Source

pub fn add(&mut self, path: impl AsRef<Path>) -> Files

Register the path of a file or a tree of files.

The return value is a key that can later be used in FsData. All the files under this location will be checked out when Setup::build() is called in a crate-build.

§Example
let mut vcs = xtest_data::setup!();
let datazip = vcs.add("tests/data.zip");
let testdata = vcs.build();

let path = testdata.path(&datazip);
assert!(path.exists(), "{}", path.display());
Source

pub fn build(self) -> FsData

Run the final validation and perform rewrites.

Returns the frozen dictionary of file mappings that had been registered with Setup::add(). This allows retrieving the final data paths for those items.

§Panics

This will panic if:

  • Any registered file or tree is not tracked in the VCS.
  • You have not allowed retrieving data from the VCS.
  • It was not possible to retrieve the data from the VCS.

Trait Implementations§

Source§

impl<'paths> Debug for Setup<'paths>

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<'paths> Freeze for Setup<'paths>

§

impl<'paths> RefUnwindSafe for Setup<'paths>

§

impl<'paths> Send for Setup<'paths>

§

impl<'paths> Sync for Setup<'paths>

§

impl<'paths> Unpin for Setup<'paths>

§

impl<'paths> !UnwindSafe for Setup<'paths>

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.