pub struct Goodbye {
pub details: Value,
pub reason: String,
}
Expand description
Goodbye - wamp-proto
represenets an goodbye message in wamp protocol.
Examples
use wamp_core::messages::Goodbye;
use wamp_core::goodbye;
use serde_json::json;
let goodbye_message = Goodbye {
reason: "wamp.close.system_shutdown".to_string(),
details: json!({})
};
Serializer
Implements serde Serialize trait for Goodbye
use wamp_core::messages::Goodbye;
use serde_json::{json, to_string};
// Create an goodbye message
let goodbye = Goodbye {
details: json!({"message": "The host is shutting down now."}),
reason: "wamp.close.system_shutdown".to_string()
};
// Establish raw json data string
let data = r#"[6,{"message":"The host is shutting down now."},"wamp.close.system_shutdown"]"#;
// Here we convert it from an `Goodbye` frame, to a string representation.
let goodbye = to_string(&goodbye).unwrap();
// Confirm that our Goodbye frame strings are equal to eachother
assert_eq!(goodbye, data);
Deserializer
Implements serde Deserialize trait for Goodbye
use wamp_core::messages::Goodbye;
use serde_json::from_str;
// Here is our raw json data string
let data = r#"[6,{"message": "The host is shutting down now."},"wamp.close.system_shutdown"]"#;
// Here we convert it to an `goodbye` frame
let goodbye = from_str::<Goodbye>(data).unwrap();
// Confirm that our error type deserialized
assert_eq!(goodbye.reason, "wamp.close.system_shutdown");
Fields§
§details: Value
§reason: String
Trait Implementations§
source§impl<'de> Deserialize<'de> for Goodbye
impl<'de> Deserialize<'de> for Goodbye
source§fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>where
D: Deserializer<'de>,
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>where
D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
source§impl PartialEq for Goodbye
impl PartialEq for Goodbye
source§impl WampMessage for Goodbye
impl WampMessage for Goodbye
impl Eq for Goodbye
impl StructuralEq for Goodbye
impl StructuralPartialEq for Goodbye
Auto Trait Implementations§
impl RefUnwindSafe for Goodbye
impl Send for Goodbye
impl Sync for Goodbye
impl Unpin for Goodbye
impl UnwindSafe for Goodbye
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more