pub struct Attribute(_);
Expand description
An attribute used in a set of Attributes
.
An attribute has to be a sequence of alphanumerical characters no shorter than three and no longer than eight characters.
Examples
use icu::locid::extensions::unicode::Attribute;
use icu::locid::extensions_unicode_attribute as attribute;
let attr: Attribute =
"buddhist".parse().expect("Failed to parse an Attribute.");
assert_eq!(attr, attribute!("buddhist"));
Implementations§
source§impl Attribute
impl Attribute
sourcepub const fn try_from_bytes(v: &[u8]) -> Result<Attribute, ParserError>
pub const fn try_from_bytes(v: &[u8]) -> Result<Attribute, ParserError>
sourcepub const fn try_from_bytes_manual_slice(
v: &[u8],
start: usize,
end: usize
) -> Result<Attribute, ParserError>
pub const fn try_from_bytes_manual_slice( v: &[u8], start: usize, end: usize ) -> Result<Attribute, 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<Attribute, ParserError>
pub const fn try_from_raw(v: [u8; 8]) -> Result<Attribute, ParserError>
Safely creates a Attribute
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]) -> Attribute
pub const unsafe fn from_raw_unchecked(v: [u8; 8]) -> Attribute
Unsafely creates a Attribute
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<'de> Deserialize<'de> for Attribute
impl<'de> Deserialize<'de> for Attribute
source§fn deserialize<D>(
deserializer: D
) -> Result<Attribute, <D as Deserializer<'de>>::Error>where
D: Deserializer<'de>,
fn deserialize<D>( deserializer: D ) -> Result<Attribute, <D as Deserializer<'de>>::Error>where D: Deserializer<'de>,
source§impl Display for Attribute
impl Display for Attribute
This trait is implemented for compatibility with fmt!
.
To create a string, [Writeable::write_to_string
] is usually more efficient.
source§impl Ord for Attribute
impl Ord for Attribute
source§impl PartialEq<Attribute> for Attribute
impl PartialEq<Attribute> for Attribute
source§impl PartialOrd<Attribute> for Attribute
impl PartialOrd<Attribute> for Attribute
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 Serialize for Attribute
impl Serialize for Attribute
source§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,
source§impl ULE for Attribute
impl ULE for Attribute
source§fn validate_byte_slice(bytes: &[u8]) -> Result<(), ZeroVecError>
fn validate_byte_slice(bytes: &[u8]) -> Result<(), ZeroVecError>
&[u8]
. Read more§fn parse_byte_slice(bytes: &[u8]) -> Result<&[Self], ZeroVecError>
fn parse_byte_slice(bytes: &[u8]) -> Result<&[Self], ZeroVecError>
§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 Attribute
impl Writeable for Attribute
source§fn write_to<W>(&self, sink: &mut W) -> Result<(), Error>where
W: Write + ?Sized,
fn write_to<W>(&self, sink: &mut W) -> Result<(), Error>where W: Write + ?Sized,
write_to_parts
, and discards any
Part
annotations.