pub struct NotificationMetaObject(pub MetaObject);Expand description
The _meta map carried by notifications (spec NotificationMetaObject).
In addition to arbitrary extension keys, notifications reserve
io.modelcontextprotocol/subscriptionId to correlate a notification with a
prior subscription request.
This type dereferences to MetaObject (and transitively to the underlying
map), so general helpers such as the SEP-414 trace-context accessors remain
available.
Tuple Fields§
§0: MetaObjectImplementations§
Source§impl NotificationMetaObject
impl NotificationMetaObject
Sourcepub fn subscription_id(&self) -> Option<RequestId>
pub fn subscription_id(&self) -> Option<RequestId>
Get the subscription id carried in _meta, if present and valid.
§Examples
use rmcp::model::{NotificationMetaObject, RequestId};
let mut meta = NotificationMetaObject::new();
assert_eq!(meta.subscription_id(), None);
meta.set_subscription_id(RequestId::Number(7));
assert_eq!(meta.subscription_id(), Some(RequestId::Number(7)));Sourcepub fn set_subscription_id(&mut self, subscription_id: RequestId)
pub fn set_subscription_id(&mut self, subscription_id: RequestId)
Set the subscription id carried in _meta.
Sourcepub fn extend(&mut self, other: NotificationMetaObject)
pub fn extend(&mut self, other: NotificationMetaObject)
Insert every entry of other, overwriting existing keys on conflict.
Methods from Deref<Target = MetaObject>§
Sourcepub fn get_traceparent(&self) -> Option<&str>
pub fn get_traceparent(&self) -> Option<&str>
Get the W3C traceparent value (SEP-414), if present.
Sourcepub fn set_traceparent(&mut self, value: impl Into<String>)
pub fn set_traceparent(&mut self, value: impl Into<String>)
Set the W3C traceparent value (SEP-414).
use rmcp::model::MetaObject;
let mut meta = MetaObject::new();
meta.set_traceparent("00-0af7651916cd43dd8448eb211c80319c-00f067aa0ba902b7-01");
assert_eq!(
meta.get_traceparent(),
Some("00-0af7651916cd43dd8448eb211c80319c-00f067aa0ba902b7-01"),
);Sourcepub fn get_tracestate(&self) -> Option<&str>
pub fn get_tracestate(&self) -> Option<&str>
Get the W3C tracestate value (SEP-414), if present.
Sourcepub fn set_tracestate(&mut self, value: impl Into<String>)
pub fn set_tracestate(&mut self, value: impl Into<String>)
Set the W3C tracestate value (SEP-414).
Sourcepub fn get_baggage(&self) -> Option<&str>
pub fn get_baggage(&self) -> Option<&str>
Get the W3C baggage value (SEP-414), if present.
Sourcepub fn set_baggage(&mut self, value: impl Into<String>)
pub fn set_baggage(&mut self, value: impl Into<String>)
Set the W3C baggage value (SEP-414).
Sourcepub fn extend(&mut self, other: MetaObject)
pub fn extend(&mut self, other: MetaObject)
Insert every entry of other, overwriting existing keys on conflict.
Methods from Deref<Target = JsonObject>§
Sourcepub fn get<Q>(&self, key: &Q) -> Option<&Value>
pub fn get<Q>(&self, key: &Q) -> Option<&Value>
Returns a reference to the value corresponding to the key.
The key may be any borrowed form of the map’s key type, but the ordering on the borrowed form must match the ordering on the key type.
Sourcepub fn contains_key<Q>(&self, key: &Q) -> bool
pub fn contains_key<Q>(&self, key: &Q) -> bool
Returns true if the map contains a value for the specified key.
The key may be any borrowed form of the map’s key type, but the ordering on the borrowed form must match the ordering on the key type.
Sourcepub fn get_mut<Q>(&mut self, key: &Q) -> Option<&mut Value>
pub fn get_mut<Q>(&mut self, key: &Q) -> Option<&mut Value>
Returns a mutable reference to the value corresponding to the key.
The key may be any borrowed form of the map’s key type, but the ordering on the borrowed form must match the ordering on the key type.
Sourcepub fn get_key_value<Q>(&self, key: &Q) -> Option<(&String, &Value)>
pub fn get_key_value<Q>(&self, key: &Q) -> Option<(&String, &Value)>
Returns the key-value pair matching the given key.
The key may be any borrowed form of the map’s key type, but the ordering on the borrowed form must match the ordering on the key type.
Sourcepub fn insert(&mut self, k: String, v: Value) -> Option<Value>
pub fn insert(&mut self, k: String, v: Value) -> Option<Value>
Inserts a key-value pair into the map.
If the map did not have this key present, None is returned.
If the map did have this key present, the value is updated, and the old value is returned.
Sourcepub fn remove<Q>(&mut self, key: &Q) -> Option<Value>
pub fn remove<Q>(&mut self, key: &Q) -> Option<Value>
Removes a key from the map, returning the value at the key if the key was previously in the map.
The key may be any borrowed form of the map’s key type, but the ordering on the borrowed form must match the ordering on the key type.
If serde_json’s “preserve_order” is enabled, .remove(key) is
equivalent to [.swap_remove(key)][Self::swap_remove], replacing this
entry’s position with the last element. If you need to preserve the
relative order of the keys in the map, use
[.shift_remove(key)][Self::shift_remove] instead.
Sourcepub fn remove_entry<Q>(&mut self, key: &Q) -> Option<(String, Value)>
pub fn remove_entry<Q>(&mut self, key: &Q) -> Option<(String, Value)>
Removes a key from the map, returning the stored key and value if the key was previously in the map.
The key may be any borrowed form of the map’s key type, but the ordering on the borrowed form must match the ordering on the key type.
If serde_json’s “preserve_order” is enabled, .remove_entry(key) is
equivalent to [.swap_remove_entry(key)][Self::swap_remove_entry],
replacing this entry’s position with the last element. If you need to
preserve the relative order of the keys in the map, use
[.shift_remove_entry(key)][Self::shift_remove_entry] instead.
Sourcepub fn append(&mut self, other: &mut Map<String, Value>)
pub fn append(&mut self, other: &mut Map<String, Value>)
Moves all elements from other into self, leaving other empty.
Sourcepub fn entry<S>(&mut self, key: S) -> Entry<'_>
pub fn entry<S>(&mut self, key: S) -> Entry<'_>
Gets the given key’s corresponding entry in the map for in-place manipulation.
Sourcepub fn values_mut(&mut self) -> ValuesMut<'_>
pub fn values_mut(&mut self) -> ValuesMut<'_>
Gets an iterator over mutable values of the map.
Sourcepub fn retain<F>(&mut self, f: F)
pub fn retain<F>(&mut self, f: F)
Retains only the elements specified by the predicate.
In other words, remove all pairs (k, v) such that f(&k, &mut v)
returns false.
Sourcepub fn sort_keys(&mut self)
pub fn sort_keys(&mut self)
Sorts this map’s entries in-place using str’s usual ordering.
If serde_json’s “preserve_order” feature is not enabled, this method does no work because all JSON maps are always kept in a sorted state.
If serde_json’s “preserve_order” feature is enabled, this method destroys the original source order or insertion order of this map in favor of an alphanumerical order that matches how a BTreeMap with the same contents would be ordered. This takes O(n log n + c) time where n is the length of the map and c is the capacity.
Other maps nested within the values of this map are not sorted. If you
need the entire data structure to be sorted at all levels, you must also
call
map.values_mut().for_each(Value::sort_all_objects).
Trait Implementations§
Source§impl Clone for NotificationMetaObject
impl Clone for NotificationMetaObject
Source§fn clone(&self) -> NotificationMetaObject
fn clone(&self) -> NotificationMetaObject
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for NotificationMetaObject
impl Debug for NotificationMetaObject
Source§impl Default for NotificationMetaObject
impl Default for NotificationMetaObject
Source§fn default() -> NotificationMetaObject
fn default() -> NotificationMetaObject
Source§impl Deref for NotificationMetaObject
impl Deref for NotificationMetaObject
Source§impl DerefMut for NotificationMetaObject
impl DerefMut for NotificationMetaObject
Source§impl<'de> Deserialize<'de> for NotificationMetaObject
impl<'de> Deserialize<'de> for NotificationMetaObject
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>,
Source§impl From<Map<String, Value>> for NotificationMetaObject
impl From<Map<String, Value>> for NotificationMetaObject
Source§fn from(object: JsonObject) -> Self
fn from(object: JsonObject) -> Self
Source§impl From<MetaObject> for NotificationMetaObject
impl From<MetaObject> for NotificationMetaObject
Source§fn from(meta: MetaObject) -> Self
fn from(meta: MetaObject) -> Self
Source§impl JsonSchema for NotificationMetaObject
Available on crate feature schemars only.
impl JsonSchema for NotificationMetaObject
schemars only.Source§fn json_schema(generator: &mut SchemaGenerator) -> Schema
fn json_schema(generator: &mut SchemaGenerator) -> Schema
Source§fn inline_schema() -> bool
fn inline_schema() -> bool
$ref keyword. Read more