From a05562ce5e04b818d526e523b663bbb514fb12c0 Mon Sep 17 00:00:00 2001 From: juliohq Date: Sat, 21 Jan 2023 14:10:32 -0300 Subject: [PATCH 1/2] Add into boxed function --- src/lib.rs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/lib.rs b/src/lib.rs index 6df36c9..f97b43a 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -98,6 +98,11 @@ impl Lingo { self.set_context_locale(context_locale); self } + + /// Boxes the `Lingo` object. + pub fn into_boxed(self) -> Box { + Box::new(self) + } } /// The way to have a Lingo object in the whole application From 04df4ebd34c0db50b0d094cd9a49075f212138b5 Mon Sep 17 00:00:00 2001 From: juliohq Date: Sat, 21 Jan 2023 14:21:51 -0300 Subject: [PATCH 2/2] Add into boxed test --- src/lib.rs | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/lib.rs b/src/lib.rs index f97b43a..5f20634 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -185,4 +185,20 @@ mod builder_tests { let lingo = lingo![].with_context_locale(Locale::from_string("fr_FR", '_').unwrap()); assert_eq!(lingo.context_locale().to_code(), "fr_FR".to_string()); } +} + +#[cfg(test)] +mod box_tests { + use crate::{Lingo, Locale}; + + #[test] + fn into_boxed() { + let lingo = lingo![].into_boxed(); + + let boxed_fn = |obj: Box| -> bool { + true + }; + + assert_eq!(boxed_fn(lingo), true); + } } \ No newline at end of file