Struct icu_locid::extensions::private::Subtag
source · pub struct Subtag(/* private fields */);
Expand description
A single item used in a list of Private
extensions.
The subtag has to be an ASCII alphanumerical string no shorter than one character and no longer than eight.
§Examples
use icu::locid::extensions::private::Subtag;
let subtag1: Subtag = "Foo".parse().expect("Failed to parse a Subtag.");
assert_eq!(subtag1.as_str(), "foo");
Implementations§
source§impl Subtag
impl Subtag
sourcepub const fn try_from_bytes(v: &[u8]) -> Result<Self, ParserError>
pub const fn try_from_bytes(v: &[u8]) -> Result<Self, ParserError>
sourcepub const fn try_from_bytes_manual_slice(
v: &[u8],
start: usize,
end: usize,
) -> Result<Self, ParserError>
pub const fn try_from_bytes_manual_slice( v: &[u8], start: usize, end: usize, ) -> Result<Self, ParserError>
Equivalent to try_from_bytes(bytes[start..end])
,
but callable in a const
context (which range indexing is not).
sourcepub const fn try_from_raw(v: [u8; 8]) -> Result<Self, ParserError>
pub const fn try_from_raw(v: [u8; 8]) -> Result<Self, ParserError>
Safely creates a Subtag
from its raw format
as returned by Self::into_raw
. Unlike Self::try_from_bytes
,
this constructor only takes normalized values.
sourcepub const unsafe fn from_raw_unchecked(v: [u8; 8]) -> Self
pub const unsafe fn from_raw_unchecked(v: [u8; 8]) -> Self
Unsafely creates a Subtag
from its raw format
as returned by Self::into_raw
. Unlike Self::try_from_bytes
,
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.
sourcepub 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
.
sourcepub 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()
.
sourcepub 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§
source§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.
source§impl From<Subtag> for TinyAsciiStr<8>
impl From<Subtag> for TinyAsciiStr<8>
source§impl Ord for Subtag
impl Ord for Subtag
source§impl PartialEq for Subtag
impl PartialEq for Subtag
source§impl PartialOrd for Subtag
impl PartialOrd for Subtag
1.0.0 · source§fn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
self
and other
) and is used by the <=
operator. Read moresource§impl ULE for Subtag
impl ULE for Subtag
source§fn validate_byte_slice(bytes: &[u8]) -> Result<(), ZeroVecError>
fn validate_byte_slice(bytes: &[u8]) -> Result<(), ZeroVecError>
&[u8]
. Read moresource§fn parse_byte_slice(bytes: &[u8]) -> Result<&[Self], ZeroVecError>
fn parse_byte_slice(bytes: &[u8]) -> Result<&[Self], ZeroVecError>
source§unsafe fn from_byte_slice_unchecked(bytes: &[u8]) -> &[Self]
unsafe fn from_byte_slice_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_byte_slice()
with
success. Read moresource§impl Writeable for Subtag
impl Writeable for Subtag
source§fn write_to<W: Write + ?Sized>(&self, sink: &mut W) -> Result
fn write_to<W: Write + ?Sized>(&self, sink: &mut W) -> Result
write_to_parts
, and discards any
Part
annotations.source§fn writeable_length_hint(&self) -> LengthHint
fn writeable_length_hint(&self) -> LengthHint
source§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 moresource§fn 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,
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.source§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: Copy,
impl<T> CloneToUninit for Twhere
T: Copy,
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> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§default unsafe fn clone_to_uninit(&self, dst: *mut T)
default unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)