Struct icu_locid::subtags::Script[][src]

pub struct Script(_);

A script subtag (examples: "Latn", "Arab", etc.)

Script represents a Unicode base language code conformat to the unicode_script_id field of the Language and Locale Identifier.

Examples

use icu::locid::subtags::Script;

let script: Script = "Latn".parse()
    .expect("Failed to parse a script subtag.");

Implementations

impl Script[src]

pub fn from_bytes(v: &[u8]) -> Result<Self, ParserError>[src]

A constructor which takes a utf8 slice, parses it and produces a well-formed Script.

Examples

use icu::locid::subtags::Script;

let script = Script::from_bytes(b"Latn")
    .expect("Parsing failed.");

assert_eq!(script, "Latn");

pub fn into_raw(self) -> u32[src]

Deconstructs the Script into raw format to be consumed by from_raw_unchecked().

Examples

use icu::locid::subtags::Script;

let script = Script::from_bytes(b"Latn")
    .expect("Parsing failed.");

let raw = script.into_raw();
let script = unsafe { Script::from_raw_unchecked(raw) };
assert_eq!(script, "Latn");

pub const unsafe fn from_raw_unchecked(v: u32) -> Self[src]

Constructor which takes a raw value returned by into_raw.

Examples

use icu::locid::subtags::Script;

let script = Script::from_bytes(b"Latn")
    .expect("Parsing failed.");

let raw = script.into_raw();
let script = unsafe { Script::from_raw_unchecked(raw) };
assert_eq!(script, "Latn");

Safety

This function accepts a u32 that is expected to be a valid TinyStr4 representing a Script subtag in canonical syntax.

pub fn as_str(&self) -> &str[src]

A helper function for displaying a Script subtag as a &str.

Examples

use icu::locid::subtags::Script;

let script = Script::from_bytes(b"Latn")
    .expect("Parsing failed.");

assert_eq!(script.as_str(), "Latn");

Notice: For many use cases, such as comparison, Script implements PartialEq<&str> which allows for direct comparisons.

Trait Implementations

impl Clone for Script[src]

impl Copy for Script[src]

impl Debug for Script[src]

impl Display for Script[src]

impl Eq for Script[src]

impl FromStr for Script[src]

type Err = ParserError

The associated error which can be returned from parsing.

impl Hash for Script[src]

impl Ord for Script[src]

impl PartialEq<&'_ str> for Script[src]

impl PartialEq<Script> for Script[src]

impl PartialOrd<Script> for Script[src]

impl StructuralEq for Script[src]

impl StructuralPartialEq for Script[src]

impl Writeable for Script[src]

Auto Trait Implementations

impl RefUnwindSafe for Script

impl Send for Script

impl Sync for Script

impl Unpin for Script

impl UnwindSafe for Script

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T> ToString for T where
    T: Display + ?Sized
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.