pub struct Any<E: EncodingMarker = AnyEncoding> { /* private fields */ }Expand description
Represents a serialized value, wrapping the underlying serialization and deserialization details, while ensuring that we pass correctly-serialized message throughout the system.
The default Any spelling is encoding-agnostic. Use Any with an
encoding marker, such as Any<encoding::Multipart>, when an API
requires a specific encoding.
Implementations§
Source§impl Any
impl Any
Sourcepub fn serialize_with_encoding<T: Serialize + Named>(
encoding: Encoding,
value: &T,
) -> Result<Self>
pub fn serialize_with_encoding<T: Serialize + Named>( encoding: Encoding, value: &T, ) -> Result<Self>
Serialize the value with the using the provided encoding.
Sourcepub fn serialize_with_encoding_as<T: Named, U: Serialize>(
encoding: Encoding,
value: &U,
) -> Result<Self>
pub fn serialize_with_encoding_as<T: Named, U: Serialize>( encoding: Encoding, value: &U, ) -> Result<Self>
Serialize U-typed value as a T-typed value. This should be used with care (typically only in testing), as the value’s representation may be illegally coerced.
Sourcepub fn new_broken() -> Self
pub fn new_broken() -> Self
Create a new broken Any value. A broken value has unknown type and no valid data. Attempting to deserialize a broken value will fail.
Sourcepub fn try_into_static_encoding<E: StaticEncoding>(self) -> Result<Any<E>, Self>
pub fn try_into_static_encoding<E: StaticEncoding>(self) -> Result<Any<E>, Self>
Statically constrain this value to the requested encoding.
Sourcepub fn try_into_bincode(self) -> Result<Any<Bincode>, Self>
pub fn try_into_bincode(self) -> Result<Any<Bincode>, Self>
Statically constrain this value to bincode encoding.
Sourcepub fn try_into_json(self) -> Result<Any<Json>, Self>
pub fn try_into_json(self) -> Result<Any<Json>, Self>
Statically constrain this value to JSON encoding.
Sourcepub fn try_into_multipart(self) -> Result<Any<Multipart>, Self>
pub fn try_into_multipart(self) -> Result<Any<Multipart>, Self>
Statically constrain this value to multipart encoding.
Source§impl<E: EncodingMarker> Any<E>
impl<E: EncodingMarker> Any<E>
Sourcepub fn serialize<T: Serialize + Named>(value: &T) -> Result<Self>
pub fn serialize<T: Serialize + Named>(value: &T) -> Result<Self>
Construct a new serialized value.
Encoding-agnostic Any uses config::DEFAULT_ENCODING. Statically
constrained values, such as Any<encoding::Multipart>, use their static
encoding.
Sourcepub fn serialize_as<T: Named, U: Serialize>(value: &U) -> Result<Self>
pub fn serialize_as<T: Named, U: Serialize>(value: &U) -> Result<Self>
Serialize U-typed value as a T-typed value.
Sourcepub fn erase_encoding(self) -> Any
pub fn erase_encoding(self) -> Any
Erase this value’s static encoding marker.
Sourcepub fn deserialized<T: DeserializeOwned + Named>(&self) -> Result<T>
pub fn deserialized<T: DeserializeOwned + Named>(&self) -> Result<T>
Deserialize a value to the provided type T.
Sourcepub fn deserialized_unchecked<T: DeserializeOwned>(&self) -> Result<T>
pub fn deserialized_unchecked<T: DeserializeOwned>(&self) -> Result<T>
Deserialize a value to the provided type T, without checking for type conformance. This should be used carefully, only when you know that the dynamic type check is not needed.
Sourcepub fn transcode_to_json(self) -> Result<Any<Json>, Self>
pub fn transcode_to_json(self) -> Result<Any<Json>, Self>
Transcode the serialized value to JSON. This operation will succeed if the type hash is embedded in the value, and the corresponding type is available in this binary.
Sourcepub fn dump(&self) -> Result<Value>
pub fn dump(&self) -> Result<Value>
Dump the Any message into a JSON value. This will succeed if: 1) the typehash is embedded in the serialized value; 2) the named type is linked into the binary.
Sourcepub fn typename(&self) -> Option<&'static str>
pub fn typename(&self) -> Option<&'static str>
The typename of the serialized value, if available.
Sourcepub fn prefix<T: DeserializeOwned>(&self) -> Result<T>
pub fn prefix<T: DeserializeOwned>(&self) -> Result<T>
Deserialize a prefix of the value. This is currently only supported for bincode-serialized values.
Sourcepub fn emplace_prefix<T: Serialize + DeserializeOwned>(
&mut self,
prefix: T,
) -> Result<()>
pub fn emplace_prefix<T: Serialize + DeserializeOwned>( &mut self, prefix: T, ) -> Result<()>
Emplace a new prefix to this value. This is currently only supported for bincode-serialized values.
Trait Implementations§
Source§impl<'de, E: EncodingMarker> Deserialize<'de> for Any<E>
impl<'de, E: EncodingMarker> Deserialize<'de> for Any<E>
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<E: EncodingMarker> Display for Any<E>
impl<E: EncodingMarker> Display for Any<E>
Source§impl<E: EncodingMarker> Serialize for Any<E>
impl<E: EncodingMarker> Serialize for Any<E>
impl<E: EncodingMarker> StructuralPartialEq for Any<E>
Auto Trait Implementations§
impl<E = AnyEncoding> !Freeze for Any<E>
impl<E> RefUnwindSafe for Any<E>where
E: RefUnwindSafe,
impl<E> Send for Any<E>where
E: Send,
impl<E> Sync for Any<E>where
E: Sync,
impl<E> Unpin for Any<E>where
E: Unpin,
impl<E> UnsafeUnpin for Any<E>
impl<E> UnwindSafe for Any<E>where
E: UnwindSafe,
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more