From f0bf96fe72a62207684aaa470847e61dc1df5a39 Mon Sep 17 00:00:00 2001 From: Vance Longwill <4891589+VanceLongwill@users.noreply.github.com> Date: Wed, 31 Jan 2024 12:48:52 +0300 Subject: [PATCH] Add support for boxed values (#4) --- expunge/src/lib.rs | 10 +++++++++- expunge/tests/expunge.rs | 15 +++++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/expunge/src/lib.rs b/expunge/src/lib.rs index b596a66..341b704 100644 --- a/expunge/src/lib.rs +++ b/expunge/src/lib.rs @@ -72,7 +72,7 @@ use std::{ collections::{HashMap, HashSet}, - ops::{Deref, DerefMut}, + ops::{Deref, DerefMut}, sync::Arc, }; pub use expunge_derive::*; @@ -242,6 +242,14 @@ where } } +impl Expunge for Box where T: Expunge { + fn expunge(self) -> Self + where + Self: Sized { + Box::new((*self).expunge()) + } +} + #[cfg(feature = "zeroize")] impl Expunge for Secret where diff --git a/expunge/tests/expunge.rs b/expunge/tests/expunge.rs index a138f8d..b8a5b3e 100644 --- a/expunge/tests/expunge.rs +++ b/expunge/tests/expunge.rs @@ -284,3 +284,18 @@ fn it_works_enum() { let expunged = item.expunge(); assert_eq!(SensitiveItem::ZeroizableString("99".to_string()), expunged); } + +#[test] +fn it_returns_boxed() { + #[derive(Expunge)] + struct Location { + #[expunge] + city: String, + } + + let location = Box::new(Location { + city: "New York".to_string(), + }); + + let _: Box = location.expunge(); +}