#[non_exhaustive]pub struct ExtensionMessage {
pub message_type: String,
pub id: Option<String>,
pub body: Map<String, Value>,
}Available on crate feature
server only.Expand description
One client message whose @type an ExtensionHandler registered.
use jmap_websocket::server::ExtensionMessage;
#[derive(serde::Deserialize)]
#[serde(rename_all = "camelCase")]
struct ToyEnable {
topics: Vec<String>,
}
let m = ExtensionMessage::new(
"ToyStreamEnable",
serde_json::from_str(r#"{"id":"e1","topics":["a"]}"#).unwrap(),
);
assert_eq!(m.id.as_deref(), Some("e1"));
let enable: ToyEnable = m.deserialize().unwrap();
assert_eq!(enable.topics, ["a"]);Fields (Non-exhaustive)§
This struct is marked as non-exhaustive
Non-exhaustive structs could have additional fields added in future. Therefore, non-exhaustive structs cannot be constructed in external crates using the traditional
Struct { .. } syntax; cannot be matched against without a wildcard ..; and struct update syntax will not work.message_type: StringThe message’s @type.
id: Option<String>The message’s id when it is a string: the requestId of a
RequestError the message causes (RFC 8887 §4.3.4). It also stays
in body.
body: Map<String, Value>Every member of the message except @type.
Implementations§
Source§impl ExtensionMessage
impl ExtensionMessage
Sourcepub fn new(message_type: impl Into<String>, body: Map<String, Value>) -> Self
pub fn new(message_type: impl Into<String>, body: Map<String, Value>) -> Self
A message of type message_type with the members body (without
@type); id is taken from body.
Sourcepub fn deserialize<T: DeserializeOwned>(&self) -> Result<T, JmapError>
pub fn deserialize<T: DeserializeOwned>(&self) -> Result<T, JmapError>
The body as a T, typically the extension’s own frame type.
§Errors
A notRequest error when the body does not deserialize, as the
driver answers a malformed WebSocketPushEnable. Return it from
ExtensionHandler::handle to send it to the client.
Trait Implementations§
Source§impl Clone for ExtensionMessage
impl Clone for ExtensionMessage
Source§impl Debug for ExtensionMessage
impl Debug for ExtensionMessage
Source§impl PartialEq for ExtensionMessage
impl PartialEq for ExtensionMessage
impl StructuralPartialEq for ExtensionMessage
Auto Trait Implementations§
impl Forget for ExtensionMessage
impl Freeze for ExtensionMessage
impl Move for ExtensionMessage
impl RefUnwindSafe for ExtensionMessage
impl Send for ExtensionMessage
impl Sync for ExtensionMessage
impl Unpin for ExtensionMessage
impl UnsafeUnpin for ExtensionMessage
impl UnwindSafe for ExtensionMessage
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