Enum writeable::LengthHint[][src]

pub enum LengthHint {
    Undefined,
    Exact(usize),
}

A hint to help consumers of Writeable pre-allocate bytes before they call write_to.

LengthHint implements std::ops::Add and similar traits for easy composition.

See this issue for more info: https://github.com/unicode-org/icu4x/issues/370.

Variants

Undefined

Default value: no hint is provided.

Exact(usize)

An exact length hint. This value is expected to equal the actual length from write_to.

Implementations

impl LengthHint[src]

pub fn capacity(&self) -> usize[src]

Returns a recommendation for the number of bytes to pre-allocate.

Examples

use writeable::Writeable;

fn pre_allocate_string(w: &impl Writeable) -> String {
    String::with_capacity(w.write_len().capacity())
}

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

Returns whether the LengthHint indicates that the string is exactly 0 bytes long.

Trait Implementations

impl Add<LengthHint> for LengthHint[src]

type Output = Self

The resulting type after applying the + operator.

impl Add<usize> for LengthHint[src]

type Output = Self

The resulting type after applying the + operator.

impl AddAssign<LengthHint> for LengthHint[src]

impl AddAssign<usize> for LengthHint[src]

impl Clone for LengthHint[src]

impl Copy for LengthHint[src]

impl Debug for LengthHint[src]

impl Eq for LengthHint[src]

impl PartialEq<LengthHint> for LengthHint[src]

impl StructuralEq for LengthHint[src]

impl StructuralPartialEq for LengthHint[src]

impl Sum<LengthHint> for LengthHint[src]

impl Sum<usize> for LengthHint[src]

Auto Trait Implementations

Blanket Implementations

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

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

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

impl<T> From<T> for T[src]

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

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

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

type Error = Infallible

The type returned in the event of a conversion error.

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

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

The type returned in the event of a conversion error.