pub struct JsonRpcNotification {
pub jsonrpc: String,
pub method: String,
pub params: Option<Value>,
}Expand description
JSON-RPC 2.0 Notification Message
Represents a notification - a request that does not expect a response. Notifications are “fire and forget” messages used for events or one-way communication.
§JSON-RPC 2.0 Specification Compliance
jsonrpc: MUST be exactly “2.0”method: MUST be a String containing the name of the notification methodparams: MAY be omitted. If present, MUST be Structured values (Object) or Ordered values (Array)id: MUST NOT be present (this is what distinguishes notifications from requests)
§Examples
use airsprotocols_mcp::protocol::{JsonRpcNotification, JsonRpcMessageTrait};
use serde_json::json;
// Notification with parameters
let notification = JsonRpcNotification::new(
"user_logged_in",
Some(json!({"user_id": 12345, "timestamp": "2025-07-28T10:30:00Z"}))
);
// Use trait methods for serialization
let json = notification.to_json().unwrap();
let parsed = JsonRpcNotification::from_json(&json).unwrap();
assert_eq!(notification, parsed);Fields§
§jsonrpc: StringProtocol version - always “2.0” for JSON-RPC 2.0 compliance
method: StringName of the notification method
params: Option<Value>Parameters for the notification (null, object, or array)
Implementations§
Source§impl JsonRpcNotification
impl JsonRpcNotification
Sourcepub fn new(method: impl Into<String>, params: Option<Value>) -> Self
pub fn new(method: impl Into<String>, params: Option<Value>) -> Self
Create a new JSON-RPC 2.0 notification
§Parameters
method: Name of the notification methodparams: Optional parameters (will be serialized as JSON)
§Examples
use airsprotocols_mcp::protocol::JsonRpcNotification;
use serde_json::json;
let notification = JsonRpcNotification::new(
"status_changed",
Some(json!({"old_status": "pending", "new_status": "active"}))
);Sourcepub fn new_validated(
method: impl Into<String>,
params: Option<Value>,
) -> Result<Self, JsonRpcError>
pub fn new_validated( method: impl Into<String>, params: Option<Value>, ) -> Result<Self, JsonRpcError>
Create and validate a new JSON-RPC 2.0 notification
This function performs validation during construction to catch invalid notifications early.
§Parameters
method: Name of the notification method (must be non-empty)params: Optional parameters (will be serialized as JSON)
§Returns
Ok(JsonRpcNotification)- Valid notification created successfullyErr(JsonRpcError)- Notification violates JSON-RPC 2.0 specification
§Examples
use airsprotocols_mcp::protocol::JsonRpcNotification;
use serde_json::json;
let notification = JsonRpcNotification::new_validated(
"status_changed",
Some(json!({"old_status": "pending", "new_status": "active"}))
)?;Trait Implementations§
Source§impl Clone for JsonRpcNotification
impl Clone for JsonRpcNotification
Source§fn clone(&self) -> JsonRpcNotification
fn clone(&self) -> JsonRpcNotification
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for JsonRpcNotification
impl Debug for JsonRpcNotification
Source§impl<'de> Deserialize<'de> for JsonRpcNotification
impl<'de> Deserialize<'de> for JsonRpcNotification
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 JsonRpcMessageTrait for JsonRpcNotification
impl JsonRpcMessageTrait for JsonRpcNotification
Source§impl PartialEq for JsonRpcNotification
impl PartialEq for JsonRpcNotification
Source§impl Serialize for JsonRpcNotification
impl Serialize for JsonRpcNotification
impl StructuralPartialEq for JsonRpcNotification
Auto Trait Implementations§
impl Freeze for JsonRpcNotification
impl RefUnwindSafe for JsonRpcNotification
impl Send for JsonRpcNotification
impl Sync for JsonRpcNotification
impl Unpin for JsonRpcNotification
impl UnwindSafe for JsonRpcNotification
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