Struct Fields

struct Fields(_)

A list of Key-Value pairs representing functional information about content transformations.

Here are examples of fields used in Unicode:

You can find the full list in Unicode BCP 47 T Extension section of LDML.

Examples

use icu::locale::extensions::transform::{key, Fields, Value};

let value = "hybrid".parse::<Value>().expect("Failed to parse a Value.");
let fields = [(key!("h0"), value)].into_iter().collect::<Fields>();

assert_eq!(&fields.to_string(), "h0-hybrid");

Implementations

impl Fields

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 Fields

const fn new() -> Self

Returns a new empty list of key-value pairs. Same as default(), but is const.

Examples

use icu::locale::extensions::transform::Fields;

assert_eq!(Fields::new(), Fields::default());
fn is_empty(self: &Self) -> bool

Returns true if there are no fields.

Examples

use icu::locale::locale;
use icu::locale::Locale;

let loc1 = Locale::try_from_str("und-t-h0-hybrid").unwrap();
let loc2 = locale!("und-u-ca-buddhist");

assert!(!loc1.extensions.transform.fields.is_empty());
assert!(loc2.extensions.transform.fields.is_empty());
fn clear(self: &mut Self) -> Self

Empties the Fields list.

Returns the old list.

Examples

use icu::locale::extensions::transform::{key, Fields, Value};

let value = "hybrid".parse::<Value>().expect("Failed to parse a Value.");
let mut fields = [(key!("h0"), value)].into_iter().collect::<Fields>();

assert_eq!(&fields.to_string(), "h0-hybrid");

fields.clear();

assert_eq!(fields, Fields::new());
fn contains_key<Q>(self: &Self, key: &Q) -> bool
where
    Key: Borrow<Q>,
    Q: Ord

Returns true if the list contains a Value for the specified Key.

Examples

use icu::locale::extensions::transform::{Fields, Key, Value};

let key: Key = "h0".parse().expect("Failed to parse a Key.");
let value: Value = "hybrid".parse().expect("Failed to parse a Value.");
let mut fields = [(key, value)].into_iter().collect::<Fields>();

let key: Key = "h0".parse().expect("Failed to parse a Key.");
assert!(&fields.contains_key(&key));
fn get<Q>(self: &Self, key: &Q) -> Option<&Value>
where
    Key: Borrow<Q>,
    Q: Ord

Returns a reference to the Value corresponding to the Key.

Examples

use icu::locale::extensions::transform::{key, Fields, Value};

let value = "hybrid".parse::<Value>().unwrap();
let fields = [(key!("h0"), value.clone())]
    .into_iter()
    .collect::<Fields>();

assert_eq!(fields.get(&key!("h0")), Some(&value));
fn set(self: &mut Self, key: Key, value: Value) -> Option<Value>

Sets the specified keyword, returning the old value if it already existed.

Examples

use icu::locale::extensions::transform::{key, Value};
use icu::locale::Locale;

let lower = "lower".parse::<Value>().expect("valid extension subtag");
let casefold = "casefold".parse::<Value>().expect("valid extension subtag");

let mut loc: Locale = "en-t-hi-d0-casefold"
    .parse()
    .expect("valid BCP-47 identifier");
let old_value = loc.extensions.transform.fields.set(key!("d0"), lower);

assert_eq!(old_value, Some(casefold));
assert_eq!(loc, "en-t-hi-d0-lower".parse().unwrap());
fn retain_by_key<F>(self: &mut Self, predicate: F)
where
    F: FnMut(&Key) -> bool

Retains a subset of fields as specified by the predicate function.

Examples

use icu::locale::extensions::transform::key;
use icu::locale::Locale;

let mut loc: Locale = "und-t-h0-hybrid-d0-hex-m0-xml".parse().unwrap();

loc.extensions
    .transform
    .fields
    .retain_by_key(|&k| k == key!("h0"));
assert_eq!(loc, "und-t-h0-hybrid".parse().unwrap());

loc.extensions
    .transform
    .fields
    .retain_by_key(|&k| k == key!("d0"));
assert_eq!(loc, Locale::UNKNOWN);

impl Clone for Fields

fn clone(self: &Self) -> Fields

impl Debug for Fields

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

impl Default for Fields

fn default() -> Fields

impl Display for Fields

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

impl Eq for Fields

impl Freeze for Fields

impl From for Fields

fn from(map: LiteMap<Key, Value>) -> Self

impl FromIterator for Fields

fn from_iter<I: IntoIterator<Item = (Key, Value)>>(iter: I) -> Self

impl Hash for Fields

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

impl Ord for Fields

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

impl PartialEq for Fields

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

impl PartialOrd for Fields

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

impl RefUnwindSafe for Fields

impl Send for Fields

impl StructuralPartialEq for Fields

impl Sync for Fields

impl Unpin for Fields

impl UnsafeUnpin for Fields

impl UnwindSafe for Fields

impl Writeable for Fields

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 Fields

fn type_id(self: &Self) -> TypeId

impl<T> Borrow for Fields

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

impl<T> BorrowMut for Fields

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

impl<T> CloneToUninit for Fields

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

impl<T> ErasedDestructor for Fields

impl<T> From for Fields

fn from(t: T) -> T

Returns the argument unchanged.

impl<T> ToOwned for Fields

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

impl<T> ToString for Fields

fn to_string(self: &Self) -> String

impl<T, U> Into for Fields

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 Fields

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

impl<T, U> TryInto for Fields

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