Skip to content

Commit

Permalink
feat: serde::redacted convenience serialize_with - serialize with…
Browse files Browse the repository at this point in the history
…out exposing

# Todo
- [ ] Document function with rustdoc
- [ ] Update serde section in `README.md`
  • Loading branch information
eopb committed Nov 5, 2023
1 parent e06604f commit f371154
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ mod error;
mod fake;
mod ops;
#[cfg(feature = "serde")]
mod serde;
pub mod serde;

#[cfg(feature = "serde")]
pub use crate::serde::expose_secret;
Expand Down
6 changes: 6 additions & 0 deletions src/serde.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,12 @@ pub fn expose_secret<S: Serializer, T: Serialize>(
.serialize(serializer)
}

#[cfg(feature = "serde")]
#[inline]
pub fn redacted<S: Serializer, T>(secret: &Secret<T>, serializer: S) -> Result<S::Ok, S::Error> {
format!("{secret:?}").serialize(serializer)
}

#[cfg(test)]
mod tests {
use super::*;
Expand Down

0 comments on commit f371154

Please sign in to comment.