use alloc::collections::TryReserveError;
use super::FastPacketError;
use crate::JpegError;
mod build;
mod packet;
mod plan;
mod shared_allocation;
mod shared_input;
mod store;
pub use packet::{JpegFastPacket, SharedJpegFastPacket};
pub use plan::{JpegCachedPlan, JpegFastPacketState};
pub use shared_input::SharedJpegInput;
pub use store::{
JpegPlanCache, JpegPlanCacheDiagnostics, JpegPlanCacheInsert, DEFAULT_JPEG_PLAN_CACHE_ENTRIES,
DEFAULT_JPEG_PLAN_CACHE_HOST_BYTES,
};
#[derive(Debug, Clone, thiserror::Error)]
#[doc(hidden)]
pub enum JpegPlanCacheError {
#[error(
"host allocation limit exceeded for {what}: requested {requested} bytes, cap {cap} bytes"
)]
Limit {
what: &'static str,
requested: usize,
cap: usize,
},
#[error("host allocation failed for {bytes} bytes while allocating {what}: {source}")]
Allocation {
what: &'static str,
bytes: usize,
#[source]
source: TryReserveError,
},
#[error("JPEG accelerator plan cache invariant failed: {0}")]
Invariant(&'static str),
}
#[derive(Debug, Clone, thiserror::Error)]
#[doc(hidden)]
pub enum JpegCachedPlanBuildError {
#[error(transparent)]
Decode(#[from] JpegError),
#[error(transparent)]
FastPacket(#[from] FastPacketError),
#[error(transparent)]
Cache(#[from] JpegPlanCacheError),
}
impl JpegPlanCacheError {
pub(super) fn allocation(what: &'static str, bytes: usize, source: TryReserveError) -> Self {
Self::Allocation {
what,
bytes,
source,
}
}
}
#[cfg(test)]
mod tests;