diff --git a/src/lib.rs b/src/lib.rs index 6df36c9..5f20634 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 @@ -180,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