prost_types/
lib.rs

1#![doc(html_root_url = "https://docs.rs/prost-types/0.13.5")]
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//! - `arbitrary`: Enable integration with crate `arbitrary`. All types on this crate will implement `trait Arbitrary`.
39//!
40//! [1]: https://developers.google.com/protocol-buffers/docs/reference/google.protobuf
41
42#![cfg_attr(not(feature = "std"), no_std)]
43
44#[rustfmt::skip]
45pub mod compiler;
46mod datetime;
47#[rustfmt::skip]
48mod protobuf;
49
50use core::convert::TryFrom;
51use core::fmt;
52use core::str::FromStr;
53use core::time;
54
55use prost::alloc::format;
56use prost::alloc::string::String;
57use prost::alloc::vec::Vec;
58use prost::{DecodeError, EncodeError, Message, Name};
59
60pub use protobuf::*;
61
62// The Protobuf `Duration` and `Timestamp` types can't delegate to the standard library equivalents
63// because the Protobuf versions are signed. To make them easier to work with, `From` conversions
64// are defined in both directions.
65
66const NANOS_PER_SECOND: i32 = 1_000_000_000;
67const NANOS_MAX: i32 = NANOS_PER_SECOND - 1;
68
69const PACKAGE: &str = "google.protobuf";
70
71mod any;
72
73mod duration;
74pub use duration::DurationError;
75
76mod timestamp;
77pub use timestamp::TimestampError;
78
79mod type_url;
80pub(crate) use type_url::{type_url_for, TypeUrl};
81
82mod conversions;