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>>
pub fn read_at<T: ReadScalar>(&self, offset: usize) -> Result<T, ReadError>
pub fn read_with_args<T>( &self, range: Range<usize>, args: &T::Args ) -> Result<T, ReadError>where T: FontReadWithArgs<'a>,
sourcepub unsafe fn read_at_unchecked<T: ReadScalar>(&self, offset: usize) -> T
pub unsafe fn read_at_unchecked<T: ReadScalar>(&self, offset: usize) -> T
Read a scalar value out of the buffer at offset, elliding bounds checks
Safety
The range offset..offset + T::RAW_BYTE_LEN must be in bounds.
pub fn read_ref_at<T: FixedSize>( &self, offset: usize ) -> Result<&'a T, ReadError>
pub fn read_array<T: FixedSize>( &self, range: Range<usize> ) -> Result<&'a [T], ReadError>
sourcepub unsafe fn read_array_unchecked<T: FixedSize>(
&self,
range: Range<usize>
) -> &'a [T]
pub unsafe fn read_array_unchecked<T: FixedSize>( &self, range: Range<usize> ) -> &'a [T]
Interpret the bytes at offset as a reference to some type T.
Safety
T must be a struct or scalar that has alignment of 1, a non-zero size,
and no internal padding, and range must have a length that is non-zero
and is a multiple of size_of::<T>().
Trait Implementations§
impl<'a> Copy for FontData<'a>
Auto Trait Implementations§
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
Mutably borrows from an owned value. Read more