error.rs38.46%
1
// Copyright 2024 Google LLC2
//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 at6
//7
// https://www.apache.org/licenses/LICENSE-2.08
//9
// Unless required by applicable law or agreed to in writing, software10
// 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 and13
// limitations under the License.14
15
use std::fmt::{self, Display};16
17
use serde::{de, ser};18
19
#[derive(Debug)]20
pub 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
34
impl std::error::Error for Error {}35
36
impl Display for Error {37
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {38
write!(f, "{self:?}")39
}40
}41
42
impl de::Error for Error {43
fn custom<T>(msg: T) -> Self13x44
where13x45
T: Display,13x46
{47
Error::Message(msg.to_string())13x48
}13x49
}50
51
impl ser::Error for Error {52
fn custom<T>(msg: T) -> Self53
where54
T: Display,55
{56
Error::Message(msg.to_string())57
}58
}59
60
pub type Result<T, E = Error> = std::result::Result<T, E>;61