Struct icu_locale::subtags::Subtag
pub struct Subtag(/* private fields */);
Expand description
A generic subtag.
The subtag has to be an ASCII alphanumerical string no shorter than two characters and no longer than eight.
§Examples
use icu::locale::subtags::Subtag;
let subtag1: Subtag = "Foo".parse()
.expect("Failed to parse a Subtag.");
assert_eq!(subtag1.as_str(), "foo");
Implementations§
§impl Subtag
impl Subtag
pub const fn try_from_str(s: &str) -> Result<Subtag, ParseError>
pub const fn try_from_str(s: &str) -> Result<Subtag, ParseError>
pub const fn try_from_utf8(code_units: &[u8]) -> Result<Subtag, ParseError>
pub const fn try_from_utf8(code_units: &[u8]) -> Result<Subtag, ParseError>
pub const fn try_from_raw(raw: [u8; 8]) -> Result<Subtag, ParseError>
pub const fn try_from_raw(raw: [u8; 8]) -> Result<Subtag, ParseError>
Safely creates a Subtag
from its raw format
as returned by Self::into_raw
. Unlike Self::try_from_utf8
,
this constructor only takes normalized values.
pub const unsafe fn from_raw_unchecked(v: [u8; 8]) -> Subtag
pub const unsafe fn from_raw_unchecked(v: [u8; 8]) -> Subtag
Unsafely creates a Subtag
from its raw format
as returned by Self::into_raw
. Unlike Self::try_from_utf8
,
this constructor only takes normalized values.
§Safety
This function is safe iff Self::try_from_raw
returns an Ok
. This is the case
for inputs that are correctly normalized.
pub const fn into_raw(self) -> [u8; 8]
pub const fn into_raw(self) -> [u8; 8]
Deconstructs into a raw format to be consumed by
from_raw_unchecked
or
try_from_raw
.
pub fn strict_cmp(self, other: &[u8]) -> Ordering
pub fn strict_cmp(self, other: &[u8]) -> Ordering
Compare with BCP-47 bytes.
The return value is equivalent to what would happen if you first converted
self
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.as_str().as_bytes()
.
pub fn normalizing_eq(self, other: &str) -> bool
pub fn normalizing_eq(self, other: &str) -> bool
Compare with a potentially unnormalized BCP-47 string.
The return value is equivalent to what would happen if you first parsed the BCP-47 string and then performed a structural comparison.
Trait Implementations§
§impl Bake for Subtag
impl Bake for Subtag
§fn bake(&self, env: &CrateEnv) -> TokenStream
fn bake(&self, env: &CrateEnv) -> TokenStream
§impl BakeSize for Subtag
impl BakeSize for Subtag
§fn borrows_size(&self) -> usize
fn borrows_size(&self) -> usize
§impl<'de> Deserialize<'de> for Subtag
impl<'de> Deserialize<'de> for Subtag
§fn deserialize<D>(
deserializer: D,
) -> Result<Subtag, <D as Deserializer<'de>>::Error>where
D: Deserializer<'de>,
fn deserialize<D>(
deserializer: D,
) -> Result<Subtag, <D as Deserializer<'de>>::Error>where
D: Deserializer<'de>,
§impl Display for Subtag
impl Display for Subtag
This trait is implemented for compatibility with fmt!
.
To create a string, [Writeable::write_to_string
] is usually more efficient.
§impl Extend<Subtag> for Value
impl Extend<Subtag> for Value
§fn extend<T>(&mut self, iter: T)where
T: IntoIterator<Item = Subtag>,
fn extend<T>(&mut self, iter: T)where
T: IntoIterator<Item = Subtag>,
source§fn extend_one(&mut self, item: A)
fn extend_one(&mut self, item: A)
extend_one
)source§fn extend_reserve(&mut self, additional: usize)
fn extend_reserve(&mut self, additional: usize)
extend_one
)§impl FromIterator<Subtag> for Value
impl FromIterator<Subtag> for Value
§impl NicheBytes<8> for Subtag
impl NicheBytes<8> for Subtag
const NICHE_BIT_PATTERN: [u8; 8] = tinystr::TinyAsciiStr<8>::NICHE_BIT_PATTERN
§impl Ord for Subtag
impl Ord for Subtag
§impl PartialOrd for Subtag
impl PartialOrd for Subtag
§impl Serialize for Subtag
impl Serialize for Subtag
§fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
§impl ULE for Subtag
impl ULE for Subtag
§fn parse_bytes_to_slice(bytes: &[u8]) -> Result<&[Self], UleError>
fn parse_bytes_to_slice(bytes: &[u8]) -> Result<&[Self], UleError>
§unsafe fn slice_from_bytes_unchecked(bytes: &[u8]) -> &[Self]
unsafe fn slice_from_bytes_unchecked(bytes: &[u8]) -> &[Self]
&[u8]
, and return it as &[Self]
with the same lifetime, assuming
that this byte slice has previously been run through [Self::parse_bytes_to_slice()
] with
success. Read more§fn slice_as_bytes(slice: &[Self]) -> &[u8] ⓘ
fn slice_as_bytes(slice: &[Self]) -> &[u8] ⓘ
§impl Writeable for Subtag
impl Writeable for Subtag
§fn write_to<W>(&self, sink: &mut W) -> Result<(), Error>
fn write_to<W>(&self, sink: &mut W) -> Result<(), Error>
write_to_parts
, and discards any
Part
annotations.§fn writeable_length_hint(&self) -> LengthHint
fn writeable_length_hint(&self) -> LengthHint
§fn write_to_string(&self) -> Cow<'_, str>
fn write_to_string(&self) -> Cow<'_, str>
String
with the data from this Writeable
. Like ToString
,
but smaller and faster. Read more§impl<'a> ZeroMapKV<'a> for Subtag
impl<'a> ZeroMapKV<'a> for Subtag
impl Copy for Subtag
impl Eq for Subtag
impl StructuralPartialEq for Subtag
Auto Trait Implementations§
impl Freeze for Subtag
impl RefUnwindSafe for Subtag
impl Send for Subtag
impl Sync for Subtag
impl Unpin for Subtag
impl UnwindSafe for Subtag
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)source§impl<T> IntoEither for T
impl<T> IntoEither for T
source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moresource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more