[][src]Struct harfbuzz_rs::Blob

#[repr(C)]
pub struct Blob<'a> { /* fields omitted */ }

A Blob manages raw data like e.g. file contents. It refers to a slice of bytes that can be either owned by the Blob or not.

It is used to provide access to memory for Face and Font. Typically it contains the raw font data (e.g. an entire font file or font tables). To enable shared usage of its data it uses a reference counting mechanism making the clone operation very cheap as no data is cloned.

Construction

A Blob implements Into for every type that satisfies the AsRef<[u8]> trait such as Vec<u8> and Box<[u8]> so owned blobs can be created easily from standard Rust objects.

You can also create Blobs that contain borrowed data using the constructors Blob::with_bytes and Blob::with_bytes_mut for immutable and mutable access respectively.

Methods

impl<'a> Blob<'a>[src]

pub fn with_bytes(bytes: &'a [u8]) -> Owned<Blob<'a>>[src]

Create a new Blob from the slice bytes. The blob will not own the slice's data.

pub fn with_bytes_mut(bytes: &'a mut [u8]) -> Owned<Blob<'a>>[src]

Create a new Blob from the mutable slice bytes. The blob will not own the slice's data.

pub fn from_file<P: AsRef<Path>>(path: P) -> Result<Shared<Blob<'static>>>[src]

Create a Blob from the contents of the file at path whose contents will be read into memory.

The result will be either a Blob that owns the file's contents or an error that happened while trying to read the file.

This can be a performance problem if the file is very big. If this turns out to be a problem consider mmaping the file or splitting it into smaller chunks before creating a Blob.

pub fn get_data(&self) -> &[u8][src]

Get a slice of the Blob's bytes.

pub fn create_sub_blob(&self, offset: usize, length: usize) -> Shared<Blob<'a>>[src]

Creates an immutable Blob that contains part of the data of the parent Blob. The parent Blob will be immutable after this and the subBlob cannot outlive its parent.

Arguments

  • offset: Byte-offset of sub-blob within parent.
  • length: Length of the sub-blob.

pub fn is_immutable(&self) -> bool[src]

Returns true if the blob is immutable.

HarfBuzz internally uses this value to make sure the blob is not mutated after being shared. In Rust this is not really necessary due to the borrow checker. This method is provided regardless for completeness.

pub fn make_immutable(&mut self)[src]

Makes this blob immutable so the bytes it refers to will never change during its lifetime.

pub fn try_get_mut_data(&mut self) -> Option<&'a mut [u8]>[src]

Try to get a mutable slice of the Blob's bytes, possibly copying them.

This returns None if the blob is immutable or memory allocation failed.

Trait Implementations

impl<'a> HarfbuzzObject for Blob<'a>[src]

type Raw = hb_blob_t

Type of the raw harfbuzz object.

impl<'a> Send for Blob<'a>[src]

impl<'a> Sync for Blob<'a>[src]

impl<'a> AsRef<[u8]> for Blob<'a>[src]

impl<'a> Deref for Blob<'a>[src]

type Target = [u8]

The resulting type after dereferencing.

impl<'a> Debug for Blob<'a>[src]

Blanket Implementations

impl<T, U> Into for T where
    U: From<T>, 
[src]

impl<T> From for T[src]

impl<T, U> TryFrom for T where
    U: Into<T>, 
[src]

type Error = !

🔬 This is a nightly-only experimental API. (try_from)

The type returned in the event of a conversion error.

impl<T> Borrow for T where
    T: ?Sized
[src]

impl<T, U> TryInto for T where
    U: TryFrom<T>, 
[src]

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

🔬 This is a nightly-only experimental API. (try_from)

The type returned in the event of a conversion error.

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> BorrowMut for T where
    T: ?Sized
[src]