Skip to main content

Limits

Struct Limits 

Source
#[non_exhaustive]
pub struct Limits { pub max_width: Option<u32>, pub max_height: Option<u32>, pub max_total_pixels: Option<u64>, pub max_frame_count: Option<u64>, pub max_file_size: Option<u64>, pub max_memory: Option<u64>, }
Expand description

Configuration for decode limits.

All limits are optional; None means unlimited.

§Example

use zenwebp::Limits;

// Start with defaults and customize
let limits = Limits::default()
    .max_dimensions(4096, 4096)
    .max_memory(256 * 1024 * 1024);  // 256 MB

// Or start with no limits for trusted inputs
let unlimited = Limits::none();

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_width: Option<u32>

Maximum image width in pixels.

§max_height: Option<u32>

Maximum image height in pixels.

§max_total_pixels: Option<u64>

Maximum total pixels (width * height). Useful for limiting memory even with odd aspect ratios.

§max_frame_count: Option<u64>

Maximum number of frames in an animation.

§max_file_size: Option<u64>

Maximum input file size in bytes.

§max_memory: Option<u64>

Maximum memory usage in bytes during decoding.

Implementations§

Source§

impl Limits

Source

pub fn none() -> Self

Create limits with no restrictions.

Warning: Only use this for trusted inputs!

Source

pub fn max_dimensions(self, width: u32, height: u32) -> Self

Set maximum dimensions.

Source

pub fn max_total_pixels(self, pixels: u64) -> Self

Set maximum total pixels.

Source

pub fn max_frame_count(self, count: u64) -> Self

Set maximum frame count.

Source

pub fn max_file_size(self, bytes: u64) -> Self

Set maximum file size in bytes.

Source

pub fn max_memory(self, bytes: u64) -> Self

Set maximum memory usage in bytes.

Source

pub fn check_dimensions( &self, width: u32, height: u32, ) -> Result<(), At<DecodeError>>

Check if dimensions are within limits.

Source

pub fn check_frame_count(&self, count: usize) -> Result<(), At<DecodeError>>

Check if frame count is within limits.

Source

pub fn check_file_size(&self, size: u64) -> Result<(), At<DecodeError>>

Check if file size is within limits.

Source

pub fn check_memory(&self, bytes: usize) -> Result<(), At<DecodeError>>

Check if memory usage is within limits.

Trait Implementations§

Source§

impl Clone for Limits

Source§

fn clone(&self) -> Limits

Returns a duplicate 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() -> Self

Default limits suitable for server-side use.

  • Max dimensions: 16384 x 16384 (WebP format max)
  • Max total pixels: 100 megapixels
  • Max frames: 10,000
  • Max file size: 100 MB
  • Max memory: 1 GB
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 StructuralPartialEq for Limits

Auto Trait Implementations§

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, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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.