Skip to main content

Crate langtag

Crate langtag 

Source
Expand description

This crate provides an implementation of language tags defined by RFC5646 (BCP47).

§Usage

You can easily parse new language from any string:

use langtag::LangTag;

fn main() -> Result<(), langtag::InvalidLangTag<&'static str>> {
  let tag = LangTag::new("fr-FR")?;
  assert_eq!(tag.language().unwrap().primary(), "fr");
  assert!(tag == "Fr-fr"); // comparison is case-insensitive.
  Ok(())
}

Note that LangTag::new does not copy the data it is given, but only borrows it. The LangTagBuf type allows you to own the language tag. Once parsed, you can explore every component of the language tag using the provided functions.

You can use this library with no_std by disabling the std feature, though it will also disable all the *Buf types.

Macros§

langtag
Parses an LangTag at compile time.

Structs§

ExtendedLangTag
Single extended language subtag.
ExtendedLangTagBuf
Owned extendedlangtag.
Extension
Single extension and its subtags.
ExtensionBuf
Owned extension.
ExtensionIter
ExtensionSubtag
Single extension subtag.
ExtensionSubtagBuf
Owned extensionsubtag.
Extensions
List of extensions.
ExtensionsBuf
Owned extensions.
ExtensionsIter
InvalidExtendedLangTag
Invalid extendedlangtag error.
InvalidExtension
Invalid extension error.
InvalidExtensionSubtag
Invalid extensionsubtag error.
InvalidExtensions
Invalid extensions error.
InvalidGrandfatheredTag
InvalidLangTag
Invalid langtag error.
InvalidLanguage
Invalid language error.
InvalidLanguageExtension
Invalid languageextension error.
InvalidNormalLangTag
Invalid normallangtag error.
InvalidPrimaryLanguage
Invalid primarylanguage error.
InvalidPrivateUse
Invalid privateuse error.
InvalidPrivateUseSubtag
Invalid privateusesubtag error.
InvalidRegion
Invalid region error.
InvalidScript
Invalid script error.
InvalidSingleton
InvalidVariant
Invalid variant error.
InvalidVariants
Invalid variants error.
LangTag
Any language tag (normal, private use or grandfathered).
LangTagBuf
Owned langtag.
Language
Primary and extended language subtags.
LanguageBuf
Owned language.
LanguageExtension
List of extended language subtags.
LanguageExtensionBuf
Owned languageextension.
LanguageExtensionIter
NormalLangTag
Normal language tag.
NormalLangTagBuf
Owned normallangtag.
PrimaryLanguage
Primary language subtag.
PrimaryLanguageBuf
Owned primarylanguage.
PrivateUse
Private use.
PrivateUseBuf
Owned privateuse.
PrivateUseIter
PrivateUseSubtag
Private use subtag.
PrivateUseSubtagBuf
Owned privateusesubtag.
Region
Region subtag.
RegionBuf
Owned region.
Script
Script subtag.
ScriptBuf
Owned script.
Singleton
Extension identifier.
Variant
Single variant subtag.
VariantBuf
Owned variant.
Variants
List of variant subtags.
VariantsBuf
Owned variants.
VariantsIter

Enums§

GrandfatheredLangTag
Grandfathered tags.
Kind
Language tag kind (normal, private use or grandfathered).
TypedLangTag
Language tag with type information (normal, private use or grandfathered).

Statics§

GRANDFATHERED
List of all grandfathered tags.

Type Aliases§

PrivateUseLangTag
Private use language tag.
PrivateUseLangTagBuf
Owned private use language tag.