#[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
impl Limits
Sourcepub fn none() -> Self
pub fn none() -> Self
Create limits with no restrictions.
Warning: Only use this for trusted inputs!
Sourcepub fn max_dimensions(self, width: u32, height: u32) -> Self
pub fn max_dimensions(self, width: u32, height: u32) -> Self
Set maximum dimensions.
Sourcepub fn max_total_pixels(self, pixels: u64) -> Self
pub fn max_total_pixels(self, pixels: u64) -> Self
Set maximum total pixels.
Sourcepub fn max_frame_count(self, count: u64) -> Self
pub fn max_frame_count(self, count: u64) -> Self
Set maximum frame count.
Sourcepub fn max_file_size(self, bytes: u64) -> Self
pub fn max_file_size(self, bytes: u64) -> Self
Set maximum file size in bytes.
Sourcepub fn max_memory(self, bytes: u64) -> Self
pub fn max_memory(self, bytes: u64) -> Self
Set maximum memory usage in bytes.
Sourcepub fn check_dimensions(
&self,
width: u32,
height: u32,
) -> Result<(), At<DecodeError>>
pub fn check_dimensions( &self, width: u32, height: u32, ) -> Result<(), At<DecodeError>>
Check if dimensions are within limits.
Sourcepub fn check_frame_count(&self, count: usize) -> Result<(), At<DecodeError>>
pub fn check_frame_count(&self, count: usize) -> Result<(), At<DecodeError>>
Check if frame count is within limits.
Sourcepub fn check_file_size(&self, size: u64) -> Result<(), At<DecodeError>>
pub fn check_file_size(&self, size: u64) -> Result<(), At<DecodeError>>
Check if file size is within limits.
Sourcepub fn check_memory(&self, bytes: usize) -> Result<(), At<DecodeError>>
pub fn check_memory(&self, bytes: usize) -> Result<(), At<DecodeError>>
Check if memory usage is within limits.
Trait Implementations§
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 UnsafeUnpin for Limits
impl UnwindSafe for Limits
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more