mirror of
https://github.com/serde-rs/json.git
synced 2026-02-08 00:46:18 +00:00
Mark error construction as cold code
This commit is contained in:
parent
acbc1517b3
commit
a59a4f447f
@ -264,6 +264,7 @@ pub enum ErrorCode {
|
||||
impl Error {
|
||||
// Not public API. Should be pub(crate).
|
||||
#[doc(hidden)]
|
||||
#[cold]
|
||||
pub fn syntax(code: ErrorCode, line: usize, column: usize) -> Self {
|
||||
Error {
|
||||
err: Box::new(ErrorImpl {
|
||||
@ -278,6 +279,7 @@ impl Error {
|
||||
//
|
||||
// Update `eager_json` crate when this function changes.
|
||||
#[doc(hidden)]
|
||||
#[cold]
|
||||
pub fn io(error: io::Error) -> Self {
|
||||
Error {
|
||||
err: Box::new(ErrorImpl {
|
||||
@ -290,6 +292,7 @@ impl Error {
|
||||
|
||||
// Not public API. Should be pub(crate).
|
||||
#[doc(hidden)]
|
||||
#[cold]
|
||||
pub fn fix_position<F>(self, f: F) -> Self
|
||||
where
|
||||
F: FnOnce(ErrorCode) -> Error,
|
||||
@ -391,6 +394,7 @@ impl Debug for Error {
|
||||
}
|
||||
|
||||
impl de::Error for Error {
|
||||
#[cold]
|
||||
fn custom<T: Display>(msg: T) -> Error {
|
||||
Error {
|
||||
err: Box::new(ErrorImpl {
|
||||
@ -401,6 +405,7 @@ impl de::Error for Error {
|
||||
}
|
||||
}
|
||||
|
||||
#[cold]
|
||||
fn invalid_type(unexp: de::Unexpected, exp: &de::Expected) -> Self {
|
||||
if let de::Unexpected::Unit = unexp {
|
||||
Error::custom(format_args!("invalid type: null, expected {}", exp))
|
||||
@ -411,6 +416,7 @@ impl de::Error for Error {
|
||||
}
|
||||
|
||||
impl ser::Error for Error {
|
||||
#[cold]
|
||||
fn custom<T: Display>(msg: T) -> Error {
|
||||
Error {
|
||||
err: Box::new(ErrorImpl {
|
||||
|
||||
@ -748,6 +748,7 @@ impl Number {
|
||||
#[cfg(not(feature = "arbitrary_precision"))]
|
||||
// Not public API. Should be pub(crate).
|
||||
#[doc(hidden)]
|
||||
#[cold]
|
||||
pub fn unexpected(&self) -> Unexpected {
|
||||
match self.n {
|
||||
N::PosInt(u) => Unexpected::Unsigned(u),
|
||||
@ -759,6 +760,7 @@ impl Number {
|
||||
#[cfg(feature = "arbitrary_precision")]
|
||||
// Not public API. Should be pub(crate).
|
||||
#[doc(hidden)]
|
||||
#[cold]
|
||||
pub fn unexpected(&self) -> Unexpected {
|
||||
Unexpected::Other("number")
|
||||
}
|
||||
|
||||
@ -1409,6 +1409,7 @@ impl Value {
|
||||
serde::de::Error::invalid_type(self.unexpected(), exp)
|
||||
}
|
||||
|
||||
#[cold]
|
||||
fn unexpected(&self) -> Unexpected {
|
||||
match *self {
|
||||
Value::Null => Unexpected::Unit,
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user