Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add into boxed function #2

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,11 @@ impl Lingo {
self.set_context_locale(context_locale);
self
}

/// Boxes the `Lingo` object.
pub fn into_boxed(self) -> Box<Lingo> {
Box::new(self)
}
}

/// The way to have a Lingo object in the whole application
Expand Down Expand Up @@ -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<Lingo>| -> bool {
true
};

assert_eq!(boxed_fn(lingo), true);
}
}