Struct Limits
#[non_exhaustive]
pub struct Limits { pub max_image_width: Option<u32>, pub max_image_height: Option<u32>, pub max_alloc: Option<u64> }
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
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
fn no_limits() -> LimitsDisable all limits.
fn check_support(&self, _supported: &LimitSupport) -> ImageResult<()>This function checks that all currently set strict limits are supported.
fn check_dimensions(&self, width: u32, height: u32) -> ImageResult<()>This function checks the
max_image_widthandmax_image_heightlimits given the image width and height.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.
fn reserve_usize(&mut self, amount: usize) -> ImageResult<()>This function acts identically to
reserve, but takes ausizefor convenience.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 anImageBufferand does all the math for you.fn free(&mut self, amount: u64)This function increases the
max_alloclimit with amount. Should only be used together withreserve.fn free_usize(&mut self, amount: usize)This function acts identically to
free, but takes ausizefor convenience.
Trait Implementations
impl Clone for Limits
fn clone(&self) -> Self
impl Debug for Limits
fn fmt(&self, f: &mut Formatter<'_>) -> Result
impl Default for Limits
fn default() -> Limits
impl Eq for Limits
impl Hash for Limits
fn hash<__H: Hasher>(&self, state: &mut __H)
impl PartialEq for Limits
fn eq(&self, other: &Self) -> bool
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
impl<R, P> ReadPrimitive<R> for Limits
where
R: Read + ReadEndian<P>,
P: Default,
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for Limits
where
ST: ?Sized,
DT: ?Sized,
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for Limits
where
ST: ?Sized,
DT: ?Sized,
impl<T> Any for Limits
where
T: 'static + ?Sized,
fn type_id(&self) -> TypeId
impl<T> Borrow<T> for Limits
where
T: ?Sized,
fn borrow(&self) -> &T
impl<T> BorrowMut<T> for Limits
where
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
impl<T> CloneToUninit for Limits
where
T: Clone,
unsafe fn clone_to_uninit(&self, dest: *mut u8)
impl<T> From<T> for Limits
fn from(t: T) -> TReturns the argument unchanged.
impl<T> IntoEither for Limits
impl<T> Pointable for Limits
const ALIGN: usize = _;type Init = T;unsafe fn init(init: <T as Pointable>::Init) -> usizeunsafe fn deref<'a>(ptr: usize) -> &'a Tunsafe fn deref_mut<'a>(ptr: usize) -> &'a mut Tunsafe fn drop(ptr: usize)
impl<T> Read<Exclusive, BecauseExclusive> for Limits
where
T: ?Sized,
impl<T> ToOwned for Limits
where
T: Clone,
type Owned = T;fn to_owned(&self) -> Tfn clone_into(&self, target: &mut T)
impl<T, U> Into<U> for Limits
where
U: From<T>,
fn into(self) -> UCalls
U::from(self).That is, this conversion is whatever the implementation of
[From]<T> for Uchooses to do.
impl<T, U> TryFrom<U> for Limits
where
U: Into<T>,
type Error = never;fn try_from(value: U) -> Result<T, never>
impl<T, U> TryInto<U> for Limits
where
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error;fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>