From 942d21a750da0da8359d99bb827c1618e9dc969a Mon Sep 17 00:00:00 2001 From: Chris Olstrom Date: Wed, 30 Oct 2024 03:06:40 -0700 Subject: [PATCH] adds support for re-exporting crate (#79) --- CHANGELOG.md | 14 +++++++++++++- Cargo.toml | 4 ++-- README.md | 2 +- src/private.rs | 17 +++++++++-------- src/redactor.rs | 6 ++++++ veil-macros/Cargo.toml | 2 +- veil-macros/src/flags.rs | 6 +++--- veil-macros/src/fmt.rs | 14 +++++++------- veil-macros/src/redactable.rs | 10 +++++----- 9 files changed, 47 insertions(+), 28 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c0baa4cf..ab52fd09 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,16 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 --- +## [0.2.0] - 2024-10-30 + +### Changed + +- Breaking: de-anchor veil imports, to allow for reexporting. + +This might cause issues in some very rare cases, but generally shouldn't require any changes. + +--- + ## [0.1.7] - 2023-11-20 ### Changed @@ -21,6 +31,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Updated to syn v2 -[Unreleased]: https://github.com/primait/veil/compare/0.1.7...HEAD + +[Unreleased]: https://github.com/primait/veil/compare/0.2.0...HEAD +[0.2.0]: https://github.com/primait/veil/compare/0.1.7...0.2.0 [0.1.7]: https://github.com/primait/veil/compare/0.1.6...0.1.7 [0.1.6]: https://github.com/primait/veil/compare/0.1.5...0.1.6 diff --git a/Cargo.toml b/Cargo.toml index 1abacfd2..2c508093 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "veil" -version = "0.1.7" +version = "0.2.0" edition = "2021" description = "Rust derive macro for redacting sensitive data in `std::fmt::Debug`" license = "MIT OR Apache-2.0" @@ -28,7 +28,7 @@ name = "disable_redaction" required-features = ["toggle"] [dependencies] -veil-macros = { path = "veil-macros", version = "=0.1.7" } +veil-macros = { path = "veil-macros", version = "=0.2.0" } once_cell = "1" [dev-dependencies] diff --git a/README.md b/README.md index 0bb7928f..9228071c 100644 --- a/README.md +++ b/README.md @@ -14,7 +14,7 @@ Add to your Cargo.toml: ```toml [dependencies] -veil = "0.1.7" +veil = "0.2.0" ``` Usage documentation can be found [here](https://docs.rs/veil). diff --git a/src/private.rs b/src/private.rs index 27e03631..9429c8f8 100644 --- a/src/private.rs +++ b/src/private.rs @@ -11,13 +11,13 @@ pub enum RedactSpecialization { /// This could be improved & rid of in a number of different ways in the future: /// /// * Once specialization is stabilized, we can use a trait to override redacting behavior for some types, - /// one of which would be [`Option`]. + /// one of which would be [`Option`]. /// /// * Once std::ptr::metadata and friends are stabilized, we could use it to unsafely cast the dyn Debug pointer - /// to a concrete [`Option`] and redact it directly. Probably not the best idea. + /// to a concrete [`Option`] and redact it directly. Probably not the best idea. /// /// * Once trait upcasting is stabilized, we could use it to upcast the dyn Debug pointer to a dyn Any and then - /// downcast it to a concrete [`Option`] and redact it directly. + /// downcast it to a concrete [`Option`] and redact it directly. Option, } @@ -127,12 +127,13 @@ impl RedactionTarget<'_> { } } } -impl ToString for RedactionTarget<'_> { - fn to_string(&self) -> String { + +impl Display for RedactionTarget<'_> { + fn fmt(&self, f: &mut std::fmt::Formatter) -> Result<(), std::fmt::Error> { match self { - RedactionTarget::Debug { this, alternate: false } => format!("{:?}", this), - RedactionTarget::Debug { this, alternate: true } => format!("{:#?}", this), - RedactionTarget::Display(this) => this.to_string(), + RedactionTarget::Debug { this, alternate: false } => write!(f, "{:?}", this), + RedactionTarget::Debug { this, alternate: true } => write!(f, "{:#?}", this), + RedactionTarget::Display(this) => write!(f, "{}", this), } } } diff --git a/src/redactor.rs b/src/redactor.rs index 7cd18f85..3d3944b1 100644 --- a/src/redactor.rs +++ b/src/redactor.rs @@ -214,3 +214,9 @@ impl RedactorBuilder { Ok(Redactor(flags)) } } + +impl Default for RedactorBuilder { + fn default() -> Self { + Self::new() + } +} diff --git a/veil-macros/Cargo.toml b/veil-macros/Cargo.toml index 58422e91..72e67e3e 100644 --- a/veil-macros/Cargo.toml +++ b/veil-macros/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "veil-macros" -version = "0.1.7" +version = "0.2.0" edition = "2021" description = "Veil procedural macros" license = "MIT OR Apache-2.0" diff --git a/veil-macros/src/flags.rs b/veil-macros/src/flags.rs index a2aa8029..735417f3 100644 --- a/veil-macros/src/flags.rs +++ b/veil-macros/src/flags.rs @@ -88,11 +88,11 @@ pub enum RedactionLength { impl quote::ToTokens for RedactionLength { fn to_tokens(&self, tokens: &mut proc_macro2::TokenStream) { match self { - RedactionLength::Full => quote! { ::veil::private::RedactionLength::Full }.to_tokens(tokens), - RedactionLength::Partial => quote! { ::veil::private::RedactionLength::Partial }.to_tokens(tokens), + RedactionLength::Full => quote! { veil::private::RedactionLength::Full }.to_tokens(tokens), + RedactionLength::Partial => quote! { veil::private::RedactionLength::Partial }.to_tokens(tokens), RedactionLength::Fixed(n) => { let n = n.get(); - quote! { ::veil::private::RedactionLength::Fixed(::core::num::NonZeroU8::new(#n).unwrap()) } + quote! { veil::private::RedactionLength::Fixed(::core::num::NonZeroU8::new(#n).unwrap()) } .to_tokens(tokens) } } diff --git a/veil-macros/src/fmt.rs b/veil-macros/src/fmt.rs index 7924dd88..6de8ddd0 100644 --- a/veil-macros/src/fmt.rs +++ b/veil-macros/src/fmt.rs @@ -162,7 +162,7 @@ pub(crate) fn generate_redact_call( unused.redacted_something(); let specialization = if is_option { - quote! { ::std::option::Option::Some(::veil::private::RedactSpecialization::Option) } + quote! { ::std::option::Option::Some(veil::private::RedactSpecialization::Option) } } else { quote! { ::std::option::Option::None } }; @@ -170,18 +170,18 @@ pub(crate) fn generate_redact_call( if field_flags.display { // std::fmt::Display quote! { - &::veil::private::RedactionFormatter { - this: ::veil::private::RedactionTarget::Display(#field_accessor), - flags: ::veil::private::RedactFlags { #field_flags }, + &veil::private::RedactionFormatter { + this: veil::private::RedactionTarget::Display(#field_accessor), + flags: veil::private::RedactFlags { #field_flags }, specialization: #specialization } } } else { // std::fmt::Debug quote! { - &::veil::private::RedactionFormatter { - this: ::veil::private::RedactionTarget::Debug { this: #field_accessor, alternate }, - flags: ::veil::private::RedactFlags { #field_flags }, + &veil::private::RedactionFormatter { + this: veil::private::RedactionTarget::Debug { this: #field_accessor, alternate }, + flags: veil::private::RedactFlags { #field_flags }, specialization: #specialization } } diff --git a/veil-macros/src/redactable.rs b/veil-macros/src/redactable.rs index 7451b57e..91bef7cd 100644 --- a/veil-macros/src/redactable.rs +++ b/veil-macros/src/redactable.rs @@ -48,19 +48,19 @@ fn try_derive(mut item: syn::DeriveInput) -> Result { let name_ident = &item.ident; let (impl_generics, ty_generics, where_clause) = item.generics.split_for_impl(); Ok(quote! { - impl #impl_generics ::veil::Redactable for #name_ident #ty_generics #where_clause { + impl #impl_generics veil::Redactable for #name_ident #ty_generics #where_clause { fn redact(&self) -> String { - ::veil::private::derived_redactable( + veil::private::derived_redactable( self, - ::veil::private::RedactFlags { #flags } + veil::private::RedactFlags { #flags } ) } fn redact_into(&self, buffer: &mut dyn ::std::fmt::Write) -> ::std::fmt::Result { buffer.write_str( - ::veil::private::derived_redactable( + veil::private::derived_redactable( self, - ::veil::private::RedactFlags { #flags } + veil::private::RedactFlags { #flags } ) .as_str() )