From 0b9a0f939e9e533bb34b2a1f3917c945dd5337e6 Mon Sep 17 00:00:00 2001 From: Casper Meijn Date: Thu, 29 Aug 2024 14:52:55 +0200 Subject: [PATCH] docs(prost-types): Add description of using Any --- prost-types/src/lib.rs | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/prost-types/src/lib.rs b/prost-types/src/lib.rs index c7c81b5a8..bfe5b0be0 100644 --- a/prost-types/src/lib.rs +++ b/prost-types/src/lib.rs @@ -7,6 +7,32 @@ //! //! See the [Protobuf reference][1] for more information about well-known types. //! +//! ## Any +//! +//! The well-known [`Any`] type contains an arbitrary serialized message along with a URL that +//! describes the type of the serialized message. Every message that also implements [`Name`] +//! can be serialized to and deserialized from [`Any`]. +//! +//! ### Serialization +//! +//! A message can be serialized using [`Any::from_msg`]. +//! +//! ```rust +//! let message = Timestamp::date(2000, 1, 1).unwrap(); +//! let any = Any::from_msg(&message).unwrap(); +//! ``` +//! +//! ### Deserialization +//! +//! A message can be deserialized using [`Any::to_msg`]. +//! +//! ```rust +//! # let message = Timestamp::date(2000, 1, 1).unwrap(); +//! # let any = Any::from_msg(&message).unwrap(); +//! # +//! let message = any.to_msg::().unwrap(); +//! ``` +//! //! ## Feature Flags //! - `std`: Enable integration with standard library. Disable this feature for `no_std` support. This feature is enabled by default. //!