Expand description
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 following features can also enable a variety of automatically derived implementations:
cel(TryIntocel::Value)serde(Serialize,Deserialize)diesel(FromSql,ToSql,FromSqlRow,QueryId,AsExpression)- The diesel backend must be specified in the feature (i.e. diesel-postgres, diesel-sqlite, diesel-mysql)
In addition, the types from the google packages come with the 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
Intervaland to/fromchrono::TimeDelta - Helpers for the extraction of units (seconds, minutes, etc) and formatting
Timestamp- Ord, PartialOrd
- Display
- Add, Sub (with Duration)
- Custom formatting with chrono syntax (requires the
chronofeature) - Conversions to/from
std::time::SystemTimeandchrono::DateTime
FieldMask- Display
EmptyAny
Β§π google.type
All of these can be included with the all_common flag, or selected individually with their respective flag.
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::DateTimewithchrono::FixedOffsetorchrono::Utc(andchrono::DateTimewithchrono_tz::Tzwith thechrono-tzfeature)
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 thepalettefeature)
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
kindfield from beingNone) - Validator (checks presence of required
kindfield)
- Constructor with validation check (prevents the
QuaternionLocalizedTextExprCalendarPeriodMonthDayOfWeek
Β§π» google.rpc
Available by default:
Enabled with the rpc flag:
ErrorInfoDebugInfoRetryInfoQuotaFailurequota_failure::ViolationPreconditionFailureprecondition_failure::ViolationBadRequestbad_request::FieldViolationRequestInfoResourceInfoHelphelp::LinkLocalizedMessageHttpRequestHttpResponseHttpHeader
Β§π License
This repository is licensed under the MPL-2.0 license, unless otherwise indicated.
The file CREDITS.md contains the details of the external code (and relevant licenses) used in this project.
Β§Feature flags
chrono-wasmβ Enables the now() methods for chrono in a wasm environmentstd(enabled by default) β Enables the standard library featurescelβ Enables conversions into cel::Value.serdeβ Enables serde implementations.protovalidateβ Enables implementations for the buf.validate messages and enums.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 thepalettecrate 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.
Re-exportsΒ§
ModulesΒ§
- cel
cel - Implementations to allow conversion from well known types to
cel::Value - common
- 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. - generated_
code_ info - Nested message and enum types in
GeneratedCodeInfo. - method_
options - Nested message and enum types in
MethodOptions. - num_
wrappers - Struct wrappers for protobuf-specific numeric types such as
sint32orfixed64. - protovalidate
protovalidate - Generated rust code from buf.validate protobuf package, with some added methods and structs.
- rpc
- source_
code_ info - Nested message and enum types in
SourceCodeInfo. - timestamp
- uninterpreted_
option - Nested message and enum types in
UninterpretedOption. - value
- Nested message and enum types in
Value.
StructsΒ§
- Any
Anycontains 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.
- Bool
Value - Wrapper message for
bool. - Bytes
Value - Wrapper message for
bytes. - 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.
- Empty
- A generic empty message that you can re-use to avoid defining duplicated empty messages in your APIs.
- 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 - Extension
Range Options - Field
- A single field of a message type.
- Field
Descriptor Proto - Describes a field within a message.
- Field
Mask FieldMaskrepresents 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.
- Float
Value - Wrapper message for
float. - Generated
Code Info - Describes the relationship between generated code and its original source file.
- Int32
Value - Wrapper message for
int32. - Int64
Value - Wrapper message for
int64. - List
Value ListValueis a wrapper around a repeated field of values.- 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:
- Oneof
Descriptor Proto - Describes a oneof.
- Oneof
Options - Option
- A protocol buffer option, which can be attached to a message, field, enumeration, etc.
- 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 SourceContextrepresents information about the source of a protobuf element, like the file in which it is defined.- String
Value - Wrapper message for
string. - Struct
Structrepresents a structured data value, consisting of fields which map to dynamically typed values.- 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.
- 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.
- Value
Valuerepresents a dynamically typed value which can be either null, a number, a string, a boolean, a recursive struct value, or a list of values.
EnumsΒ§
- Field
Type - This is an enhanced enum for protobuf types, which allows precise identification for well known types such as Any, Timestamp or Duration. It is non-exhaustive because other well known types can be added in the future, but it is safe to assume that any non matching variant will be of the generic
Messagetype. - Null
Value NullValueis a singleton enumeration to represent the null value for theValuetype union.- Syntax
- The syntax in which a protocol buffer element is defined.