Struct FontData
pub struct FontData<'a> { /* private fields */ }Expand description
A reference to raw binary font data.
This is a wrapper around a byte slice, that provides convenience methods for parsing and validating that data.
Implementations§
§impl<'a> FontData<'a>
impl<'a> FontData<'a>
pub const fn new(bytes: &'a [u8]) -> FontData<'a>
pub const fn new(bytes: &'a [u8]) -> FontData<'a>
Create a new FontData with these bytes.
You generally don’t need to do this? It is handled for you when loading data from disk, but may be useful in tests.
pub fn take_up_to(&mut self, pos: usize) -> Option<FontData<'a>>
pub fn take_up_to(&mut self, pos: usize) -> Option<FontData<'a>>
returns self[..pos], and updates self to = self[pos..];
pub fn slice(&self, range: impl RangeBounds<usize>) -> Option<FontData<'a>>
pub fn read_at<T>(&self, offset: usize) -> Result<T, ReadError>where
T: Scalar,
pub fn read_at<T>(&self, offset: usize) -> Result<T, ReadError>where
T: Scalar,
Read a scalar at the provided location in the data.
pub fn read_be_at<T>(&self, offset: usize) -> Result<BigEndian<T>, ReadError>where
T: Scalar,
pub fn read_be_at<T>(&self, offset: usize) -> Result<BigEndian<T>, ReadError>where
T: Scalar,
Read a big-endian value at the provided location in the data.
pub fn read_with_args<T>(
&self,
range: Range<usize>,
args: &<T as ReadArgs>::Args,
) -> Result<T, ReadError>where
T: FontReadWithArgs<'a>,
pub fn read_ref_at<T>(&self, offset: usize) -> Result<&'a T, ReadError>where
T: AnyBitPattern + FixedSize,
pub fn read_ref_at<T>(&self, offset: usize) -> Result<&'a T, ReadError>where
T: AnyBitPattern + FixedSize,
Interpret the bytes at the provided offset as a reference to T.
Returns an error if the slice offset.. is shorter than T::RAW_BYTE_LEN.
This is a wrapper around read_ref_unchecked, which panics if
the type does not uphold the required invariants.
§Panics
This function will panic if T is zero-sized, has an alignment
other than one, or has any internal padding.
pub fn read_array<T>(&self, range: Range<usize>) -> Result<&'a [T], ReadError>where
T: AnyBitPattern + FixedSize,
pub fn read_array<T>(&self, range: Range<usize>) -> Result<&'a [T], ReadError>where
T: AnyBitPattern + FixedSize,
Interpret the bytes at the provided offset as a slice of T.
Returns an error if range is out of bounds for the underlying data,
or if the length of the range is not a multiple of T::RAW_BYTE_LEN.
This is a wrapper around read_array_unchecked, which panics if
the type does not uphold the required invariants.
§Panics
This function will panic if T is zero-sized, has an alignment
other than one, or has any internal padding.
Trait Implementations§
impl<'a> Copy for FontData<'a>
Auto Trait Implementations§
impl<'a> Freeze for FontData<'a>
impl<'a> RefUnwindSafe for FontData<'a>
impl<'a> Send for FontData<'a>
impl<'a> Sync for FontData<'a>
impl<'a> Unpin for FontData<'a>
impl<'a> UnsafeUnpin for FontData<'a>
impl<'a> UnwindSafe for FontData<'a>
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,
§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can
then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be
further downcast into Rc<ConcreteType> where ConcreteType implements Trait.§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.§impl<T> DowncastSync for T
impl<T> DowncastSync for T
§impl<'a, T> FontReadWithArgs<'a> for Twhere
T: FontRead<'a>,
impl<'a, T> FontReadWithArgs<'a> for Twhere
T: FontRead<'a>,
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
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§impl<T> NoneValue for Twhere
T: Default,
impl<T> NoneValue for Twhere
T: Default,
type NoneType = T
§fn null_value() -> T
fn null_value() -> T
§impl<T> Pointable for T
impl<T> Pointable for T
§impl<F, T, S> SimdInto<T, S> for Fwhere
T: SimdFrom<F, S>,
S: Simd,
impl<F, T, S> SimdInto<T, S> for Fwhere
T: SimdFrom<F, S>,
S: Simd,
Source§impl<T> ToHex for T
impl<T> ToHex for T
Source§fn encode_hex<U>(&self) -> Uwhere
U: FromIterator<char>,
fn encode_hex<U>(&self) -> Uwhere
U: FromIterator<char>,
self into the result. Lower case
letters are used (e.g. f9b4ca)Source§fn encode_hex_upper<U>(&self) -> Uwhere
U: FromIterator<char>,
fn encode_hex_upper<U>(&self) -> Uwhere
U: FromIterator<char>,
self into the result. Upper case
letters are used (e.g. F9B4CA)