Struct icu_locale_core::extensions::unicode::Value

source ·
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

source

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.");
source

pub fn try_from_utf8(code_units: &[u8]) -> Result<Self, ParseError>

source

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());
source

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());
source

pub fn push_subtag(&mut self, subtag: Subtag)

Appends a subtag to the back of a Value.

§Examples
use icu::locale::{extensions::unicode::Value, subtags::subtag};

let mut v = Value::default();
v.push_subtag(subtag!("foo"));
v.push_subtag(subtag!("bar"));
assert_eq!(v, "foo-bar");
source

pub fn subtag_count(&self) -> usize

Returns the number of subtags in the Value.

§Examples
use icu::locale::{extensions::unicode::Value, subtags::subtag};

let mut v = Value::default();
assert_eq!(v.subtag_count(), 0);
v.push_subtag(subtag!("foo"));
assert_eq!(v.subtag_count(), 1);
source

pub const fn new_empty() -> Self

Creates an empty Value, which corresponds to a “true” value.

§Examples
use icu::locale::extensions::unicode::{value, Value};

assert_eq!(value!("true"), Value::new_empty());
source

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);
source

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");
source

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);
source

pub fn from_vec_unchecked(input: Vec<Subtag>) -> Self

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.

source§

impl Value

source

pub fn to_string(&self) -> String

Converts the given value to a String.

Under the hood, this uses an efficient [Writeable] implementation. However, in order to avoid allocating a string, it is more efficient to use [Writeable] directly.

Trait Implementations§

source§

impl Clone for Value

source§

fn clone(&self) -> Value

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Debug for Value

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl Default for Value

source§

fn default() -> Value

Returns the “default value” for a type. Read more
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.

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl Extend<Subtag> for Value

source§

fn extend<T: IntoIterator<Item = Subtag>>(&mut self, iter: T)

Extends a collection with the contents of an iterator. Read more
source§

fn extend_one(&mut self, item: A)

🔬This is a nightly-only experimental API. (extend_one)
Extends a collection with exactly one element.
source§

fn extend_reserve(&mut self, additional: usize)

🔬This is a nightly-only experimental API. (extend_one)
Reserves capacity in a collection for the given number of additional elements. Read more
source§

impl From<CalendarAlgorithm> for Value

source§

fn from(input: CalendarAlgorithm) -> Value

Converts to this type from the input type.
source§

impl From<CollationCaseFirst> for Value

source§

fn from(input: CollationCaseFirst) -> Value

Converts to this type from the input type.
source§

impl From<CollationNumericOrdering> for Value

source§

fn from(input: CollationNumericOrdering) -> Value

Converts to this type from the input type.
source§

impl From<CollationType> for Value

source§

fn from(input: CollationType) -> Value

Converts to this type from the input type.
source§

impl From<CommonVariantType> for Value

source§

fn from(input: CommonVariantType) -> Value

Converts to this type from the input type.
source§

impl From<CurrencyFormatStyle> for Value

source§

fn from(input: CurrencyFormatStyle) -> Value

Converts to this type from the input type.
source§

impl From<CurrencyType> for Value

source§

fn from(input: CurrencyType) -> Value

Converts to this type from the input type.
source§

impl From<DictionaryBreakScriptExclusions> for Value

source§

fn from(input: DictionaryBreakScriptExclusions) -> Value

Converts to this type from the input type.
source§

impl From<EmojiPresentationStyle> for Value

source§

fn from(input: EmojiPresentationStyle) -> Value

Converts to this type from the input type.
source§

impl From<FirstDay> for Value

source§

fn from(input: FirstDay) -> Value

Converts to this type from the input type.
source§

impl From<HourCycle> for Value

source§

fn from(input: HourCycle) -> Value

Converts to this type from the input type.
source§

impl From<LineBreakStyle> for Value

source§

fn from(input: LineBreakStyle) -> Value

Converts to this type from the input type.
source§

impl From<LineBreakWordHandling> for Value

source§

fn from(input: LineBreakWordHandling) -> Value

Converts to this type from the input type.
source§

impl From<MeasurementSystem> for Value

source§

fn from(input: MeasurementSystem) -> Value

Converts to this type from the input type.
source§

impl From<MeasurementUnitOverride> for Value

source§

fn from(input: MeasurementUnitOverride) -> Value

Converts to this type from the input type.
source§

impl From<NumberingSystem> for Value

source§

fn from(input: NumberingSystem) -> Value

Converts to this type from the input type.
source§

impl From<RegionOverride> for Value

source§

fn from(input: RegionOverride) -> Value

Converts to this type from the input type.
source§

impl From<RegionalSubdivision> for Value

source§

fn from(input: RegionalSubdivision) -> Value

Converts to this type from the input type.
source§

impl From<SentenceBreakSupressions> for Value

source§

fn from(input: SentenceBreakSupressions) -> Value

Converts to this type from the input type.
source§

impl From<TimeZoneShortId> for Value

source§

fn from(input: TimeZoneShortId) -> Value

Converts to this type from the input type.
source§

impl FromIterator<Subtag> for Value

source§

fn from_iter<T: IntoIterator<Item = Subtag>>(iter: T) -> Self

Creates a value from an iterator. Read more
source§

impl FromStr for Value

source§

type Err = ParseError

The associated error which can be returned from parsing.
source§

fn from_str(s: &str) -> Result<Self, Self::Err>

Parses a string s to return a value of this type. Read more
source§

impl Hash for Value

source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
source§

impl IntoIterator for Value

source§

type Item = Subtag

The type of the elements being iterated over.
source§

type IntoIter = ShortBoxSliceIntoIter<Subtag>

Which kind of iterator are we turning this into?
source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more
source§

impl Ord for Value

source§

fn cmp(&self, other: &Value) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 · source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 · source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 · source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized + PartialOrd,

Restrict a value to a certain interval. Read more
source§

impl PartialEq<&str> for Value

source§

fn eq(&self, other: &&str) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl PartialEq for Value

source§

fn eq(&self, other: &Value) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl PartialOrd for Value

source§

fn partial_cmp(&self, other: &Value) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · source§

fn lt(&self, other: &Rhs) -> bool

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · source§

fn le(&self, other: &Rhs) -> bool

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · source§

fn gt(&self, other: &Rhs) -> bool

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · source§

fn ge(&self, other: &Rhs) -> bool

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
source§

impl TryFrom<&Value> for CalendarAlgorithm

source§

type Error = PreferencesParseError

The type returned in the event of a conversion error.
source§

fn try_from(s: &Value) -> Result<Self, Self::Error>

Performs the conversion.
source§

impl TryFrom<&Value> for CollationCaseFirst

source§

type Error = PreferencesParseError

The type returned in the event of a conversion error.
source§

fn try_from(s: &Value) -> Result<Self, Self::Error>

Performs the conversion.
source§

impl TryFrom<&Value> for CollationNumericOrdering

source§

type Error = PreferencesParseError

The type returned in the event of a conversion error.
source§

fn try_from(s: &Value) -> Result<Self, Self::Error>

Performs the conversion.
source§

impl TryFrom<&Value> for CollationType

source§

type Error = PreferencesParseError

The type returned in the event of a conversion error.
source§

fn try_from(s: &Value) -> Result<Self, Self::Error>

Performs the conversion.
source§

impl TryFrom<&Value> for CommonVariantType

source§

type Error = PreferencesParseError

The type returned in the event of a conversion error.
source§

fn try_from(s: &Value) -> Result<Self, Self::Error>

Performs the conversion.
source§

impl TryFrom<&Value> for CurrencyFormatStyle

source§

type Error = PreferencesParseError

The type returned in the event of a conversion error.
source§

fn try_from(s: &Value) -> Result<Self, Self::Error>

Performs the conversion.
source§

impl TryFrom<&Value> for EmojiPresentationStyle

source§

type Error = PreferencesParseError

The type returned in the event of a conversion error.
source§

fn try_from(s: &Value) -> Result<Self, Self::Error>

Performs the conversion.
source§

impl TryFrom<&Value> for FirstDay

source§

type Error = PreferencesParseError

The type returned in the event of a conversion error.
source§

fn try_from(s: &Value) -> Result<Self, Self::Error>

Performs the conversion.
source§

impl TryFrom<&Value> for HourCycle

source§

type Error = PreferencesParseError

The type returned in the event of a conversion error.
source§

fn try_from(s: &Value) -> Result<Self, Self::Error>

Performs the conversion.
source§

impl TryFrom<&Value> for LineBreakStyle

source§

type Error = PreferencesParseError

The type returned in the event of a conversion error.
source§

fn try_from(s: &Value) -> Result<Self, Self::Error>

Performs the conversion.
source§

impl TryFrom<&Value> for LineBreakWordHandling

source§

type Error = PreferencesParseError

The type returned in the event of a conversion error.
source§

fn try_from(s: &Value) -> Result<Self, Self::Error>

Performs the conversion.
source§

impl TryFrom<&Value> for MeasurementSystem

source§

type Error = PreferencesParseError

The type returned in the event of a conversion error.
source§

fn try_from(s: &Value) -> Result<Self, Self::Error>

Performs the conversion.
source§

impl TryFrom<&Value> for MeasurementUnitOverride

source§

type Error = PreferencesParseError

The type returned in the event of a conversion error.
source§

fn try_from(s: &Value) -> Result<Self, Self::Error>

Performs the conversion.
source§

impl TryFrom<&Value> for SentenceBreakSupressions

source§

type Error = PreferencesParseError

The type returned in the event of a conversion error.
source§

fn try_from(s: &Value) -> Result<Self, Self::Error>

Performs the conversion.
source§

impl TryFrom<Value> for CurrencyType

source§

type Error = PreferencesParseError

The type returned in the event of a conversion error.
source§

fn try_from(input: Value) -> Result<Self, Self::Error>

Performs the conversion.
source§

impl TryFrom<Value> for DictionaryBreakScriptExclusions

source§

type Error = PreferencesParseError

The type returned in the event of a conversion error.
source§

fn try_from(input: Value) -> Result<Self, Self::Error>

Performs the conversion.
source§

impl TryFrom<Value> for NumberingSystem

source§

type Error = PreferencesParseError

The type returned in the event of a conversion error.
source§

fn try_from(input: Value) -> Result<Self, Self::Error>

Performs the conversion.
source§

impl TryFrom<Value> for RegionOverride

source§

type Error = PreferencesParseError

The type returned in the event of a conversion error.
source§

fn try_from(input: Value) -> Result<Self, Self::Error>

Performs the conversion.
source§

impl TryFrom<Value> for RegionalSubdivision

source§

type Error = PreferencesParseError

The type returned in the event of a conversion error.
source§

fn try_from(input: Value) -> Result<Self, Self::Error>

Performs the conversion.
source§

impl TryFrom<Value> for TimeZoneShortId

source§

type Error = PreferencesParseError

The type returned in the event of a conversion error.
source§

fn try_from(input: Value) -> Result<Self, Self::Error>

Performs the conversion.
source§

impl Writeable for Value

source§

fn write_to<W: Write + ?Sized>(&self, sink: &mut W) -> Result

Writes a string to the given sink. Errors from the sink are bubbled up. The default implementation delegates to write_to_parts, and discards any Part annotations.
source§

fn writeable_length_hint(&self) -> LengthHint

Returns a hint for the number of UTF-8 bytes that will be written to the sink. Read more
source§

fn write_to_string(&self) -> Cow<'_, str>

Creates a new String with the data from this Writeable. Like ToString, but smaller and faster. Read more
§

fn write_to_parts<S>(&self, sink: &mut S) -> Result<(), Error>
where S: PartsWrite + ?Sized,

Write bytes and 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.
source§

impl Eq for Value

source§

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> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> CloneToUninit for T
where T: Clone,

source§

unsafe fn clone_to_uninit(&self, dst: *mut T)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> IntoEither for T

source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
source§

impl<T> ToOwned for T
where T: Clone,

source§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T> ToString for T
where T: Display + ?Sized,

source§

default fn to_string(&self) -> String

Converts the given value to a String. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

source§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<T> ErasedDestructor for T
where T: 'static,