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
impl Config
Sourcepub fn new() -> Self
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 whenOUT_DIRis not set) - filters: none (all files included)
Sourcepub fn with_ext(self, ext: impl Into<String>) -> Self
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.
Sourcepub fn with_exts(
self,
exts: impl IntoIterator<Item = impl Into<String>>,
) -> Self
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"]);Sourcepub fn without_path(self, p: impl Into<PathBuf>) -> Self
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");Sourcepub fn without_paths(
self,
paths: impl IntoIterator<Item = impl Into<PathBuf>>,
) -> Self
pub fn without_paths( self, paths: impl IntoIterator<Item = impl Into<PathBuf>>, ) -> Self
Batch version of Config::without_path.
Sourcepub fn from_path(self, p: impl Into<PathBuf>) -> Self
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.
Sourcepub fn with_ext_as_string(self, ext: impl Into<String>) -> Self
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).
Sourcepub fn with_exts_as_string(
self,
exts: impl IntoIterator<Item = impl Into<String>>,
) -> Self
pub fn with_exts_as_string( self, exts: impl IntoIterator<Item = impl Into<String>>, ) -> Self
Batch version of Config::with_ext_as_string.
Sourcepub fn with_ext_as_bin(self, ext: impl Into<String>) -> Self
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]).
Sourcepub fn with_exts_as_bin(
self,
exts: impl IntoIterator<Item = impl Into<String>>,
) -> Self
pub fn with_exts_as_bin( self, exts: impl IntoIterator<Item = impl Into<String>>, ) -> Self
Batch version of Config::with_ext_as_bin.
Sourcepub fn with_output_path(self, p: impl Into<PathBuf>) -> Self
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.
Sourcepub fn build(self) -> Result<FixtureTree>
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.