Skip to content

Commit

Permalink
Merge pull request #21 from eopb/fake
Browse files Browse the repository at this point in the history
feat: `fake` support
  • Loading branch information
eopb authored Feb 5, 2023
2 parents 5fef5b1 + 196878d commit 097e220
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
5 changes: 4 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "redact"
version = "0.1.0"
version = "0.1.1-pre0"
authors = ["Ethan Brierley <ethanboxx@gmail.com>"]
license = "MIT/Apache-2.0"
readme = "README.md"
Expand All @@ -16,9 +16,12 @@ exclude = [".github"]
default = ["std"]
# impl std::error::Error for Secret<E> where E: Error
std = []
fake = ["dep:fake", "dep:rand"]

[dependencies]
serde = { version = "1.0", optional = true, default-features = false }
fake = { version = "2.5", optional = true, default-features = false }
rand = { version = "0.8", optional = true, default-features = false }

[dev-dependencies]
serde = { version = "1.0", features = ["derive"] }
Expand Down
18 changes: 18 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -199,3 +199,21 @@ pub fn expose_secret<S: Serializer, T: Serialize>(
) -> Result<S::Ok, S::Error> {
secret.expose_secret().serialize(serializer)
}

#[cfg(feature = "fake")]
use fake::Dummy;
#[cfg(feature = "fake")]
use rand::Rng;

#[cfg(feature = "fake")]
impl<T: Dummy<U>, U> Dummy<U> for Secret<T> {
#[inline]
fn dummy_with_rng<R: Rng + ?Sized>(config: &U, rng: &mut R) -> Self {
Secret(T::dummy_with_rng(config, rng))
}

#[inline]
fn dummy(config: &U) -> Self {
Secret(T::dummy(config))
}
}

0 comments on commit 097e220

Please sign in to comment.