Struct image::io::Limits

source ·
pub struct Limits {
    pub max_image_width: Option<u32>,
    pub max_image_height: Option<u32>,
    pub max_alloc: Option<u64>,
    /* private fields */
}
Expand description

Resource limits for decoding.

Limits can be either strict or non-strict. Non-strict limits are best-effort limits where the library does not guarantee that limit will not be exceeded. Do note that it is still considered a bug if a non-strict limit is exceeded, however as some of the underlying decoders do not support not support such limits one cannot rely on these limits being supported. For stric limits the library makes a stronger guarantee that the limit will not be exceeded. Exceeding a strict limit is considered a critical bug. If a decoder cannot guarantee that it will uphold a strict limit it must fail with image::error::LimitErrorKind::Unsupported.

Currently the only strict limits supported are the max_image_width and max_image_height limits, however more will be added in the future. LimitSupport will default to support being false and decoders should enable support for the limits they support in ImageDecoder::set_limits.

The limit check should only ever fail if a limit will be exceeded or an unsupported strict limit is used.

Fields§

§max_image_width: Option<u32>

The maximum allowed image width. This limit is strict. The default is no limit.

§max_image_height: Option<u32>

The maximum allowed image height. This limit is strict. The default is no limit.

§max_alloc: Option<u64>

The maximum allowed sum of allocations allocated by the decoder at any one time excluding allocator overhead. This limit is non-strict by default and some decoders may ignore it. The default is 512MiB.

Implementations§

source§

impl Limits

source

pub fn no_limits() -> Limits

Disable all limits.

source

pub fn check_support(&self, _supported: &LimitSupport) -> ImageResult<()>

This function checks that all currently set strict limits are supported.

source

pub fn check_dimensions(&self, width: u32, height: u32) -> ImageResult<()>

This function checks the max_image_width and max_image_height limits given the image width and height.

source

pub fn reserve(&mut self, amount: u64) -> ImageResult<()>

This function checks that the current limit allows for reserving the set amount of bytes, it then reduces the limit accordingly.

source

pub fn reserve_usize(&mut self, amount: usize) -> ImageResult<()>

This function acts identically to [reserve], but takes a usize for convenience.

source

pub fn free(&mut self, amount: u64)

This function increases the max_alloc limit with amount. Should only be used together with reserve.

source

pub fn free_usize(&mut self, amount: usize)

This function acts identically to [free], but takes a usize for convenience.

Trait Implementations§

source§

impl Clone for Limits

source§

fn clone(&self) -> Limits

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 Debug for Limits

source§

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

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

impl Default for Limits

source§

fn default() -> Limits

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

impl Hash for Limits

source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · source§

fn hash_slice<H>(data: &[Self], state: &mut H)where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
source§

impl PartialEq<Limits> for Limits

source§

fn eq(&self, other: &Limits) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl Eq for Limits

source§

impl StructuralEq for Limits

source§

impl StructuralPartialEq for Limits

Auto Trait Implementations§

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.