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>

source

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.

source

pub fn len(&self) -> usize

The length of the data, in bytes

source

pub fn is_empty(&self) -> bool

true if the data has a length of zero bytes.

source

pub fn split_off(&self, pos: usize) -> Option<FontData<'a>>

Returns self[pos..]

source

pub fn take_up_to(&mut self, pos: usize) -> Option<FontData<'a>>

returns self[..pos], and updates self to = self[pos..];

source

pub fn slice(&self, range: impl RangeBounds<usize>) -> Option<FontData<'a>>

source

pub fn read_at<T: ReadScalar>(&self, offset: usize) -> Result<T, ReadError>

source

pub fn read_with_args<T>( &self, range: Range<usize>, args: &T::Args ) -> Result<T, ReadError>where T: FontReadWithArgs<'a>,

source

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.

source

pub fn read_ref_at<T: FixedSize>( &self, offset: usize ) -> Result<&'a T, ReadError>

source

pub fn read_array<T: FixedSize>( &self, range: Range<usize> ) -> Result<&'a [T], ReadError>

source

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§

source§

impl AsRef<[u8]> for FontData<'_>

source§

fn as_ref(&self) -> &[u8]

Converts this type into a shared reference of the (usually inferred) input type.
source§

impl<'a> Clone for FontData<'a>

source§

fn clone(&self) -> FontData<'a>

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl<'a> Debug for FontData<'a>

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl<'a> Default for FontData<'a>

source§

fn default() -> FontData<'a>

Returns the “default value” for a type. Read more
source§

impl<'a> FontRead<'a> for FontData<'a>

source§

fn read(data: FontData<'a>) -> Result<Self, ReadError>

Read an instace of Self from the provided data, performing validation. Read more
source§

impl<'a> From<&'a [u8]> for FontData<'a>

source§

fn from(src: &'a [u8]) -> FontData<'a>

Converts to this type from the input type.
source§

impl<'a> From<FontData<'a>> for Cow<'a, [u8]>

source§

fn from(src: FontData<'a>) -> Self

Converts to this type from the input type.
source§

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> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> ToOwned for Twhere T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.