Struct read_fonts::FontData
source · 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§
source§impl<'a> FontData<'a>
impl<'a> FontData<'a>
sourcepub const fn new(bytes: &'a [u8]) -> Self
pub const fn new(bytes: &'a [u8]) -> Self
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.
sourcepub 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>>
sourcepub fn read_at<T: Scalar>(&self, offset: usize) -> Result<T, ReadError>
pub fn read_at<T: Scalar>(&self, offset: usize) -> Result<T, ReadError>
Read a scalar at the provided location in the data.
sourcepub fn read_be_at<T: Scalar>(
&self,
offset: usize,
) -> Result<BigEndian<T>, ReadError>
pub fn read_be_at<T: Scalar>( &self, offset: usize, ) -> Result<BigEndian<T>, ReadError>
Read a big-endian value at the provided location in the data.
pub fn read_with_args<T>(
&self,
range: Range<usize>,
args: &T::Args,
) -> Result<T, ReadError>where
T: FontReadWithArgs<'a>,
sourcepub fn read_ref_at<T: AnyBitPattern + FixedSize>(
&self,
offset: usize,
) -> Result<&'a T, ReadError>
pub fn read_ref_at<T: AnyBitPattern + FixedSize>( &self, offset: usize, ) -> Result<&'a T, ReadError>
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.
sourcepub fn read_array<T: AnyBitPattern + FixedSize>(
&self,
range: Range<usize>,
) -> Result<&'a [T], ReadError>
pub fn read_array<T: AnyBitPattern + FixedSize>( &self, range: Range<usize>, ) -> Result<&'a [T], ReadError>
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> 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,
source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)