pub struct LanguageMap(/* private fields */);Expand description
A dictionary where the key is an RFC 5646 Language Tag, and the value is a string in the language indicated by the tag. This map is supposed to be populated as fully as possible.
IMPLEMENTATION NOTE - This implementation uses a B-Tree based natural
language ordered map (BTreeMap), in preference to a HashMap b/c it
seems to be faster when deserializing, as well easier when finding
correct candidate for a language-tag w/ a country variant; for example
deciding on the appropriate label when the dictionary contains entries for
en-US, en, and en-AU.
§Requirements for Canonical format
xAPI requirements for producing resources that have a LanguageMap
property when canonical format is specified state:
- Activity objects —more specifically their ActivityDefinition
parts— contain LanguageMap objects within their
name,descriptionand various InteractionComponents. The LRS shall return only one language in each of these maps. - The LRS may maintain canonical versions of language maps against any
IRI identifying an object containing language maps. This includes the
language map stored in the Verb’s
displayproperty and potentially some language maps used within extensions. - The LRS may maintain a canonical version of any language map and return
this when
canonicalformat is used to retrieve Statements. The LRS shall return only one language within each language map for which it returns a canonical map. - In order to choose the most relevant language, the LRS shall apply the
Accept-Languageheader as described in RFC-2616, except that this logic shall be applied to each language map individually to select which language entry to include, rather than to the resource (list of Statements) as a whole.
Implementations§
Source§impl LanguageMap
impl LanguageMap
Sourcepub fn new() -> Self
pub fn new() -> Self
Create an empty LanguageMap instance.
Sourcepub fn get(&self, k: &MyLanguageTag) -> Option<&str>
pub fn get(&self, k: &MyLanguageTag) -> Option<&str>
Return a reference to the label keyed by k if it exists, or None
otherwise.
Sourcepub fn append(&mut self, other: &mut Self)
pub fn append(&mut self, other: &mut Self)
Move all elements from other into self, leaving other empty.
Sourcepub fn insert(&mut self, k: &MyLanguageTag, v: &str) -> Option<String>
pub fn insert(&mut self, k: &MyLanguageTag, v: &str) -> Option<String>
Insert v keyed by k and return the previous v if k was already
known, or None otherwise.
Sourcepub fn keys(&self) -> Keys<'_, MyLanguageTag, String>
pub fn keys(&self) -> Keys<'_, MyLanguageTag, String>
Return an iterator over this dictionary’s keys.
Sourcepub fn contains_key(&self, k: &MyLanguageTag) -> bool
pub fn contains_key(&self, k: &MyLanguageTag) -> bool
Return TRUE if k is a known key of this dictionary; FALSE otherwise.
Trait Implementations§
Source§impl Canonical for LanguageMap
impl Canonical for LanguageMap
Source§fn canonicalize(&mut self, tags: &[MyLanguageTag])
fn canonicalize(&mut self, tags: &[MyLanguageTag])
self to conform to its canonical format as defined in xAPI
keeping the most appropriate entry given a list of preferred language
tags.Source§impl Clone for LanguageMap
impl Clone for LanguageMap
Source§fn clone(&self) -> LanguageMap
fn clone(&self) -> LanguageMap
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for LanguageMap
impl Debug for LanguageMap
Source§impl Default for LanguageMap
impl Default for LanguageMap
Source§fn default() -> LanguageMap
fn default() -> LanguageMap
Source§impl<'de> Deserialize<'de> for LanguageMap
impl<'de> Deserialize<'de> for LanguageMap
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Source§impl Display for LanguageMap
impl Display for LanguageMap
Source§impl MultiLingual for LanguageMap
impl MultiLingual for LanguageMap
Source§fn add_label(
&mut self,
tag: &MyLanguageTag,
label: &str,
) -> Result<&mut Self, DataError>
fn add_label( &mut self, tag: &MyLanguageTag, label: &str, ) -> Result<&mut Self, DataError>
self (a
LanguageMap) a label string in a given language tag. Read moreSource§impl PartialEq for LanguageMap
impl PartialEq for LanguageMap
Source§fn eq(&self, other: &LanguageMap) -> bool
fn eq(&self, other: &LanguageMap) -> bool
self and other values to be equal, and is used by ==.Source§impl Serialize for LanguageMap
impl Serialize for LanguageMap
impl Eq for LanguageMap
impl StructuralPartialEq for LanguageMap
Auto Trait Implementations§
impl Freeze for LanguageMap
impl RefUnwindSafe for LanguageMap
impl Send for LanguageMap
impl Sync for LanguageMap
impl Unpin for LanguageMap
impl UnsafeUnpin for LanguageMap
impl UnwindSafe for LanguageMap
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> ToStringFallible for Twhere
T: Display,
impl<T> ToStringFallible for Twhere
T: Display,
Source§fn try_to_string(&self) -> Result<String, TryReserveError>
fn try_to_string(&self) -> Result<String, TryReserveError>
ToString::to_string, but without panic on OOM.