Skip to main content

Config

Struct Config 

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

Builder for configuring a FixtureTree.

Construct with Config::new, chain builder methods to set options, and finalise with Config::build.

§Examples

let tree = fixture_tree::Config::new()
    .from_path("test_data")
    .with_exts(["json", "toml"])
    .with_exts_as_string(["json", "toml"])
    .without_path("scratch")
    .build()
    .unwrap();
tree.generate_fixtures().unwrap();

Implementations§

Source§

impl Config

Source

pub fn new() -> Self

Create a new config with default settings.

Defaults:

  • source directory: current working directory
  • output path: $OUT_DIR/fixture_tree_autogen.rs (falls back to cwd when OUT_DIR is not set)
  • filters: none (all files included)
Source

pub fn with_ext(self, ext: impl Into<String>) -> Self

Only include files whose extension matches ext (case-insensitive).

Can be called multiple times to allow several extensions. If no extension filter is set, all files are included.

Source

pub fn with_exts( self, exts: impl IntoIterator<Item = impl Into<String>>, ) -> Self

Batch version of Config::with_ext.

config.with_exts(["json", "toml", "yaml"]);
Source

pub fn without_path(self, p: impl Into<PathBuf>) -> Self

Exclude an entire directory subtree by its path relative to the source root.

config.without_path("snapshots");
Source

pub fn without_paths( self, paths: impl IntoIterator<Item = impl Into<PathBuf>>, ) -> Self

Batch version of Config::without_path.

Source

pub fn from_path(self, p: impl Into<PathBuf>) -> Self

Set the root directory to scan for fixture files.

The path is canonicalised and, if it falls under CARGO_MANIFEST_DIR, generated code will reference it relative to the manifest via env!("CARGO_MANIFEST_DIR").

§Panics

Panics if the path does not exist or cannot be canonicalised.

Source

pub fn with_ext_as_string(self, ext: impl Into<String>) -> Self

Register a file extension whose contents should be embedded as a &'static str via include_str!.

The generated accessor for matching files returns (&'static Path, &'static str).

Source

pub fn with_exts_as_string( self, exts: impl IntoIterator<Item = impl Into<String>>, ) -> Self

Batch version of Config::with_ext_as_string.

Source

pub fn with_ext_as_bin(self, ext: impl Into<String>) -> Self

Register a file extension whose contents should be embedded as a &'static [u8] via include_bytes!.

The generated accessor for matching files returns (&'static Path, &'static [u8]).

Source

pub fn with_exts_as_bin( self, exts: impl IntoIterator<Item = impl Into<String>>, ) -> Self

Batch version of Config::with_ext_as_bin.

Source

pub fn with_output_path(self, p: impl Into<PathBuf>) -> Self

Override the path where the generated Rust source file is written.

Defaults to $OUT_DIR/fixture_tree_autogen.rs.

Source

pub fn build(self) -> Result<FixtureTree>

Validate the configuration and build a FixtureTree.

§Errors

Returns an error if:

  • An extension is registered as both string and binary.
  • The source directory cannot be read.

Trait Implementations§

Source§

impl Debug for Config

Source§

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

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

impl Default for Config

Source§

fn default() -> Self

Returns the “default value” for a type. 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.