Alioth Code Coverage

error.rs38.46%

1// Copyright 2024 Google LLC
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// https://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15use std::fmt::{self, Display};
16
17use serde::{de, ser};
18
19#[derive(Debug)]
20pub enum Error {
21 Message(String),
22 ExpectedMapEq,
23 ExpectedInteger,
24 ExpectedFloat,
25 ExpectedBool,
26 ExpectedUnit,
27 Trailing(String),
28 Ignored(String),
29 IdNotFound(String),
30 Overflow,
31 UnknownType,
32}
33
34impl std::error::Error for Error {}
35
36impl Display for Error {
37 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
38 write!(f, "{self:?}")
39 }
40}
41
42impl de::Error for Error {
43 fn custom<T>(msg: T) -> Self13x
44 where13x
45 T: Display,13x
46 {
47 Error::Message(msg.to_string())13x
48 }13x
49}
50
51impl ser::Error for Error {
52 fn custom<T>(msg: T) -> Self
53 where
54 T: Display,
55 {
56 Error::Message(msg.to_string())
57 }
58}
59
60pub type Result<T, E = Error> = std::result::Result<T, E>;
61