#[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.as_str(), "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.as_str(), "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.
sourcepub fn strict_cmp(&self, other: &[u8]) -> Ordering
pub fn strict_cmp(&self, other: &[u8]) -> Ordering
Compare this Script
with BCP-47 bytes.
The return value is equivalent to what would happen if you first converted this
Script
to a BCP-47 string and then performed a byte comparison.
This function is case-sensitive and results in a total order, so it is appropriate for
binary search. The only argument producing Ordering::Equal
is self.to_string()
.
sourcepub fn normalizing_eq(&self, other: &str) -> bool
pub fn normalizing_eq(&self, other: &str) -> bool
Compare this Script
with a potentially unnormalized BCP-47 string.
The return value is equivalent to what would happen if you first parsed the
BCP-47 string to a Script
and then performed a structucal comparison.
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 as script, subtags::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 Bake for Script
impl Bake for Script
sourcefn bake(&self, env: &CrateEnv) -> TokenStream
fn bake(&self, env: &CrateEnv) -> TokenStream
Returns a TokenStream
that would evalutate to self
. Read more
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
1.21.0 · sourcefn max(self, other: Self) -> Self
fn max(self, other: Self) -> Self
Compares and returns the maximum of two values. Read more
1.21.0 · sourcefn min(self, other: Self) -> Self
fn min(self, other: Self) -> Self
Compares and returns the minimum of two values. Read more
1.50.0 · sourcefn clamp(self, min: Self, max: Self) -> Self where
Self: PartialOrd<Self>,
fn clamp(self, min: Self, max: Self) -> Self where
Self: PartialOrd<Self>,
Restrict a value to a certain interval. Read more
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 &mut [u8]impl Write for &mut [u8]impl Read for &[u8]
unsafe fn from_byte_slice_unchecked(bytes: &[u8]) -> &[Self]ⓘNotable traits for &mut [u8]impl Write for &mut [u8]impl Read for &[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
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