Struct Limits
#[non_exhaustive]pub struct Limits {
pub max_image_width: Option<u32>,
pub max_image_height: Option<u32>,
pub max_alloc: Option<u64>,
}
dep_image
only.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
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§
§impl Limits
impl Limits
pub fn check_support(&self, _supported: &LimitSupport) -> Result<(), ImageError> ⓘ
pub fn check_support(&self, _supported: &LimitSupport) -> Result<(), ImageError> ⓘ
This function checks that all currently set strict limits are supported.
pub fn check_dimensions(
&self,
width: u32,
height: u32,
) -> Result<(), ImageError> ⓘ
pub fn check_dimensions( &self, width: u32, height: u32, ) -> Result<(), ImageError> ⓘ
This function checks the max_image_width
and max_image_height
limits given
the image width and height.
pub fn reserve(&mut self, amount: u64) -> Result<(), ImageError> ⓘ
pub fn reserve(&mut self, amount: u64) -> Result<(), ImageError> ⓘ
This function checks that the current limit allows for reserving the set amount of bytes, it then reduces the limit accordingly.
pub fn reserve_usize(&mut self, amount: usize) -> Result<(), ImageError> ⓘ
pub fn reserve_usize(&mut self, amount: usize) -> Result<(), ImageError> ⓘ
This function acts identically to reserve
, but takes a usize
for convenience.
pub fn reserve_buffer(
&mut self,
width: u32,
height: u32,
color_type: ColorType,
) -> Result<(), ImageError> ⓘ
pub fn reserve_buffer( &mut self, width: u32, height: u32, color_type: ColorType, ) -> Result<(), ImageError> ⓘ
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.
pub 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
.
pub 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§
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> ByteSized for T
impl<T> ByteSized for T
Source§const BYTE_ALIGN: usize = _
const BYTE_ALIGN: usize = _
Source§fn byte_align(&self) -> usize
fn byte_align(&self) -> usize
Source§fn ptr_size_ratio(&self) -> [usize; 2]
fn ptr_size_ratio(&self) -> [usize; 2]
Source§impl<T, R> Chain<R> for Twhere
T: ?Sized,
impl<T, R> Chain<R> for Twhere
T: ?Sized,
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key
and return true
if they are equal.Source§impl<T> ExtAny for T
impl<T> ExtAny for T
Source§fn type_hash_with<H: Hasher>(&self, hasher: H) -> u64
fn type_hash_with<H: Hasher>(&self, hasher: H) -> u64
TypeId
of Self
using a custom hasher.Source§fn as_any_mut(&mut self) -> &mut dyn Anywhere
Self: Sized,
fn as_any_mut(&mut self) -> &mut dyn Anywhere
Self: Sized,
Source§impl<T> ExtMem for Twhere
T: ?Sized,
impl<T> ExtMem for Twhere
T: ?Sized,
Source§const NEEDS_DROP: bool = _
const NEEDS_DROP: bool = _
Source§fn mem_align_of<T>() -> usize
fn mem_align_of<T>() -> usize
Source§fn mem_align_of_val(&self) -> usize
fn mem_align_of_val(&self) -> usize
Source§fn mem_size_of<T>() -> usize
fn mem_size_of<T>() -> usize
Source§fn mem_size_of_val(&self) -> usize
fn mem_size_of_val(&self) -> usize
Source§fn mem_needs_drop(&self) -> bool
fn mem_needs_drop(&self) -> bool
true
if dropping values of this type matters. Read moreSource§fn mem_forget(self)where
Self: Sized,
fn mem_forget(self)where
Self: Sized,
self
without running its destructor. Read moreSource§fn mem_replace(&mut self, other: Self) -> Selfwhere
Self: Sized,
fn mem_replace(&mut self, other: Self) -> Selfwhere
Self: Sized,
Source§unsafe fn mem_zeroed<T>() -> T
unsafe fn mem_zeroed<T>() -> T
unsafe_layout
only.T
represented by the all-zero byte-pattern. Read moreSource§unsafe fn mem_transmute_copy<Src, Dst>(src: &Src) -> Dst
unsafe fn mem_transmute_copy<Src, Dst>(src: &Src) -> Dst
unsafe_layout
only.T
represented by the all-zero byte-pattern. Read moreSource§fn mem_as_bytes(&self) -> &[u8] ⓘ
fn mem_as_bytes(&self) -> &[u8] ⓘ
unsafe_slice
only.§impl<S> FromSample<S> for S
impl<S> FromSample<S> for S
fn from_sample_(s: S) -> S
Source§impl<T> Hook for T
impl<T> Hook for T
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more