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<Self, ParseError>
pub fn try_from_str(s: &str) -> Result<Self, ParseError>
A constructor which str slice, parses it and
produces a well-formed Value.
§Examples
use icu::locale::extensions::unicode::Value;
Value::try_from_str("buddhist").expect("Parsing failed.");§alloc Cargo feature
Without the alloc Cargo feature, this only supports parsing
up to two (non-true) subtags, and will return an error for
longer strings.
Sourcepub fn try_from_utf8(code_units: &[u8]) -> Result<Self, ParseError>
pub fn try_from_utf8(code_units: &[u8]) -> Result<Self, 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 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!(v.is_empty());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);Trait Implementations§
Source§impl Display for Value
This trait is implemented for compatibility with fmt!.
To create a string, [Writeable::write_to_string] is usually more efficient.
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 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<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 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§impl TryFrom<&Value> for CollationCaseFirst
impl TryFrom<&Value> for CollationCaseFirst
Source§impl TryFrom<&Value> for CollationNumericOrdering
impl TryFrom<&Value> for CollationNumericOrdering
Source§impl TryFrom<&Value> for CollationType
impl TryFrom<&Value> for CollationType
Source§impl TryFrom<&Value> for CommonVariantType
impl TryFrom<&Value> for CommonVariantType
Source§impl TryFrom<&Value> for CurrencyFormatStyle
impl TryFrom<&Value> for CurrencyFormatStyle
Source§impl TryFrom<&Value> for EmojiPresentationStyle
impl TryFrom<&Value> for EmojiPresentationStyle
Source§impl TryFrom<&Value> for LineBreakStyle
impl TryFrom<&Value> for LineBreakStyle
Source§impl TryFrom<&Value> for LineBreakWordHandling
impl TryFrom<&Value> for LineBreakWordHandling
Source§impl TryFrom<&Value> for MeasurementSystem
impl TryFrom<&Value> for MeasurementSystem
Source§impl TryFrom<&Value> for MeasurementUnitOverride
impl TryFrom<&Value> for MeasurementUnitOverride
Source§impl TryFrom<&Value> for SentenceBreakSupressions
impl TryFrom<&Value> for SentenceBreakSupressions
Source§impl TryFrom<Value> for CurrencyType
impl TryFrom<Value> for CurrencyType
Source§impl TryFrom<Value> for NumberingSystem
impl TryFrom<Value> for NumberingSystem
Source§impl TryFrom<Value> for RegionOverride
impl TryFrom<Value> for RegionOverride
Source§impl TryFrom<Value> for RegionalSubdivision
impl TryFrom<Value> for RegionalSubdivision
Source§impl TryFrom<Value> for TimeZoneShortId
impl TryFrom<Value> for TimeZoneShortId
Source§impl Writeable for Value
impl Writeable for Value
Source§fn write_to<W: Write + ?Sized>(&self, sink: &mut W) -> Result
fn write_to<W: Write + ?Sized>(&self, sink: &mut W) -> Result
write_to_parts, and discards any
Part annotations.Source§fn writeable_length_hint(&self) -> LengthHint
fn writeable_length_hint(&self) -> LengthHint
Source§fn writeable_borrow(&self) -> Option<&str>
fn writeable_borrow(&self) -> Option<&str>
Source§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.