From 96c40d77006974cfc59947a03372e0ccd2ea3589 Mon Sep 17 00:00:00 2001 From: Casper Meijn Date: Fri, 30 Aug 2024 21:16:04 +0200 Subject: [PATCH] docs(prost-types): Add description of using Any (#1141) --- 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 369292bc8..ff3ec51bd 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. //!