#[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
impl LimitDetail
Sourcepub fn retry_with(&self) -> Option<WorkLimit>
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.