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 EMPTY: FontData<'static> = _

Empty data, useful for some tests and examples

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: Scalar>(&self, offset: usize) -> Result<T, ReadError>

Read a scalar at the provided location in the data.

source

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.

source

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

source

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.

source

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.

source

pub fn as_bytes(&self) -> &'a [u8]

Return the data as a byte slice

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

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

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

source§

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

Mutably borrows from an owned value. Read more
source§

impl<'a, T> FontReadWithArgs<'a> for T
where T: FontRead<'a>,

source§

fn read_with_args( data: FontData<'a>, _: &<T as ReadArgs>::Args ) -> Result<T, ReadError>

read an item, using the provided args. 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 T
where 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<'a, T> ReadArgs for T
where T: FontRead<'a>,

§

type Args = ()

source§

impl<T> ToOwned for T
where 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 T
where 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 T
where 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.