pub struct Lang { /* private fields */ }
Expand description
A language identifier.
Implementations§
source§impl Lang
impl Lang
sourcepub fn iso639(code: &str) -> Result<Lang>
pub fn iso639(code: &str) -> Result<Lang>
Specify a language using an ISO 639-1, -2/T or -2/B code. We know that the same language is sometimes represented by more than one code, and we do our best to treat equivalent codes as the same language.
use substudy::lang::Lang;
assert_eq!(Lang::iso639("en").unwrap(), Lang::iso639("eng").unwrap());
assert!(Lang::iso639("en").unwrap() != Lang::iso639("fr").unwrap());
assert!(Lang::iso639("abcd").is_err());
sourcepub fn as_str(&self) -> &str
pub fn as_str(&self) -> &str
Get the normalized language code as a &str
. Prefers ISO 639-1
codes when possible, and -2/T if that’s the best it can do.
use substudy::lang::Lang;
assert_eq!("en", Lang::iso639("en").unwrap().as_str());
assert_eq!("en", Lang::iso639("eng").unwrap().as_str());
sourcepub fn for_text(text: &str) -> Option<Lang>
pub fn for_text(text: &str) -> Option<Lang>
Try to determine the language of text
. We return None
unless
we’re pretty sure.
use substudy::lang::Lang;
let text = "Pour que le caractère d’un être humain dévoile des qualités";
assert_eq!(Lang::for_text(text).unwrap(), Lang::iso639("fr").unwrap());
sourcepub fn english_names(&self) -> Result<Vec<&'static str>>
pub fn english_names(&self) -> Result<Vec<&'static str>>
Names of the language (or related languages) in English. These may be separated by semi-colons.
use substudy::lang::Lang;
assert_eq!(
vec!["English".to_owned()],
Lang::iso639("en").unwrap().english_names().unwrap(),
);
Trait Implementations§
source§impl PartialEq for Lang
impl PartialEq for Lang
impl Copy for Lang
impl Eq for Lang
impl StructuralPartialEq for Lang
Auto Trait Implementations§
impl Freeze for Lang
impl RefUnwindSafe for Lang
impl Send for Lang
impl Sync for Lang
impl Unpin for Lang
impl UnwindSafe for Lang
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
Compare self to
key
and return true
if they are equal.