pub struct Value(/* private fields */);
Expand description
A value used in a list of Keywords
.
The value has to be a sequence of one or more alphanumerical strings
separated by -
.
Each part of the sequence has to be no shorter than three characters and no
longer than 8.
§Examples
use icu::locale::extensions::unicode::{value, Value};
use writeable::assert_writeable_eq;
assert_writeable_eq!(value!("gregory"), "gregory");
assert_writeable_eq!(
"islamic-civil".parse::<Value>().unwrap(),
"islamic-civil"
);
// The value "true" has the special, empty string representation
assert_eq!(value!("true").to_string(), "");
Implementations§
source§impl Value
impl Value
sourcepub fn try_from_str(s: &str) -> Result<Value, ParseError>
pub fn try_from_str(s: &str) -> Result<Value, ParseError>
sourcepub fn try_from_utf8(code_units: &[u8]) -> Result<Value, ParseError>
pub fn try_from_utf8(code_units: &[u8]) -> Result<Value, ParseError>
sourcepub const fn as_single_subtag(&self) -> Option<&Subtag>
pub const fn as_single_subtag(&self) -> Option<&Subtag>
Returns a reference to a single Subtag
if the Value
contains exactly one
subtag, or None
otherwise.
§Examples
use core::str::FromStr;
use icu::locale::extensions::unicode::Value;
let value1 = Value::from_str("foo").expect("failed to parse a Value");
let value2 = Value::from_str("foo-bar").expect("failed to parse a Value");
assert!(value1.as_single_subtag().is_some());
assert!(value2.as_single_subtag().is_none());
sourcepub fn into_single_subtag(self) -> Option<Subtag>
pub fn into_single_subtag(self) -> Option<Subtag>
Destructs into a single Subtag
if the Value
contains exactly one
subtag, or returns None
otherwise.
§Examples
use core::str::FromStr;
use icu::locale::extensions::unicode::Value;
let value1 = Value::from_str("foo").expect("failed to parse a Value");
let value2 = Value::from_str("foo-bar").expect("failed to parse a Value");
assert!(value1.into_single_subtag().is_some());
assert!(value2.into_single_subtag().is_none());
sourcepub fn push_subtag(&mut self, subtag: Subtag)
pub fn push_subtag(&mut self, subtag: Subtag)
sourcepub fn subtag_count(&self) -> usize
pub fn subtag_count(&self) -> usize
sourcepub fn is_empty(&self) -> bool
pub fn is_empty(&self) -> bool
Returns true
if the Value has no subtags.
§Examples
use icu::locale::{extensions::unicode::Value, subtags::subtag};
let mut v = Value::default();
assert_eq!(v.is_empty(), true);
sourcepub fn remove_subtag(&mut self, idx: usize) -> Option<Subtag>
pub fn remove_subtag(&mut self, idx: usize) -> Option<Subtag>
Removes and returns the subtag at position index
within the value,
shifting all subtags after it to the left.
§Examples
use icu::locale::{extensions::unicode::Value, subtags::subtag};
let mut v = Value::default();
v.push_subtag(subtag!("foo"));
v.push_subtag(subtag!("bar"));
v.push_subtag(subtag!("baz"));
assert_eq!(v.remove_subtag(1), Some(subtag!("bar")));
assert_eq!(v, "foo-baz");
sourcepub fn get_subtag(&self, idx: usize) -> Option<&Subtag>
pub fn get_subtag(&self, idx: usize) -> Option<&Subtag>
Returns a reference to a subtag at index.
§Examples
use icu::locale::{extensions::unicode::Value, subtags::subtag};
let mut v = Value::default();
v.push_subtag(subtag!("foo"));
v.push_subtag(subtag!("bar"));
v.push_subtag(subtag!("baz"));
assert_eq!(v.get_subtag(1), Some(&subtag!("bar")));
assert_eq!(v.get_subtag(3), None);
sourcepub fn from_vec_unchecked(input: Vec<Subtag>) -> Value
pub fn from_vec_unchecked(input: Vec<Subtag>) -> Value
A constructor which takes a pre-sorted list of Value
elements.
§Examples
use icu::locale::extensions::unicode::Value;
use icu::locale::subtags::subtag;
let subtag1 = subtag!("foobar");
let subtag2 = subtag!("testing");
let mut v = vec![subtag1, subtag2];
v.sort();
v.dedup();
let value = Value::from_vec_unchecked(v);
Notice: For performance- and memory-constrained environments, it is recommended
for the caller to use binary_search
instead of sort
and dedup
.
Trait Implementations§
source§impl Display for Value
impl Display for Value
This trait is implemented for compatibility with fmt!
.
To create a string, [Writeable::write_to_string
] is usually more efficient.
source§impl Extend<Subtag> for Value
impl Extend<Subtag> for Value
source§fn extend<T>(&mut self, iter: T)where
T: IntoIterator<Item = Subtag>,
fn extend<T>(&mut self, iter: T)where
T: IntoIterator<Item = Subtag>,
source§fn extend_one(&mut self, item: A)
fn extend_one(&mut self, item: A)
extend_one
)source§fn extend_reserve(&mut self, additional: usize)
fn extend_reserve(&mut self, additional: usize)
extend_one
)source§impl From<CalendarAlgorithm> for Value
impl From<CalendarAlgorithm> for Value
source§fn from(input: CalendarAlgorithm) -> Value
fn from(input: CalendarAlgorithm) -> Value
source§impl From<CollationCaseFirst> for Value
impl From<CollationCaseFirst> for Value
source§fn from(input: CollationCaseFirst) -> Value
fn from(input: CollationCaseFirst) -> Value
source§impl From<CollationNumericOrdering> for Value
impl From<CollationNumericOrdering> for Value
source§fn from(input: CollationNumericOrdering) -> Value
fn from(input: CollationNumericOrdering) -> Value
source§impl From<CollationType> for Value
impl From<CollationType> for Value
source§fn from(input: CollationType) -> Value
fn from(input: CollationType) -> Value
source§impl From<CommonVariantType> for Value
impl From<CommonVariantType> for Value
source§fn from(input: CommonVariantType) -> Value
fn from(input: CommonVariantType) -> Value
source§impl From<CurrencyFormatStyle> for Value
impl From<CurrencyFormatStyle> for Value
source§fn from(input: CurrencyFormatStyle) -> Value
fn from(input: CurrencyFormatStyle) -> Value
source§impl From<CurrencyType> for Value
impl From<CurrencyType> for Value
source§fn from(input: CurrencyType) -> Value
fn from(input: CurrencyType) -> Value
source§impl From<DictionaryBreakScriptExclusions> for Value
impl From<DictionaryBreakScriptExclusions> for Value
source§fn from(input: DictionaryBreakScriptExclusions) -> Value
fn from(input: DictionaryBreakScriptExclusions) -> Value
source§impl From<EmojiPresentationStyle> for Value
impl From<EmojiPresentationStyle> for Value
source§fn from(input: EmojiPresentationStyle) -> Value
fn from(input: EmojiPresentationStyle) -> Value
source§impl From<LineBreakStyle> for Value
impl From<LineBreakStyle> for Value
source§fn from(input: LineBreakStyle) -> Value
fn from(input: LineBreakStyle) -> Value
source§impl From<LineBreakWordHandling> for Value
impl From<LineBreakWordHandling> for Value
source§fn from(input: LineBreakWordHandling) -> Value
fn from(input: LineBreakWordHandling) -> Value
source§impl From<MeasurementSystem> for Value
impl From<MeasurementSystem> for Value
source§fn from(input: MeasurementSystem) -> Value
fn from(input: MeasurementSystem) -> Value
source§impl From<MeasurementUnitOverride> for Value
impl From<MeasurementUnitOverride> for Value
source§fn from(input: MeasurementUnitOverride) -> Value
fn from(input: MeasurementUnitOverride) -> Value
source§impl From<NumberingSystem> for Value
impl From<NumberingSystem> for Value
source§fn from(input: NumberingSystem) -> Value
fn from(input: NumberingSystem) -> Value
source§impl From<RegionOverride> for Value
impl From<RegionOverride> for Value
source§fn from(input: RegionOverride) -> Value
fn from(input: RegionOverride) -> Value
source§impl From<RegionalSubdivision> for Value
impl From<RegionalSubdivision> for Value
source§fn from(input: RegionalSubdivision) -> Value
fn from(input: RegionalSubdivision) -> Value
source§impl From<SentenceBreakSupressions> for Value
impl From<SentenceBreakSupressions> for Value
source§fn from(input: SentenceBreakSupressions) -> Value
fn from(input: SentenceBreakSupressions) -> Value
source§impl From<TimeZoneShortId> for Value
impl From<TimeZoneShortId> for Value
source§fn from(input: TimeZoneShortId) -> Value
fn from(input: TimeZoneShortId) -> Value
source§impl FromIterator<Subtag> for Value
impl FromIterator<Subtag> for Value
source§impl IntoIterator for Value
impl IntoIterator for Value
source§impl Ord for Value
impl Ord for Value
source§impl PartialOrd for Value
impl PartialOrd for Value
source§impl TryFrom<&Value> for CalendarAlgorithm
impl TryFrom<&Value> for CalendarAlgorithm
source§type Error = PreferencesParseError
type Error = PreferencesParseError
source§fn try_from(
s: &Value,
) -> Result<CalendarAlgorithm, <CalendarAlgorithm as TryFrom<&Value>>::Error>
fn try_from( s: &Value, ) -> Result<CalendarAlgorithm, <CalendarAlgorithm as TryFrom<&Value>>::Error>
source§impl TryFrom<&Value> for CollationCaseFirst
impl TryFrom<&Value> for CollationCaseFirst
source§type Error = PreferencesParseError
type Error = PreferencesParseError
source§fn try_from(
s: &Value,
) -> Result<CollationCaseFirst, <CollationCaseFirst as TryFrom<&Value>>::Error>
fn try_from( s: &Value, ) -> Result<CollationCaseFirst, <CollationCaseFirst as TryFrom<&Value>>::Error>
source§impl TryFrom<&Value> for CollationNumericOrdering
impl TryFrom<&Value> for CollationNumericOrdering
source§type Error = PreferencesParseError
type Error = PreferencesParseError
source§fn try_from(
s: &Value,
) -> Result<CollationNumericOrdering, <CollationNumericOrdering as TryFrom<&Value>>::Error>
fn try_from( s: &Value, ) -> Result<CollationNumericOrdering, <CollationNumericOrdering as TryFrom<&Value>>::Error>
source§impl TryFrom<&Value> for CollationType
impl TryFrom<&Value> for CollationType
source§type Error = PreferencesParseError
type Error = PreferencesParseError
source§fn try_from(
s: &Value,
) -> Result<CollationType, <CollationType as TryFrom<&Value>>::Error>
fn try_from( s: &Value, ) -> Result<CollationType, <CollationType as TryFrom<&Value>>::Error>
source§impl TryFrom<&Value> for CommonVariantType
impl TryFrom<&Value> for CommonVariantType
source§type Error = PreferencesParseError
type Error = PreferencesParseError
source§fn try_from(
s: &Value,
) -> Result<CommonVariantType, <CommonVariantType as TryFrom<&Value>>::Error>
fn try_from( s: &Value, ) -> Result<CommonVariantType, <CommonVariantType as TryFrom<&Value>>::Error>
source§impl TryFrom<&Value> for CurrencyFormatStyle
impl TryFrom<&Value> for CurrencyFormatStyle
source§type Error = PreferencesParseError
type Error = PreferencesParseError
source§fn try_from(
s: &Value,
) -> Result<CurrencyFormatStyle, <CurrencyFormatStyle as TryFrom<&Value>>::Error>
fn try_from( s: &Value, ) -> Result<CurrencyFormatStyle, <CurrencyFormatStyle as TryFrom<&Value>>::Error>
source§impl TryFrom<&Value> for EmojiPresentationStyle
impl TryFrom<&Value> for EmojiPresentationStyle
source§type Error = PreferencesParseError
type Error = PreferencesParseError
source§fn try_from(
s: &Value,
) -> Result<EmojiPresentationStyle, <EmojiPresentationStyle as TryFrom<&Value>>::Error>
fn try_from( s: &Value, ) -> Result<EmojiPresentationStyle, <EmojiPresentationStyle as TryFrom<&Value>>::Error>
source§impl TryFrom<&Value> for LineBreakStyle
impl TryFrom<&Value> for LineBreakStyle
source§type Error = PreferencesParseError
type Error = PreferencesParseError
source§fn try_from(
s: &Value,
) -> Result<LineBreakStyle, <LineBreakStyle as TryFrom<&Value>>::Error>
fn try_from( s: &Value, ) -> Result<LineBreakStyle, <LineBreakStyle as TryFrom<&Value>>::Error>
source§impl TryFrom<&Value> for LineBreakWordHandling
impl TryFrom<&Value> for LineBreakWordHandling
source§type Error = PreferencesParseError
type Error = PreferencesParseError
source§fn try_from(
s: &Value,
) -> Result<LineBreakWordHandling, <LineBreakWordHandling as TryFrom<&Value>>::Error>
fn try_from( s: &Value, ) -> Result<LineBreakWordHandling, <LineBreakWordHandling as TryFrom<&Value>>::Error>
source§impl TryFrom<&Value> for MeasurementSystem
impl TryFrom<&Value> for MeasurementSystem
source§type Error = PreferencesParseError
type Error = PreferencesParseError
source§fn try_from(
s: &Value,
) -> Result<MeasurementSystem, <MeasurementSystem as TryFrom<&Value>>::Error>
fn try_from( s: &Value, ) -> Result<MeasurementSystem, <MeasurementSystem as TryFrom<&Value>>::Error>
source§impl TryFrom<&Value> for MeasurementUnitOverride
impl TryFrom<&Value> for MeasurementUnitOverride
source§type Error = PreferencesParseError
type Error = PreferencesParseError
source§fn try_from(
s: &Value,
) -> Result<MeasurementUnitOverride, <MeasurementUnitOverride as TryFrom<&Value>>::Error>
fn try_from( s: &Value, ) -> Result<MeasurementUnitOverride, <MeasurementUnitOverride as TryFrom<&Value>>::Error>
source§impl TryFrom<&Value> for SentenceBreakSupressions
impl TryFrom<&Value> for SentenceBreakSupressions
source§type Error = PreferencesParseError
type Error = PreferencesParseError
source§fn try_from(
s: &Value,
) -> Result<SentenceBreakSupressions, <SentenceBreakSupressions as TryFrom<&Value>>::Error>
fn try_from( s: &Value, ) -> Result<SentenceBreakSupressions, <SentenceBreakSupressions as TryFrom<&Value>>::Error>
source§impl TryFrom<Value> for CurrencyType
impl TryFrom<Value> for CurrencyType
source§type Error = PreferencesParseError
type Error = PreferencesParseError
source§fn try_from(
input: Value,
) -> Result<CurrencyType, <CurrencyType as TryFrom<Value>>::Error>
fn try_from( input: Value, ) -> Result<CurrencyType, <CurrencyType as TryFrom<Value>>::Error>
source§impl TryFrom<Value> for DictionaryBreakScriptExclusions
impl TryFrom<Value> for DictionaryBreakScriptExclusions
source§type Error = PreferencesParseError
type Error = PreferencesParseError
source§fn try_from(
input: Value,
) -> Result<DictionaryBreakScriptExclusions, <DictionaryBreakScriptExclusions as TryFrom<Value>>::Error>
fn try_from( input: Value, ) -> Result<DictionaryBreakScriptExclusions, <DictionaryBreakScriptExclusions as TryFrom<Value>>::Error>
source§impl TryFrom<Value> for NumberingSystem
impl TryFrom<Value> for NumberingSystem
source§type Error = PreferencesParseError
type Error = PreferencesParseError
source§fn try_from(
input: Value,
) -> Result<NumberingSystem, <NumberingSystem as TryFrom<Value>>::Error>
fn try_from( input: Value, ) -> Result<NumberingSystem, <NumberingSystem as TryFrom<Value>>::Error>
source§impl TryFrom<Value> for RegionOverride
impl TryFrom<Value> for RegionOverride
source§type Error = PreferencesParseError
type Error = PreferencesParseError
source§fn try_from(
input: Value,
) -> Result<RegionOverride, <RegionOverride as TryFrom<Value>>::Error>
fn try_from( input: Value, ) -> Result<RegionOverride, <RegionOverride as TryFrom<Value>>::Error>
source§impl TryFrom<Value> for RegionalSubdivision
impl TryFrom<Value> for RegionalSubdivision
source§type Error = PreferencesParseError
type Error = PreferencesParseError
source§fn try_from(
input: Value,
) -> Result<RegionalSubdivision, <RegionalSubdivision as TryFrom<Value>>::Error>
fn try_from( input: Value, ) -> Result<RegionalSubdivision, <RegionalSubdivision as TryFrom<Value>>::Error>
source§impl TryFrom<Value> for TimeZoneShortId
impl TryFrom<Value> for TimeZoneShortId
source§type Error = PreferencesParseError
type Error = PreferencesParseError
source§fn try_from(
input: Value,
) -> Result<TimeZoneShortId, <TimeZoneShortId as TryFrom<Value>>::Error>
fn try_from( input: Value, ) -> Result<TimeZoneShortId, <TimeZoneShortId as TryFrom<Value>>::Error>
source§impl Writeable for Value
impl Writeable for Value
source§fn write_to<W>(&self, sink: &mut W) -> Result<(), Error>
fn write_to<W>(&self, sink: &mut W) -> Result<(), Error>
write_to_parts
, and discards any
Part
annotations.source§fn writeable_length_hint(&self) -> LengthHint
fn writeable_length_hint(&self) -> LengthHint
source§fn write_to_string(&self) -> Cow<'_, str>
fn write_to_string(&self) -> Cow<'_, str>
String
with the data from this Writeable
. Like ToString
,
but smaller and faster. Read moresource§fn write_to_parts<S>(&self, sink: &mut S) -> Result<(), Error>where
S: PartsWrite + ?Sized,
fn write_to_parts<S>(&self, sink: &mut S) -> Result<(), Error>where
S: PartsWrite + ?Sized,
Part
annotations to the given sink. Errors from the
sink are bubbled up. The default implementation delegates to write_to
,
and doesn’t produce any Part
annotations.impl Eq for Value
impl StructuralPartialEq for Value
Auto Trait Implementations§
impl Freeze for Value
impl RefUnwindSafe for Value
impl Send for Value
impl Sync for Value
impl Unpin for Value
impl UnwindSafe for Value
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§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)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 more