pub struct ExtensionsJson(/* private fields */);Expand description
A JSON-object map of protocol extension data attached to a payment message.
ExtensionsJson is the wire representation of optional extension fields in
PaymentPayload and PaymentRequired. Each extension is keyed by the
string constant exposed by ExtensionKey::EXTENSION_KEY and stored as a
JSON value, so heterogeneous extension types can coexist in the same map.
§Serialization
Serializes to and from a JSON object (e.g. { "eip2612GasSponsoring": { … } }).
Implementations§
Source§impl ExtensionsJson
impl ExtensionsJson
Sourcepub fn new() -> Self
pub fn new() -> Self
Creates an empty ExtensionsJson map.
Equivalent to ExtensionsJson::default().
Sourcepub fn insert<T>(&mut self, value: T) -> Result<Option<Value>>where
T: ExtensionKey + Serialize,
pub fn insert<T>(&mut self, value: T) -> Result<Option<Value>>where
T: ExtensionKey + Serialize,
Inserts or replaces an extension entry, keyed by T::EXTENSION_KEY.
value is serialized to a serde_json::Value before insertion.
If a value was previously stored under the same key, it is returned
as Some(old_value).
§Errors
Returns a serde_json::Error if value cannot be serialized to JSON.
Sourcepub fn get<T>(&self) -> Option<T>where
T: ExtensionKey + DeserializeOwned,
pub fn get<T>(&self) -> Option<T>where
T: ExtensionKey + DeserializeOwned,
Retrieves and deserializes an extension value by its type.
The lookup key is taken from T::EXTENSION_KEY (see ExtensionKey).
Returns None if the key is absent or if deserialization fails.
§Type Parameters
T– Must implement bothExtensionKey(to provide the key) andserde::de::DeserializeOwned(to decode the stored JSON value).
Trait Implementations§
Source§impl Clone for ExtensionsJson
impl Clone for ExtensionsJson
Source§fn clone(&self) -> ExtensionsJson
fn clone(&self) -> ExtensionsJson
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 ExtensionsJson
impl Debug for ExtensionsJson
Source§impl Default for ExtensionsJson
impl Default for ExtensionsJson
Source§fn default() -> ExtensionsJson
fn default() -> ExtensionsJson
Source§impl<'de> Deserialize<'de> for ExtensionsJson
impl<'de> Deserialize<'de> for ExtensionsJson
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<ExtensionsJson> for Value
impl From<ExtensionsJson> for Value
Source§fn from(value: ExtensionsJson) -> Self
fn from(value: ExtensionsJson) -> Self
Source§impl FromIterator<(String, Value)> for ExtensionsJson
impl FromIterator<(String, Value)> for ExtensionsJson
Source§fn from_iter<I: IntoIterator<Item = (String, Value)>>(iter: I) -> Self
fn from_iter<I: IntoIterator<Item = (String, Value)>>(iter: I) -> Self
Collects an iterator of (key, value) pairs into an ExtensionsJson.
Values must already be serde_json::Values. To build from
serializable types, serialize each value with serde_json::to_value
before collecting, handling any errors at the call site.