use crate::encode::JsonSerializerStateError;
use crate::internal::serde_json_compat::SERDE_JSON_NUMBER_TOKEN;
use crate::internal::serde_json_compat::SERDE_JSON_RAW_VALUE_TOKEN;
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub(crate) enum JsonPrivateProtocolKind {
RawValue,
Number,
}
impl JsonPrivateProtocolKind {
#[inline]
pub(crate) fn from_struct_name(name: &str) -> Option<Self> {
match name {
SERDE_JSON_RAW_VALUE_TOKEN => Some(Self::RawValue),
SERDE_JSON_NUMBER_TOKEN => Some(Self::Number),
_ => None,
}
}
#[must_use]
#[inline]
pub(crate) const fn struct_name(self) -> &'static str {
match self {
Self::RawValue => SERDE_JSON_RAW_VALUE_TOKEN,
Self::Number => SERDE_JSON_NUMBER_TOKEN,
}
}
#[must_use]
#[inline]
pub(crate) const fn field_name(self) -> &'static str {
self.struct_name()
}
#[inline]
pub(crate) const fn invalid_state(self) -> JsonSerializerStateError {
match self {
Self::RawValue => JsonSerializerStateError::InvalidRawValueProtocol,
Self::Number => JsonSerializerStateError::InvalidNumberProtocol,
}
}
}