Struct Value

struct Value(_)

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

impl Value

fn to_string(self: &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.

impl Value

const fn as_single_subtag(self: &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());
fn into_single_subtag(self: 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());
fn subtag_count(self: &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);
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());
fn is_empty(self: &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);
fn remove_subtag(self: &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");
fn get_subtag(self: &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);

impl Clone for Value

fn clone(self: &Self) -> Value

impl Debug for Value

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

impl Default for Value

fn default() -> Value

impl Display for Value

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

impl Eq for Value

impl Freeze for Value

impl From for Value

fn from(input: RegionOverride) -> Value

impl From for Value

fn from(input: RegionalSubdivision) -> Value

impl From for Value

fn from(input: TimeZoneShortId) -> Value

impl From for Value

fn from(input: CurrencyType) -> Value

impl From for Value

fn from(input: NumberingSystem) -> Value

impl Hash for Value

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

impl IntoIterator for Value

fn into_iter(self: Self) -> <Self as >::IntoIter

impl Ord for Value

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

impl PartialEq for Value

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

impl PartialEq for Value

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

impl PartialOrd for Value

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

impl RefUnwindSafe for Value

impl Send for Value

impl StructuralPartialEq for Value

impl Sync for Value

impl Unpin for Value

impl UnsafeUnpin for Value

impl UnwindSafe for Value

impl Writeable for Value

fn write_to<W: core::fmt::Write + ?Sized>(self: &Self, sink: &mut W) -> Result
fn writeable_length_hint(self: &Self) -> LengthHint

impl<T> Any for Value

fn type_id(self: &Self) -> TypeId

impl<T> Borrow for Value

fn borrow(self: &Self) -> &T

impl<T> BorrowMut for Value

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

impl<T> CloneToUninit for Value

unsafe fn clone_to_uninit(self: &Self, dest: *mut u8)

impl<T> ErasedDestructor for Value

impl<T> From for Value

fn from(t: T) -> T

Returns the argument unchanged.

impl<T> ToOwned for Value

fn to_owned(self: &Self) -> T
fn clone_into(self: &Self, target: &mut T)

impl<T> ToString for Value

fn to_string(self: &Self) -> String

impl<T, U> Into for Value

fn into(self: Self) -> U

Calls U::from(self).

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

impl<T, U> TryFrom for Value

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

impl<T, U> TryInto for Value

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