Fixed status::StatusDescription
This commit is contained in:
parent
84218292e7
commit
5ed241d868
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
pub mod clientbound {
|
pub mod clientbound {
|
||||||
|
|
||||||
use serde::{Serialize, Deserialize, Deserializer};
|
use serde::{Serialize, Deserialize, Serializer, Deserializer};
|
||||||
use serde::de::{self, Visitor, MapAccess};
|
use serde::de::{self, Visitor, MapAccess};
|
||||||
use std::fmt;
|
use std::fmt;
|
||||||
|
|
||||||
|
@ -14,49 +14,63 @@ pub mod clientbound {
|
||||||
pub protocol: i32,
|
pub protocol: i32,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Serialize)]
|
|
||||||
pub enum StatusDescription {
|
pub enum StatusDescription {
|
||||||
String(String),
|
String(String),
|
||||||
Chat(mc_types::Chat),
|
Chat(mc_types::Chat),
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'de> Deserialize<'de> for StatusDescription {
|
impl Serialize for StatusDescription {
|
||||||
fn deserialize<D>(deserializer: D) -> std::result::Result<Self, D::Error>
|
fn serialize<S>(&self, serializer: S)
|
||||||
where
|
-> std::result::Result<S::Ok, S::Error>
|
||||||
D: Deserializer<'de>,
|
where
|
||||||
{
|
S: Serializer,
|
||||||
struct StatusDescriptionVisitor;
|
{
|
||||||
|
match *self {
|
||||||
impl<'de> Visitor<'de> for StatusDescriptionVisitor {
|
StatusDescription::String(ref s) => serializer.serialize_str(s),
|
||||||
type Value = StatusDescription;
|
StatusDescription::Chat(ref c) => c.serialize(serializer),
|
||||||
|
|
||||||
fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
|
|
||||||
formatter.write_str(
|
|
||||||
"a string or a map representing a Chat object")
|
|
||||||
}
|
|
||||||
|
|
||||||
fn visit_str<E>(self, value: &str)
|
|
||||||
-> std::result::Result<StatusDescription, E>
|
|
||||||
where
|
|
||||||
E: de::Error,
|
|
||||||
{
|
|
||||||
Ok(StatusDescription::String(value.to_string()))
|
|
||||||
}
|
|
||||||
|
|
||||||
fn visit_map<M>(self, map: M)
|
|
||||||
-> std::result::Result<StatusDescription, M::Error>
|
|
||||||
where
|
|
||||||
M: MapAccess<'de>,
|
|
||||||
{
|
|
||||||
let chat = mc_types::Chat::deserialize(
|
|
||||||
de::value::MapAccessDeserializer::new(map))?;
|
|
||||||
Ok(StatusDescription::Chat(chat))
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
deserializer.deserialize_any(StatusDescriptionVisitor)
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
impl<'de> Deserialize<'de> for StatusDescription {
|
||||||
|
fn deserialize<D>(deserializer: D) -> std::result::Result<Self, D::Error>
|
||||||
|
where
|
||||||
|
D: Deserializer<'de>,
|
||||||
|
{
|
||||||
|
struct StatusDescriptionVisitor;
|
||||||
|
|
||||||
|
impl<'de> Visitor<'de> for StatusDescriptionVisitor {
|
||||||
|
type Value = StatusDescription;
|
||||||
|
|
||||||
|
fn expecting(&self, formatter: &mut fmt::Formatter)
|
||||||
|
-> fmt::Result
|
||||||
|
{
|
||||||
|
formatter.write_str(
|
||||||
|
"a string or a map representing a Chat object")
|
||||||
|
}
|
||||||
|
|
||||||
|
fn visit_str<E>(self, value: &str)
|
||||||
|
-> std::result::Result<StatusDescription, E>
|
||||||
|
where
|
||||||
|
E: de::Error,
|
||||||
|
{
|
||||||
|
Ok(StatusDescription::String(value.to_string()))
|
||||||
|
}
|
||||||
|
|
||||||
|
fn visit_map<M>(self, map: M)
|
||||||
|
-> std::result::Result<StatusDescription, M::Error>
|
||||||
|
where
|
||||||
|
M: MapAccess<'de>,
|
||||||
|
{
|
||||||
|
let chat = mc_types::Chat::deserialize(
|
||||||
|
de::value::MapAccessDeserializer::new(map))?;
|
||||||
|
Ok(StatusDescription::Chat(chat))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
deserializer.deserialize_any(StatusDescriptionVisitor)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize)]
|
#[derive(Serialize, Deserialize)]
|
||||||
pub struct StatusPlayerInfo {
|
pub struct StatusPlayerInfo {
|
||||||
|
|
Loading…
Reference in New Issue