Skip to main content

use_bond/
error.rs

1use std::error::Error;
2use std::fmt;
3
4/// Errors returned when constructing bond values.
5#[derive(Clone, Debug, Eq, PartialEq)]
6pub enum BondValidationError {
7    /// A bond endpoint label is empty.
8    EmptyEndpointLabel,
9    /// A bond participant label is empty.
10    EmptyParticipantLabel,
11    /// A bond descriptor is empty.
12    EmptyDescriptor,
13    /// A bond angle label or reference is empty.
14    EmptyAngleLabel,
15    /// A bond length unit is empty.
16    EmptyLengthUnit,
17    /// A bond length value is not finite.
18    NonFiniteBondLength,
19    /// A bond length value is zero or negative.
20    NonPositiveBondLength,
21    /// A fractional bond order numerator is zero.
22    ZeroFractionalBondOrderNumerator,
23    /// A fractional bond order denominator is zero.
24    ZeroFractionalBondOrderDenominator,
25}
26
27impl fmt::Display for BondValidationError {
28    fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
29        match self {
30            Self::EmptyEndpointLabel => {
31                formatter.write_str("bond endpoint label must not be empty")
32            },
33            Self::EmptyParticipantLabel => {
34                formatter.write_str("bond participant label must not be empty")
35            },
36            Self::EmptyDescriptor => formatter.write_str("bond descriptor must not be empty"),
37            Self::EmptyAngleLabel => formatter.write_str("bond angle label must not be empty"),
38            Self::EmptyLengthUnit => formatter.write_str("bond length unit must not be empty"),
39            Self::NonFiniteBondLength => formatter.write_str("bond length must be finite"),
40            Self::NonPositiveBondLength => formatter.write_str("bond length must be positive"),
41            Self::ZeroFractionalBondOrderNumerator => {
42                formatter.write_str("fractional bond order numerator must not be zero")
43            },
44            Self::ZeroFractionalBondOrderDenominator => {
45                formatter.write_str("fractional bond order denominator must not be zero")
46            },
47        }
48    }
49}
50
51impl Error for BondValidationError {}