pub struct Factory { /* private fields */ }Expand description
How a Factory generates artifacts.
§Examples
use uselesskey_core::{Factory, Mode, Seed};
// Check if a factory is in random or deterministic mode
let fx = Factory::random();
assert!(matches!(fx.mode(), Mode::Random));
let seed = Seed::from_env_value("test").unwrap();
let fx = Factory::deterministic(seed);
assert!(matches!(fx.mode(), Mode::Deterministic { .. }));Implementations§
Source§impl Factory
impl Factory
Sourcepub fn random() -> Self
pub fn random() -> Self
Create a factory in random mode.
Each process run produces different artifacts, but within a process,
artifacts are cached by (domain, label, spec, variant).
Sourcepub fn deterministic(master: Seed) -> Self
pub fn deterministic(master: Seed) -> Self
Create a deterministic factory from an existing seed.
Sourcepub fn deterministic_from_str(text: &str) -> Self
pub fn deterministic_from_str(text: &str) -> Self
Create a deterministic factory from plain text.
This hashes the provided string verbatim with BLAKE3. Unlike
Seed::from_env_value, it does not trim whitespace or interpret
hex-shaped strings specially.
Sourcepub fn deterministic_from_env(var: &str) -> Result<Self, Error>
pub fn deterministic_from_env(var: &str) -> Result<Self, Error>
Create a deterministic factory from an environment variable.
The environment variable can contain:
- A 64-character hex string (with optional
0xprefix) - Any other string (hashed to produce a 32-byte seed)
§Errors
Returns an error if the environment variable is not set.
Sourcepub fn clear_cache(&self)
pub fn clear_cache(&self)
Clear the artifact cache.
Sourcepub fn get_or_init<T, F>(
&self,
domain: ArtifactDomain,
label: &str,
spec_bytes: &[u8],
variant: &str,
init: F,
) -> Arc<T>
pub fn get_or_init<T, F>( &self, domain: ArtifactDomain, label: &str, spec_bytes: &[u8], variant: &str, init: F, ) -> Arc<T>
Get a cached artifact by (domain, label, spec, variant) or generate one.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Factory
impl !RefUnwindSafe for Factory
impl Send for Factory
impl Sync for Factory
impl Unpin for Factory
impl UnsafeUnpin for Factory
impl !UnwindSafe for Factory
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
Mutably borrows from an owned value. Read more