Skip to main content

bin_packing/
error.rs

1use thiserror::Error;
2
3/// Errors returned by the bin-packing solvers.
4#[derive(Debug, Error)]
5#[non_exhaustive]
6pub enum BinPackingError {
7    /// The problem failed input validation (e.g. empty demand list, zero dimension, invalid cost).
8    #[error("invalid input: {0}")]
9    InvalidInput(String),
10    /// The requested solver configuration is not currently supported.
11    #[error("unsupported configuration: {0}")]
12    Unsupported(String),
13    /// A 1D demand cannot fit any declared stock entry.
14    #[error("no feasible stock can fit demand `{item}` with length {length}")]
15    Infeasible1D {
16        /// Name of the demand that could not be placed.
17        item: String,
18        /// Length of the demand that triggered the infeasibility.
19        length: u32,
20    },
21    /// A 2D demand cannot fit any declared sheet entry, even with rotation.
22    #[error("no feasible sheet can fit item `{item}` with size {width}x{height}")]
23    Infeasible2D {
24        /// Name of the demand that could not be placed.
25        item: String,
26        /// Width of the demand that triggered the infeasibility.
27        width: u32,
28        /// Height of the demand that triggered the infeasibility.
29        height: u32,
30    },
31    /// A 3D demand cannot fit any declared bin entry, even with rotation.
32    #[error("no feasible bin can fit item `{item}` with size {width}x{height}x{depth}")]
33    Infeasible3D {
34        /// Name of the demand that could not be placed.
35        item: String,
36        /// Width of the demand that triggered the infeasibility.
37        width: u32,
38        /// Height of the demand that triggered the infeasibility.
39        height: u32,
40        /// Depth of the demand that triggered the infeasibility.
41        depth: u32,
42    },
43}
44
45/// Convenient `Result` alias that uses [`BinPackingError`] as the error type.
46pub type Result<T> = std::result::Result<T, BinPackingError>;