pub struct Tag(/* private fields */);
Expand description
An OpenType tag.
Per the spec, a tag is a 4-byte array where each byte is in the
printable ASCII range (0x20..=0x7E)
.
We do not strictly enforce this constraint as it is possible to encounter invalid tags in existing fonts, and these need to be representable.
When creating new tags we encourage ensuring that the tag is valid,
either by using Tag::new_checked
or by calling Tag::validate
on an
existing tag.
Implementations§
source§impl Tag
impl Tag
sourcepub const fn new(src: &[u8; 4]) -> Tag
pub const fn new(src: &[u8; 4]) -> Tag
Construct a Tag
from raw bytes.
This does not perform any validation; use Tag::new_checked
for a
constructor that validates input.
sourcepub const fn new_checked(src: &[u8]) -> Result<Tag, InvalidTag>
pub const fn new_checked(src: &[u8]) -> Result<Tag, InvalidTag>
Attempt to create a Tag
from raw bytes.
The slice must contain between 1 and 4 bytes, each in the printable
ascii range (0x20..=0x7E
).
If the input has fewer than four bytes, it will be padded with spaces.
This method returns an InvalidTag
error if the tag does conform to
the spec.
sourcepub const fn from_u32(src: u32) -> Tag
pub const fn from_u32(src: u32) -> Tag
Construct a new Tag
from a big-endian u32
, without performing validation.
This is provided as a convenience method for interop with code that stores tags as big-endian u32s.
sourcepub const fn from_be_bytes(bytes: [u8; 4]) -> Tag
pub const fn from_be_bytes(bytes: [u8; 4]) -> Tag
Create a tag from raw big-endian bytes.
Prefer to use Tag::new
(in const contexts) or Tag::new_checked
when creating a Tag
.
This does not check the input, and is only intended to be used during parsing, where invalid inputs are accepted.
sourcepub const fn to_be_bytes(self) -> [u8; 4]
pub const fn to_be_bytes(self) -> [u8; 4]
Return the memory representation of this tag.
sourcepub fn into_bytes(self) -> [u8; 4]
pub fn into_bytes(self) -> [u8; 4]
Return the raw byte array representing this tag.
sourcepub fn validate(self) -> Result<(), InvalidTag>
pub fn validate(self) -> Result<(), InvalidTag>
Check that the tag conforms with the spec.
This is intended for use during things like santization or lint passes
on existing fonts; if you are creating a new tag, you should prefer
Tag::new_checked
.
Specifically, this checks the following conditions
- the tag is not empty
- the tag contains only characters in the printable ascii range (
0x20..=0x1F
) - the tag does not begin with a space
- the tag does not contain any non-space characters after the first space
Trait Implementations§
source§impl Domain for Tag
impl Domain for Tag
source§fn is_continuous() -> bool
fn is_continuous() -> bool
source§fn ordered_values() -> impl DoubleEndedIterator
fn ordered_values() -> impl DoubleEndedIterator
T
Read moresource§fn ordered_values_range(range: RangeInclusive<Tag>) -> impl DoubleEndedIterator
fn ordered_values_range(range: RangeInclusive<Tag>) -> impl DoubleEndedIterator
source§impl Ord for Tag
impl Ord for Tag
source§impl PartialOrd for Tag
impl PartialOrd for Tag
source§impl Scalar for Tag
impl Scalar for Tag
impl AnyBitPattern for Tag
impl Copy for Tag
impl Eq for Tag
impl StructuralPartialEq for Tag
Auto Trait Implementations§
impl Freeze for Tag
impl RefUnwindSafe for Tag
impl Send for Tag
impl Sync for Tag
impl Unpin for Tag
impl UnwindSafe for Tag
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> CheckedBitPattern for Twhere
T: AnyBitPattern,
impl<T> CheckedBitPattern for Twhere
T: AnyBitPattern,
source§type Bits = T
type Bits = T
Self
must have the same layout as the specified Bits
except for
the possible invalid bit patterns being checked during
is_valid_bit_pattern
.source§fn is_valid_bit_pattern(_bits: &T) -> bool
fn is_valid_bit_pattern(_bits: &T) -> bool
bits
as &Self
.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
)