image

Struct Limits

Source
#[non_exhaustive]
pub struct Limits { pub max_image_width: Option<u32>, pub max_image_height: Option<u32>, pub max_alloc: Option<u64>, }
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. Some of the underlying decoders do not support such limits, so one cannot rely on these limits being supported. For strict 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 error::LimitErrorKind::Unsupported.

The only currently supported strict limits are the max_image_width and max_image_height limits, but 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 (Non-exhaustive)§

This struct is marked as non-exhaustive
Non-exhaustive structs could have additional fields added in future. Therefore, non-exhaustive structs cannot be constructed in external crates using the traditional Struct { .. } syntax; cannot be matched against without a wildcard ..; and struct update syntax will not work.
§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 bytes required to store the output image count towards this value. 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 reserve_buffer( &mut self, width: u32, height: u32, color_type: ColorType, ) -> ImageResult<()>

This function acts identically to reserve, but accepts the width, height and color type used to create an ImageBuffer and does all the math for you.

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

Source§

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

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

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

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

Auto Trait Implementations§

§

impl Freeze for Limits

§

impl RefUnwindSafe for Limits

§

impl Send for Limits

§

impl Sync for Limits

§

impl Unpin for Limits

§

impl UnwindSafe for Limits

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dst: *mut T)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. 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> ToOwned for T
where T: Clone,

Source§

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

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.