/rust/registry/src/index.crates.io-6f17d22bba15001f/zerovec-0.10.4/src/error.rs
Line | Count | Source (jump to first uncovered line) |
1 | | // This file is part of ICU4X. For terms of use, please see the file |
2 | | // called LICENSE at the top level of the ICU4X source tree |
3 | | // (online at: https://github.com/unicode-org/icu4x/blob/main/LICENSE ). |
4 | | |
5 | | use core::any; |
6 | | use core::fmt; |
7 | | |
8 | | /// A generic error type to be used for decoding slices of ULE types |
9 | | #[derive(Copy, Clone, Debug, PartialEq, Eq)] |
10 | | #[non_exhaustive] |
11 | | pub enum ZeroVecError { |
12 | | /// Attempted to parse a buffer into a slice of the given ULE type but its |
13 | | /// length was not compatible |
14 | | InvalidLength { ty: &'static str, len: usize }, |
15 | | /// The byte sequence provided for `ty` failed to parse correctly |
16 | | ParseError { ty: &'static str }, |
17 | | /// The byte buffer was not in the appropriate format for VarZeroVec |
18 | | VarZeroVecFormatError, |
19 | | } |
20 | | |
21 | | impl fmt::Display for ZeroVecError { |
22 | 0 | fn fmt(&self, f: &mut fmt::Formatter<'_>) -> Result<(), fmt::Error> { |
23 | 0 | match *self { |
24 | 0 | ZeroVecError::InvalidLength { ty, len } => { |
25 | 0 | write!(f, "Invalid length {len} for slice of type {ty}") |
26 | | } |
27 | 0 | ZeroVecError::ParseError { ty } => { |
28 | 0 | write!(f, "Could not parse bytes to slice of type {ty}") |
29 | | } |
30 | | ZeroVecError::VarZeroVecFormatError => { |
31 | 0 | write!(f, "Invalid format for VarZeroVec buffer") |
32 | | } |
33 | | } |
34 | 0 | } |
35 | | } |
36 | | |
37 | | impl ZeroVecError { |
38 | | /// Construct a parse error for the given type |
39 | 0 | pub fn parse<T: ?Sized + 'static>() -> ZeroVecError { |
40 | 0 | ZeroVecError::ParseError { |
41 | 0 | ty: any::type_name::<T>(), |
42 | 0 | } |
43 | 0 | } Unexecuted instantiation: <zerovec::error::ZeroVecError>::parse::<icu_properties::provider::names::NormalizedPropertyNameStr> Unexecuted instantiation: <zerovec::error::ZeroVecError>::parse::<icu_locid::subtags::region::Region> Unexecuted instantiation: <zerovec::error::ZeroVecError>::parse::<icu_locid::subtags::script::Script> Unexecuted instantiation: <zerovec::error::ZeroVecError>::parse::<icu_locid::subtags::variant::Variant> Unexecuted instantiation: <zerovec::error::ZeroVecError>::parse::<icu_locid::subtags::language::Language> Unexecuted instantiation: <zerovec::error::ZeroVecError>::parse::<icu_locid::extensions::other::subtag::Subtag> Unexecuted instantiation: <zerovec::error::ZeroVecError>::parse::<icu_locid::extensions::private::other::Subtag> Unexecuted instantiation: <zerovec::error::ZeroVecError>::parse::<icu_locid::extensions::unicode::key::Key> Unexecuted instantiation: <zerovec::error::ZeroVecError>::parse::<icu_locid::extensions::unicode::attribute::Attribute> Unexecuted instantiation: <zerovec::error::ZeroVecError>::parse::<icu_locid::extensions::transform::key::Key> Unexecuted instantiation: <zerovec::error::ZeroVecError>::parse::<_> |
44 | | |
45 | | /// Construct an "invalid length" error for the given type and length |
46 | 0 | pub fn length<T: ?Sized + 'static>(len: usize) -> ZeroVecError { |
47 | 0 | ZeroVecError::InvalidLength { |
48 | 0 | ty: any::type_name::<T>(), |
49 | 0 | len, |
50 | 0 | } |
51 | 0 | } Unexecuted instantiation: <zerovec::error::ZeroVecError>::length::<zerovec::ule::plain::RawBytesULE<2>> Unexecuted instantiation: <zerovec::error::ZeroVecError>::length::<icu_locid::subtags::region::Region> Unexecuted instantiation: <zerovec::error::ZeroVecError>::length::<icu_locid::subtags::script::Script> Unexecuted instantiation: <zerovec::error::ZeroVecError>::length::<icu_locid::subtags::variant::Variant> Unexecuted instantiation: <zerovec::error::ZeroVecError>::length::<icu_locid::subtags::language::Language> Unexecuted instantiation: <zerovec::error::ZeroVecError>::length::<icu_locid::extensions::other::subtag::Subtag> Unexecuted instantiation: <zerovec::error::ZeroVecError>::length::<icu_locid::extensions::private::other::Subtag> Unexecuted instantiation: <zerovec::error::ZeroVecError>::length::<icu_locid::extensions::unicode::key::Key> Unexecuted instantiation: <zerovec::error::ZeroVecError>::length::<icu_locid::extensions::unicode::attribute::Attribute> Unexecuted instantiation: <zerovec::error::ZeroVecError>::length::<icu_locid::extensions::transform::key::Key> Unexecuted instantiation: <zerovec::error::ZeroVecError>::length::<_> |
52 | | } |
53 | | |
54 | | #[cfg(feature = "std")] |
55 | | impl ::std::error::Error for ZeroVecError {} |