substrate/layout/
error.rs

1//! Layout result and error types.
2
3use arcstr::ArcStr;
4use rust_decimal::Decimal;
5
6/// The [`LayoutError`] result type.
7pub type LayoutResult<T> = Result<T, LayoutError>;
8
9/// A layout error.
10#[derive(thiserror::Error, Debug, Clone)]
11pub enum LayoutError {
12    /// An error with exporting a Substrate cell to GDS.
13    #[error("error during gds export: {0:?}")]
14    GdsExport(GdsExportError),
15    /// An error with defining the IO of a Substrate layout cell.
16    #[error("error specifying layout IO")]
17    IoDefinition,
18    /// A port had no geometry.
19    #[error("a port had no geometry")]
20    EmptyPort,
21}
22
23impl From<GdsExportError> for LayoutError {
24    fn from(e: GdsExportError) -> Self {
25        Self::GdsExport(e)
26    }
27}
28
29/// The [`GdsExportError`] result type.
30pub type GdsExportResult<T> = Result<T, GdsExportError>;
31
32/// A GDS export error.
33#[derive(thiserror::Error, Debug, Clone)]
34pub enum GdsExportError {
35    /// An error coverting an integer into a type that can be encoded in GDS.
36    #[error("error converting an integer to the necessary type: {0:?}")]
37    TryFromInt(std::num::TryFromIntError),
38    /// An error in writing a GDS file.
39    #[error("error writing GDS file: {0:?}")]
40    Write(gds::GdsError),
41}
42
43impl From<std::num::TryFromIntError> for GdsExportError {
44    fn from(e: std::num::TryFromIntError) -> Self {
45        Self::TryFromInt(e)
46    }
47}
48
49impl From<gds::GdsError> for GdsExportError {
50    fn from(e: gds::GdsError) -> Self {
51        Self::Write(e)
52    }
53}
54
55/// The [`GdsImportError`] result type.
56pub type GdsImportResult<T> = Result<T, GdsImportError>;
57
58/// A GDS import error.
59#[derive(thiserror::Error, Debug, Clone)]
60pub enum GdsImportError {
61    /// An error coverting an integer into a type that can be encoded in GDS.
62    #[error("error converting an integer to the necessary type: {0:?}")]
63    TryFromInt(#[from] std::num::TryFromIntError),
64    /// An error in writing a GDS file.
65    #[error("error writing GDS file: {0:?}")]
66    Write(#[from] gds::GdsError),
67    /// No cell of the given name exists in the GDS library.
68    #[error("cell not found in GDS library: {0}")]
69    CellNotFound(ArcStr),
70    /// More than one cell with the given name was defined in the same GDS library.
71    #[error("found more than one cell with the same name in a GDS library: {0}")]
72    DuplicateCell(ArcStr),
73    /// Use of an unsupported GDS feature.
74    #[error("unsupported GDS feature: {0}")]
75    Unsupported(ArcStr),
76    /// An GDS struct contained an invalid GDS boundary.
77    ///
78    /// GDS boundaries must start and end at the same point.
79    #[error("invalid GDS boundary (boundaries must start and end at the same point)")]
80    InvalidGdsBoundary,
81    /// The database unit in a GDS file does not match that expected by the PDK.
82    #[error("GDS file units ({0}) do not match PDK units ({1})")]
83    MismatchedUnits(Decimal, Decimal),
84}