Skip to main content

LimitDetail

Struct LimitDetail 

Source
#[non_exhaustive]
pub struct LimitDetail { /* private fields */ }
Expand description

What an Error::Limit carries: which limit refused the input, the WorkLimit to retry with when an option raises that limit, and a diagnostic for a log.

use rust_j2k::{DecodeOptions, Error, LimitKind, decode, decode_with};

// A file that asks for far more work than its size allows.
let bytes = std::fs::read("image.j2k")?;
let Err(Error::Limit(limit)) = decode(&bytes) else {
    panic!("expected the code-block work bound to refuse this file");
};
assert_eq!(limit.kind(), LimitKind::CodeBlockWork);
match DecodeOptions::default().with_retry(&limit) {
    // An option raises this limit: retry with it raised.
    Some(options) => {
        let image = decode_with(&bytes, &options)?;
        println!("{}x{}", image.width, image.height);
    }
    // No option raises this limit (`limit.kind().is_adjustable()` is
    // false), or the refusal gave no factor: the file is refused
    // whatever the options.
    None => eprintln!("refused: {limit}"),
}

Implementations§

Source§

impl LimitDetail

Source

pub fn kind(&self) -> LimitKind

Which limit refused the input.

Source

pub fn retry_with(&self) -> Option<WorkLimit>

What to set the option that kind names to, for a retry that may admit the input; None when no option raises this limit.

It is the WorkLimit the message names: a Raised factor, or Unlimited for an image past every factor. It is worked out from what the refusal shows, so a retry with it can still be refused, by this limit later in the file or by another limit (see WorkLimit), or fail with another error once past it, such as damage the limit stopped the decode before. It is also None for a packet work refusal that shows no factor, such as one while reading the header.

DecodeOptions::with_retry applies it to the option kind names.

Source

pub fn message(&self) -> &str

The diagnostic, without the limit: prefix that the Error’s Display adds. Do not parse it: kind and retry_with hold its data.

Trait Implementations§

Source§

impl Clone for LimitDetail

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for LimitDetail

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Display for LimitDetail

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

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> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

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.