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
impl Limits
sourcepub fn check_support(&self, _supported: &LimitSupport) -> ImageResult<()>
pub fn check_support(&self, _supported: &LimitSupport) -> ImageResult<()>
This function checks that all currently set strict limits are supported.
sourcepub fn check_dimensions(&self, width: u32, height: u32) -> ImageResult<()>
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.
sourcepub fn reserve(&mut self, amount: u64) -> ImageResult<()>
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.
sourcepub fn reserve_usize(&mut self, amount: usize) -> ImageResult<()>
pub fn reserve_usize(&mut self, amount: usize) -> ImageResult<()>
This function acts identically to [reserve
], but takes a usize
for convenience.
sourcepub fn reserve_buffer(
&mut self,
width: u32,
height: u32,
color_type: ColorType,
) -> ImageResult<()>
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.
sourcepub fn free(&mut self, amount: u64)
pub fn free(&mut self, amount: u64)
This function increases the max_alloc
limit with amount. Should only be used
together with reserve
.
sourcepub fn free_usize(&mut self, amount: usize)
pub fn free_usize(&mut self, amount: usize)
This function acts identically to [free
], but takes a usize
for convenience.
Trait Implementations§
source§impl PartialEq for Limits
impl PartialEq for Limits
impl Eq for Limits
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> 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
source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§default unsafe fn clone_to_uninit(&self, dst: *mut T)
default unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)