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 langauge-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
,description
and 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
display
property and potentially some language maps used within extensions. - The LRS may maintain a canonical version of any language map and return
this when
canonical
format 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-Language
header 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 · Source§const fn clone_from(&mut self, source: &Self)
const 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§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 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<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
key
and return true
if they are equal.Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
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> IntoCollection<T> for T
impl<T> IntoCollection<T> for T
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> Paint for Twhere
T: ?Sized,
impl<T> Paint for Twhere
T: ?Sized,
Source§fn fg(&self, value: Color) -> Painted<&T>
fn fg(&self, value: Color) -> Painted<&T>
Returns a styled value derived from self
with the foreground set to
value
.
This method should be used rarely. Instead, prefer to use color-specific
builder methods like red()
and
green()
, which have the same functionality but are
pithier.
§Example
Set foreground color to white using fg()
:
use yansi::{Paint, Color};
painted.fg(Color::White);
Set foreground color to white using white()
.
use yansi::Paint;
painted.white();
Source§fn bright_black(&self) -> Painted<&T>
fn bright_black(&self) -> Painted<&T>
Source§fn bright_red(&self) -> Painted<&T>
fn bright_red(&self) -> Painted<&T>
Source§fn bright_green(&self) -> Painted<&T>
fn bright_green(&self) -> Painted<&T>
Source§fn bright_yellow(&self) -> Painted<&T>
fn bright_yellow(&self) -> Painted<&T>
Source§fn bright_blue(&self) -> Painted<&T>
fn bright_blue(&self) -> Painted<&T>
Source§fn bright_magenta(&self) -> Painted<&T>
fn bright_magenta(&self) -> Painted<&T>
Source§fn bright_cyan(&self) -> Painted<&T>
fn bright_cyan(&self) -> Painted<&T>
Source§fn bright_white(&self) -> Painted<&T>
fn bright_white(&self) -> Painted<&T>
Source§fn bg(&self, value: Color) -> Painted<&T>
fn bg(&self, value: Color) -> Painted<&T>
Returns a styled value derived from self
with the background set to
value
.
This method should be used rarely. Instead, prefer to use color-specific
builder methods like on_red()
and
on_green()
, which have the same functionality but
are pithier.
§Example
Set background color to red using fg()
:
use yansi::{Paint, Color};
painted.bg(Color::Red);
Set background color to red using on_red()
.
use yansi::Paint;
painted.on_red();
Source§fn on_primary(&self) -> Painted<&T>
fn on_primary(&self) -> Painted<&T>
Source§fn on_magenta(&self) -> Painted<&T>
fn on_magenta(&self) -> Painted<&T>
Source§fn on_bright_black(&self) -> Painted<&T>
fn on_bright_black(&self) -> Painted<&T>
Source§fn on_bright_red(&self) -> Painted<&T>
fn on_bright_red(&self) -> Painted<&T>
Source§fn on_bright_green(&self) -> Painted<&T>
fn on_bright_green(&self) -> Painted<&T>
Source§fn on_bright_yellow(&self) -> Painted<&T>
fn on_bright_yellow(&self) -> Painted<&T>
Source§fn on_bright_blue(&self) -> Painted<&T>
fn on_bright_blue(&self) -> Painted<&T>
Source§fn on_bright_magenta(&self) -> Painted<&T>
fn on_bright_magenta(&self) -> Painted<&T>
Source§fn on_bright_cyan(&self) -> Painted<&T>
fn on_bright_cyan(&self) -> Painted<&T>
Source§fn on_bright_white(&self) -> Painted<&T>
fn on_bright_white(&self) -> Painted<&T>
Source§fn attr(&self, value: Attribute) -> Painted<&T>
fn attr(&self, value: Attribute) -> Painted<&T>
Enables the styling Attribute
value
.
This method should be used rarely. Instead, prefer to use
attribute-specific builder methods like bold()
and
underline()
, which have the same functionality
but are pithier.
§Example
Make text bold using attr()
:
use yansi::{Paint, Attribute};
painted.attr(Attribute::Bold);
Make text bold using using bold()
.
use yansi::Paint;
painted.bold();
Source§fn rapid_blink(&self) -> Painted<&T>
fn rapid_blink(&self) -> Painted<&T>
Source§fn quirk(&self, value: Quirk) -> Painted<&T>
fn quirk(&self, value: Quirk) -> Painted<&T>
Enables the yansi
Quirk
value
.
This method should be used rarely. Instead, prefer to use quirk-specific
builder methods like mask()
and
wrap()
, which have the same functionality but are
pithier.
§Example
Enable wrapping using .quirk()
:
use yansi::{Paint, Quirk};
painted.quirk(Quirk::Wrap);
Enable wrapping using wrap()
.
use yansi::Paint;
painted.wrap();
Source§fn clear(&self) -> Painted<&T>
👎Deprecated since 1.0.1: renamed to resetting()
due to conflicts with Vec::clear()
.
The clear()
method will be removed in a future release.
fn clear(&self) -> Painted<&T>
resetting()
due to conflicts with Vec::clear()
.
The clear()
method will be removed in a future release.Source§fn whenever(&self, value: Condition) -> Painted<&T>
fn whenever(&self, value: Condition) -> Painted<&T>
Conditionally enable styling based on whether the Condition
value
applies. Replaces any previous condition.
See the crate level docs for more details.
§Example
Enable styling painted
only when both stdout
and stderr
are TTYs:
use yansi::{Paint, Condition};
painted.red().on_yellow().whenever(Condition::STDOUTERR_ARE_TTY);
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.