prost_types/lib.rs
1#![doc(html_root_url = "https://docs.rs/prost-types/0.13.4")]
2
3//! Protocol Buffers well-known types.
4//!
5//! Note that the documentation for the types defined in this crate are generated from the Protobuf
6//! definitions, so code examples are not in Rust.
7//!
8//! See the [Protobuf reference][1] for more information about well-known types.
9//!
10//! ## Any
11//!
12//! The well-known [`Any`] type contains an arbitrary serialized message along with a URL that
13//! describes the type of the serialized message. Every message that also implements [`Name`]
14//! can be serialized to and deserialized from [`Any`].
15//!
16//! ### Serialization
17//!
18//! A message can be serialized using [`Any::from_msg`].
19//!
20//! ```rust
21//! let message = Timestamp::date(2000, 1, 1).unwrap();
22//! let any = Any::from_msg(&message).unwrap();
23//! ```
24//!
25//! ### Deserialization
26//!
27//! A message can be deserialized using [`Any::to_msg`].
28//!
29//! ```rust
30//! # let message = Timestamp::date(2000, 1, 1).unwrap();
31//! # let any = Any::from_msg(&message).unwrap();
32//! #
33//! let message = any.to_msg::<Timestamp>().unwrap();
34//! ```
35//!
36//! ## Feature Flags
37//! - `std`: Enable integration with standard library. Disable this feature for `no_std` support. This feature is enabled by default.
38//!
39//! [1]: https://developers.google.com/protocol-buffers/docs/reference/google.protobuf
40
41#![cfg_attr(not(feature = "std"), no_std)]
42
43#[rustfmt::skip]
44pub mod compiler;
45mod datetime;
46#[rustfmt::skip]
47mod protobuf;
48
49use core::convert::TryFrom;
50use core::fmt;
51use core::str::FromStr;
52use core::time;
53
54use prost::alloc::format;
55use prost::alloc::string::String;
56use prost::alloc::vec::Vec;
57use prost::{DecodeError, EncodeError, Message, Name};
58
59pub use protobuf::*;
60
61// The Protobuf `Duration` and `Timestamp` types can't delegate to the standard library equivalents
62// because the Protobuf versions are signed. To make them easier to work with, `From` conversions
63// are defined in both directions.
64
65const NANOS_PER_SECOND: i32 = 1_000_000_000;
66const NANOS_MAX: i32 = NANOS_PER_SECOND - 1;
67
68const PACKAGE: &str = "google.protobuf";
69
70mod any;
71
72mod duration;
73pub use duration::DurationError;
74
75mod timestamp;
76pub use timestamp::TimestampError;
77
78mod type_url;
79pub(crate) use type_url::{type_url_for, TypeUrl};
80
81mod conversions;