lewp_css/domain/numbers/
css_number_conversion_error.rs

1// This file is part of css. It is subject to the license terms in the COPYRIGHT file found in the top-level directory of this distribution and at https://raw.githubusercontent.com/lemonrock/css/master/COPYRIGHT. No part of predicator, including this file, may be copied, modified, propagated, or distributed except according to the terms contained in the COPYRIGHT file.
2// Copyright © 2017 The developers of css. See the COPYRIGHT file in the top-level directory of this distribution and at https://raw.githubusercontent.com/lemonrock/css/master/COPYRIGHT.
3
4use std::{
5    error::Error,
6    fmt::{self, Display, Formatter},
7};
8
9#[derive(Debug, Copy, Clone, Ord, PartialOrd, Eq, PartialEq, Hash)]
10pub enum CssNumberConversionError {
11    InfinityIsNotAllowed,
12    NotANumberIsNotAllowed,
13    NegativeNumberMayNotBeAllowed,
14    FloatingPointNumberMayNotBeAllowed,
15}
16
17impl Display for CssNumberConversionError {
18    #[inline(always)]
19    fn fmt(&self, f: &mut Formatter) -> fmt::Result {
20        f.write_str(&self.to_string())
21    }
22}
23
24impl Error for CssNumberConversionError {
25    #[inline(always)]
26    fn description(&self) -> &str {
27        use self::CssNumberConversionError::*;
28
29        match *self {
30            InfinityIsNotAllowed => "infinity is not a valid CSS number",
31            NotANumberIsNotAllowed => {
32                "not a number (NaN) is not a valid CSS number"
33            }
34            NegativeNumberMayNotBeAllowed => {
35                "negative numbers are not valid for a CSS number"
36            }
37            FloatingPointNumberMayNotBeAllowed => {
38                "floating point numbers are not valid for a CSS integer"
39            }
40        }
41    }
42
43    #[inline(always)]
44    fn cause(&self) -> Option<&dyn Error> {
45        None
46    }
47}