#[repr(transparent)]pub struct Script(_);
Expand description
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
sourceimpl Script
impl Script
sourcepub const fn from_bytes(v: &[u8]) -> Result<Self, ParserError>
pub const fn from_bytes(v: &[u8]) -> Result<Self, ParserError>
sourcepub const fn from_bytes_manual_slice(
v: &[u8],
start: usize,
end: usize
) -> Result<Self, ParserError>
pub const fn from_bytes_manual_slice(
v: &[u8],
start: usize,
end: usize
) -> Result<Self, ParserError>
Equivalent to from_bytes(bytes[start..end])
,
but callable in a const
context (which range indexing is not).
sourcepub fn try_from_raw(v: [u8; 4]) -> Result<Self, ParserError>
pub fn try_from_raw(v: [u8; 4]) -> Result<Self, ParserError>
Safely creates a Script
from a reference to its raw format
as returned by Script::into_raw()
.
Examples
use icu::locid::subtags::Script;
assert!(matches!(Script::try_from_raw(*b"Latn"), Ok(_)));
assert!(matches!(Script::try_from_raw(*b"Mymr"), Ok(_)));
assert!(matches!(Script::try_from_raw(*b"1234"), Err(_)));
// Unlike the other constructors, this one is case-sensitive:
assert!(matches!(Script::try_from_raw(*b"LATN"), Err(_)));
sourcepub fn into_raw(self) -> [u8; 4]
pub fn into_raw(self) -> [u8; 4]
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");
sourcepub const unsafe fn from_raw_unchecked(v: [u8; 4]) -> Self
pub const unsafe fn from_raw_unchecked(v: [u8; 4]) -> Self
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 [u8; 4] that is expected to be a valid TinyAsciiStr<4>
representing a Script
subtag in canonical syntax.
sourcepub fn as_str(&self) -> &str
pub fn as_str(&self) -> &str
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
sourceimpl AsULE for Script
impl AsULE for Script
Impl enabling Script
to be used in a ZeroVec
. Enabled with the "zerovec"
feature.
Example
use icu::locid::subtags::Script;
use icu::locid::script;
use zerovec::ZeroVec;
let zv = ZeroVec::<Script>::parse_byte_slice(b"LatnAdlmMymrLatnLatn")
.expect("Valid script subtags");
assert_eq!(zv.get(1), Some(script!("Adlm")));
ZeroVec::<Script>::parse_byte_slice(b"invalid")
.expect_err("Invalid byte slice");
sourceimpl<'de> Deserialize<'de> for Script
impl<'de> Deserialize<'de> for Script
sourcefn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where
D: Deserializer<'de>,
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where
D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
sourceimpl From<Script> for TinyAsciiStr<4>
impl From<Script> for TinyAsciiStr<4>
sourceimpl Ord for Script
impl Ord for Script
sourceimpl PartialOrd<Script> for Script
impl PartialOrd<Script> for Script
sourcefn partial_cmp(&self, other: &Script) -> Option<Ordering>
fn partial_cmp(&self, other: &Script) -> Option<Ordering>
This method returns an ordering between self
and other
values if one exists. Read more
1.0.0 · sourcefn lt(&self, other: &Rhs) -> bool
fn lt(&self, other: &Rhs) -> bool
This method tests less than (for self
and other
) and is used by the <
operator. Read more
1.0.0 · sourcefn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
This method tests less than or equal to (for self
and other
) and is used by the <=
operator. Read more
sourceimpl ULE for Script
impl ULE for Script
sourcefn validate_byte_slice(bytes: &[u8]) -> Result<(), ZeroVecError>
fn validate_byte_slice(bytes: &[u8]) -> Result<(), ZeroVecError>
Validates a byte slice, &[u8]
. Read more
sourcefn parse_byte_slice(bytes: &[u8]) -> Result<&[Self], ZeroVecError>
fn parse_byte_slice(bytes: &[u8]) -> Result<&[Self], ZeroVecError>
Parses a byte slice, &[u8]
, and return it as &[Self]
with the same lifetime. Read more
sourceunsafe fn from_byte_slice_unchecked(bytes: &[u8]) -> &[Self]ⓘNotable traits for &'_ [u8]impl<'_> Read for &'_ [u8]impl<'_> Write for &'_ mut [u8]
unsafe fn from_byte_slice_unchecked(bytes: &[u8]) -> &[Self]ⓘNotable traits for &'_ [u8]impl<'_> Read for &'_ [u8]impl<'_> Write for &'_ mut [u8]
Takes a byte slice, &[u8]
, and return it as &[Self]
with the same lifetime, assuming
that this byte slice has previously been run through Self::parse_byte_slice()
with
success. Read more
sourceimpl Writeable for Script
impl Writeable for Script
sourcefn write_to<W: Write + ?Sized>(&self, sink: &mut W) -> Result
fn write_to<W: Write + ?Sized>(&self, sink: &mut W) -> Result
Writes bytes to the given sink. Errors from the sink are bubbled up.
The default implementation delegates to write_to_parts
, and discards any
Part
annotations. Read more
sourcefn write_len(&self) -> LengthHint
fn write_len(&self) -> LengthHint
Returns a hint for the number of bytes that will be written to the sink. Read more
sourcefn 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,
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. Read more
sourcefn write_to_string(&self) -> Cow<'_, str>
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
sourceimpl<'a> ZeroMapKV<'a> for Script
impl<'a> ZeroMapKV<'a> for Script
type Container = ZeroVec<'a, Script>
type Container = ZeroVec<'a, Script>
The container that can be used with this type: ZeroVec
or VarZeroVec
.
impl Copy for Script
impl Eq for Script
impl StructuralEq for Script
impl StructuralPartialEq for Script
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
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<T> ToOwned for T where
T: Clone,
impl<T> ToOwned for T where
T: Clone,
type Owned = T
type Owned = T
The resulting type after obtaining ownership.
sourcefn clone_into(&self, target: &mut T)
fn clone_into(&self, target: &mut T)
toowned_clone_into
)Uses borrowed data to replace owned data, usually by cloning. Read more