Packer

Struct Packer 

Source
pub struct Packer<T> { /* private fields */ }
Expand description

A packer for items of type Item<T>.

Implementations§

Source§

impl<T> Packer<T>

Source

pub const fn new() -> Self

Create a new, empty packer.

Source

pub fn with_capacity(capacity: usize) -> Self

Create a packer with an initial capacity to prevent collection resizing.

Source

pub fn with_items<I: IntoIterator<Item = Item<T>>>(items: I) -> Self

Create a packer initialized with the collection of items.

Source§

impl<T: Clone> Packer<T>

Source

pub fn clear(&mut self) -> &mut Self

Source

pub fn push(&mut self, item: Item<T>) -> &mut Self

Source

pub fn extend<I: IntoIterator<Item = Item<T>>>(&mut self, items: I) -> &mut Self

Source

pub fn pack( &mut self, into_rect: Rect, ) -> Result<Vec<PackedItem<T>>, Vec<PackedItem<T>>>

Attempt to pack all the items into into_rect. The returned Vec<(Rect, T)> will contain positions for all packed items on success, or just the items the packer was able to successfully pack before failing.

This function uses some internal intermediary collections, which is why it is mutable, so it cannot be called but it is valid to call it multiple times with different into_rect values.

If you want to attempt to pack the same item list into several different into_rect, it is valid to call this function multiple times on the same Packer, and it will re-use its intermediary data structures.

Source

pub fn pack_into_po2(&mut self, max_size: usize) -> Result<PackedItems<T>, ()>

Attempts to pack the supplied items into the smallest power of 2 container it possibly can while not exceeding the provided max_size.

On success, returns the size of the container (a power of 2) and the packed items.

Trait Implementations§

Source§

impl<T> Default for Packer<T>

Source§

fn default() -> Self

Default packer, equivalent to Packer::new().

Auto Trait Implementations§

§

impl<T> Freeze for Packer<T>

§

impl<T> RefUnwindSafe for Packer<T>
where T: RefUnwindSafe,

§

impl<T> Send for Packer<T>
where T: Send,

§

impl<T> Sync for Packer<T>
where T: Sync,

§

impl<T> Unpin for Packer<T>
where T: Unpin,

§

impl<T> UnwindSafe for Packer<T>
where T: UnwindSafe,

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<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<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

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>,

Source§

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.