prost_types/
lib.rs

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