Expand description
Β§π§© Implementations for common protobuf types
This crate provides implementations for several well known protobuf types, such as those from google.protobuf
, google.rpc
and google.type
, plus some implementations for buf.validate
which are used by protocheck.
You can use feature flags to selectively include the implementations that youβre interested in.
Β§ποΈ List of implementations
Each struct/enum includes the default impls from prost such as Clone, Debug and so on.
The types coming from the google packages all have serde::Serialize
and serde::Deserialize
implementations when the serde
feature flag is activated, and they also have From/TryFrom implementations for cel::Value
when the cel
feature is enabled.
Each type comes with implementations listed below, plus a variety of utility methods and helpers that can be found in the documentation.
All of the structs that have fallible methods also come with their own custom error enum.
Β§π google.protobuf
Duration
- Ord, PartialOrd
- Display
- Add, Sub (between durations)
- Mul, Div (with integers)
- Conversions from
Interval
and to/fromchrono::TimeDelta
- Helpers for the extraction of units (seconds, minutes, etc) and formatting
- ToTokens (optional)
Timestamp
- Ord, PartialOrd
- Display
- Add, Sub (with Duration)
- Custom formatting with chrono syntax (requires the
chrono
feature) - Conversions to/from
std::time::SystemTime
andchrono::DateTime
- ToTokens (optional)
FieldMask
- Display
Empty
Any
Β§π google.type
TimeOfDay
- Constructor with validation check
- Display
- Ord, PartialOrd
- Conversions to/from
chrono::NaiveTime
Date
- Constructor with validation check
- Display
- PartialOrd
- Conversions to/from
chrono::NaiveDate
DateTime
- Constructor with validation check
- Display
- PartialOrd
- Conversions to/from
chrono::NaiveDateTime
,chrono::DateTime
withchrono::FixedOffset
orchrono::Utc
(andchrono::DateTime
withchrono_tz::Tz
with thechrono-tz
feature)
TimeZone
- Display
Interval
- Constructor with validation check
- PartialOrd
- Conversions to/from
Duration
Money
- Constructor with validation check
- PartialOrd
- Formatting helper
- Checked operations
- (Lossy) conversions to/from f64
Color
- Constructor with validation check
- Conversions to/from
palette::Srgba
(with thepalette
feature)
Fraction
- Constructor with validation check (for 0 denominator case)
- Display
- PartialOrd
- Checked operations
- Conversion to f64
Decimal
- Conversion to
rust_decimal::Decimal
- Conversion to
LatLng
- Constructor with validation check
- Display
PostalAddress
- Validator (checks presence of region_code)
PhoneNumber
- Constructor with validation check (prevents the
kind
field from beingNone
) - Validator (checks presence of required
kind
field)
- Constructor with validation check (prevents the
Quaternion
LocalizedText
Expr
CalendarPeriod
Month
DayOfWeek
Β§π» google.rpc
ErrorInfo
DebugInfo
RetryInfo
QuotaFailure
quota_failure::Violation
PreconditionFailure
precondition_failure::Violation
BadRequest
bad_request::FieldViolation
RequestInfo
ResourceInfo
Help
help::Link
LocalizedMessage
HttpRequest
HttpResponse
HttpHeader
Status
Code
Β§Feature flags
cel
β Enables conversions into cel::Value.serde
β Enables serde implementations.protovalidate
β Enables implementations for the buf.validate messages and enums.protocheck
β Used internally by protocheck.totokens
β Enables ToTokens implementations.chrono
(enabled by default) β Enables conversion to and from chrono types for the time-related structs.chrono-tz
β Enables timezone support for DateTime.all_common
β Enables all message types from the google.type package.rpc
β Enables all message types from the google.rpc package.decimal
β Enables support for the google.type.Decimal, with conversions to/from rust_decimal::Decimal.color
β Enables google.type.Color.palette
β Enables conversions to and from types from thepalette
crate for Color.date
β Enables google.type.Date.datetime
β Enables google.type.DateTime.timeofday
β Enables google.type.TimeOfDay.fraction
β Enables google.type.Fraction.money
β Enables google.type.Money.interval
β Enables google.type.Interval.localized_text
β Enables google.type.LocalizedText.postal_address
β Enables google.type.PostalAddress.quaternion
β Enables google.type.Quaternion.latlng
β Enables google.type.LatLng.expr
β Enables google.type.Expr.phone_number
β Enables google.type.PhoneNumber.
ModulesΒ§
- bad_
request rpc
- Nested message and enum types in
BadRequest
. - cel
cel
- Implementations to allow conversion from well known types to
cel::Value
- color
color
- Implementations for the google.type.Color message.
- date
date
- Implementations for the google.type.Date message.
- date_
time datetime
- Nested message and enum types in
DateTime
. - datetime
datetime
- Implementations for the google.type.DateTime message.
- decimal
decimal
- Implementations for the google.type.Decimal message.
- descriptor_
proto - Nested message and enum types in
DescriptorProto
. - duration
- Implementations and units for Duration structs.
- enum_
descriptor_ proto - Nested message and enum types in
EnumDescriptorProto
. - field
- Nested message and enum types in
Field
. - field_
descriptor_ proto - Nested message and enum types in
FieldDescriptorProto
. - field_
options - Nested message and enum types in
FieldOptions
. - file_
options - Nested message and enum types in
FileOptions
. - fraction
fraction
- Implementations for the google.type.Fraction message.
- generated_
code_ info - Nested message and enum types in
GeneratedCodeInfo
. - help
rpc
- Nested message and enum types in
Help
. - interval
interval
- Implementations for the google.type.Interval message.
- latlng
latlng
- Implementations for the google.type.LatLng message.
- method_
options - Nested message and enum types in
MethodOptions
. - money
money
- Implementations for the google.type.Money message. DISCLAIMER: all of the methods implemented for Money are just implemented for convenience, and they are provided as is, without warranties of any kind. By using this module, the user is relieving the authors of this library from any responsibility for any damage that may be caused by its usage.
- phone_
number phone_number
- Nested message and enum types in
PhoneNumber
. - precondition_
failure rpc
- Nested message and enum types in
PreconditionFailure
. - protovalidate
protovalidate
- Generated rust code from buf.validate protobuf package, with some added methods and structs.
- quota_
failure rpc
- Nested message and enum types in
QuotaFailure
. - source_
code_ info - Nested message and enum types in
SourceCodeInfo
. - time_
of_ day timeofday
- Implementations for the google.type.TimeOfDay message.
- timestamp
- uninterpreted_
option - Nested message and enum types in
UninterpretedOption
. - value
- Nested message and enum types in
Value
.
StructsΒ§
- Any
Any
contains an arbitrary serialized protocol buffer message along with a URL that describes the type of the serialized message.- Api
- Api is a light-weight descriptor for an API Interface.
- BadRequest
rpc
- Describes violations in a client request. This error type focuses on the syntactic aspects of the request.
- Bool
Value - Wrapper message for
bool
. - Bytes
Value - Wrapper message for
bytes
. - Color
color
- Represents a color in the RGBA color space. This representation is designed
for simplicity of conversion to/from color representations in various
languages over compactness. For example, the fields of this representation
can be trivially provided to the constructor of
java.awt.Color
in Java; it can also be trivially provided to UIColorβs+colorWithRed:green:blue:alpha
method in iOS; and, with just a little work, it can be easily formatted into a CSSrgba()
string in JavaScript. - Date
date
- Represents a whole or partial calendar date, such as a birthday. The time of day and time zone are either specified elsewhere or are insignificant. The date is relative to the Gregorian Calendar. This can represent one of the following:
- Date
Time datetime
- Represents civil time (or occasionally physical time).
- Debug
Info rpc
- Describes additional debugging info.
- Decimal
decimal
- A representation of a decimal value, such as 2.5. Clients may convert values into language-native decimal formats, such as Javaβs [BigDecimal][] or Pythonβs [decimal.Decimal][].
- Descriptor
Proto - Describes a message type.
- Double
Value - Wrapper message for
double
. - Duration
- A Duration represents a signed, fixed-length span of time represented as a count of seconds and fractions of seconds at nanosecond resolution. It is independent of any calendar and concepts like βdayβ or βmonthβ. It is related to Timestamp in that the difference between two Timestamp values is a Duration and it can be added or subtracted from a Timestamp. Range is approximately +-10,000 years.
- Empty
- A generic empty message that you can re-use to avoid defining duplicated empty messages in your APIs. A typical example is to use it as the request or the response type of an API method. For instance:
- Enum
- Enum type definition.
- Enum
Descriptor Proto - Describes an enum type.
- Enum
Options - Enum
Value - Enum value definition.
- Enum
Value Descriptor Proto - Describes a value within an enum.
- Enum
Value Options - Error
Info rpc
- Describes the cause of the error with structured details.
- Expr
expr
- Represents a textual expression in the Common Expression Language (CEL) syntax. CEL is a C-like expression language. The syntax and semantics of CEL are documented at https://github.com/google/cel-spec.
- Extension
Range Options - Field
- A single field of a message type.
- Field
Descriptor Proto - Describes a field within a message.
- Field
Mask FieldMask
represents a set of symbolic field paths, for example:- Field
Options - File
Descriptor Proto - Describes a complete .proto file.
- File
Descriptor Set - The protocol compiler can output a FileDescriptorSet containing the .proto files it parses.
- File
Options - Each of the definitions above may have βoptionsβ attached. These are just annotations which may cause code to be generated slightly differently or may contain hints for code that manipulates protocol messages.
- Float
Value - Wrapper message for
float
. - Fraction
fraction
- Represents a fraction in terms of a numerator divided by a denominator.
- Generated
Code Info - Describes the relationship between generated code and its original source file. A GeneratedCodeInfo message is associated with only one generated source file, but may contain references to different source .proto files.
- Help
rpc
- Provides links to documentation or for performing an out of band action.
- Http
Header rpc
- Represents an HTTP header.
- Http
Request rpc
- Represents an HTTP request.
- Http
Response rpc
- Represents an HTTP response.
- Int32
Value - Wrapper message for
int32
. - Int64
Value - Wrapper message for
int64
. - Interval
interval
- Represents a time interval, encoded as a Timestamp start (inclusive) and a Timestamp end (exclusive).
- LatLng
latlng
- An object that represents a latitude/longitude pair. This is expressed as a pair of doubles to represent degrees latitude and degrees longitude. Unless specified otherwise, this must conform to the WGS84> standard. Values must be within normalized ranges.
- List
Value ListValue
is a wrapper around a repeated field of values.- Localized
Message rpc
- Provides a localized error message that is safe to return to the user which can be attached to an RPC error.
- Localized
Text localized_text
- Localized variant of a text in a particular language.
- Message
Options - Method
- Method represents a method of an API interface.
- Method
Descriptor Proto - Describes a method of a service.
- Method
Options - Mixin
- Declares an API Interface to be included in this interface. The including interface must redeclare all the methods from the included interface, but documentation and options are inherited as follows:
- Money
money
- Represents an amount of money with its currency type.
- Oneof
Descriptor Proto - Describes a oneof.
- Oneof
Options - Option
- A protocol buffer option, which can be attached to a message, field, enumeration, etc.
- Phone
Number phone_number
- An object representing a phone number, suitable as an API wire format.
- Postal
Address postal_address
- Represents a postal address, e.g. for postal delivery or payments addresses. Given a postal address, a postal service can deliver items to a premise, P.O. Box or similar. It is not intended to model geographical locations (roads, towns, mountains).
- Precondition
Failure rpc
- Describes what preconditions have failed.
- Quaternion
quaternion
- A quaternion is defined as the quotient of two directed lines in a three-dimensional space or equivalently as the quotient of two Euclidean vectors (https://en.wikipedia.org/wiki/Quaternion).
- Quota
Failure rpc
- Describes how a quota check failed.
- Request
Info rpc
- Contains metadata about the request that clients can attach when filing a bug or providing other forms of feedback.
- Resource
Info rpc
- Describes the resource that is being accessed.
- Retry
Info rpc
- Describes when the clients can retry a failed request. Clients could ignore the recommendation here or retry when this information is missing from error responses.
- Service
Descriptor Proto - Describes a service.
- Service
Options - Source
Code Info - Encapsulates information about the original source file from which a FileDescriptorProto was generated.
- Source
Context SourceContext
represents information about the source of a protobuf element, like the file in which it is defined.- Status
rpc
- The
Status
type defines a logical error model that is suitable for different programming environments, including REST APIs and RPC APIs. It is used by gRPC. EachStatus
message contains three pieces of data: error code, error message, and error details. - String
Value - Wrapper message for
string
. - Struct
Struct
represents a structured data value, consisting of fields which map to dynamically typed values. In some languages,Struct
might be supported by a native representation. For example, in scripting languages like JS a struct is represented as an object. The details of that representation are described together with the proto support for the language.- Time
OfDay timeofday
- Represents a time of day. The date and time zone are either not significant
or are specified elsewhere. An API may choose to allow leap seconds. Related
types are [google.type.Date][google.type.Date] and
google.protobuf.Timestamp
. - Time
Zone datetime
- Represents a time zone from the IANA Time Zone Database.
- Timestamp
- A Timestamp represents a point in time independent of any time zone or local calendar, encoded as a count of seconds and fractions of seconds at nanosecond resolution. The count is relative to an epoch at UTC midnight on January 1, 1970, in the proleptic Gregorian calendar which extends the Gregorian calendar backwards to year one.
- Type
- A protocol buffer message type.
- UInt32
Value - Wrapper message for
uint32
. - UInt64
Value - Wrapper message for
uint64
. - Uninterpreted
Option - A message representing a option the parser does not recognize. This only appears in options protos created by the compiler::Parser class. DescriptorPool resolves these when building Descriptor objects. Therefore, options protos in descriptor objects (e.g. returned by Descriptor::options(), or produced by Descriptor::CopyTo()) will never have UninterpretedOptions in them.
- Value
Value
represents a dynamically typed value which can be either null, a number, a string, a boolean, a recursive struct value, or a list of values. A producer of value is expected to set one of these variants. Absence of any variant indicates an error.
EnumsΒ§
- Calendar
Period - A
CalendarPeriod
represents the abstract concept of a time period that has a canonical start. Grammatically, βthe start of the currentCalendarPeriod
.β All calendar times begin at midnight UTC. - Code
rpc
- The canonical error codes for gRPC APIs.
- DayOf
Week - Represents a day of the week.
- Field
Type - An enhanced enum for protobuf types, allowing you to identify well known types such as Any, Timestamp or Duration
- Month
- Represents a month in the Gregorian calendar.
- Null
Value NullValue
is a singleton enumeration to represent the null value for theValue
type union.- Syntax
- The syntax in which a protocol buffer element is defined.