bomboni_proto crate provides enhanced versions of Google’s protobuf types with additional conversion methods, serde support, and integrations with popular Rust libraries.
google::protobuf Types
Any
Represents any protobuf message type.Methods
Creates a new
Any message with the given type URL and value.Converts a protobuf message to an
Any message.Returns: Result<Any, EncodeError> - Encoded Any message or encoding errorConverts an
Any message back to the original protobuf message.Returns: Result<T, DecodeError> - Decoded message or error if type URL doesn’t matchMacros
impl_proto_any_convert! - ImplementsTryFrom conversions between messages and Any:
Any with type-based dispatch:
Any:
Timestamp
Represents a point in time.Methods
Creates a new
Timestamp with the given seconds and nanoseconds.Returns a normalized canonical format of the timestamp.Ensures nanos are in the range [0, 999999999] and handles overflow/underflow.
Conversions
Converts from
bomboni_common::UtcDateTimeConverts to
bomboni_common::UtcDateTimeConverts from
std::time::SystemTimeWhen the
chrono feature is enabled:TryFrom<Timestamp>forDateTime<Utc>From<DateTime<Utc>>forTimestampTryFrom<Timestamp>forNaiveDateTimeFrom<NaiveDateTime>forTimestamp
String Format
Formats as RFC3339 string (e.g.,
"1970-01-01T00:00:10.000000002Z")Parses from RFC3339 string format
Serde
Timestamp automatically serializes/deserializes as RFC3339 strings.Duration
Represents a time span.Methods
Creates a new
Duration with the given seconds and nanoseconds.Returns a normalized canonical format of the duration.Ensures nanos have the same sign as seconds and are in the valid range.
Conversions
Converts from standard library Duration (only positive durations)
Converts to standard library Duration (fails for negative durations)
Converts from
time crate DurationWhen the
chrono feature is enabled:TryFrom<chrono::Duration>forDurationTryFrom<Duration>forchrono::Duration
String Format
Formats as string with ‘s’ suffix (e.g.,
"10.000000002s")Parses from string format (e.g.,
"10.5s")FieldMask
Represents a field mask for partial updates.Methods
Creates a new field mask with the given paths.
Checks if this field mask contains the exact given path.
Checks if this field mask masks the given field path.Returns true if any path in the mask is a prefix of the field path.
Conversions
Creates a FieldMask from any iterator of string-like items.Example:
Serde
FieldMask serializes as a comma-separated string (e.g.,"user.name,user.email").
Empty
Represents an empty message.Creates a new empty message.
Struct and Value
Dynamic JSON-like structures.Struct Methods
Creates a new struct with the given fields.
Conversions
Converts from JSON Value (must be an object)
Converts to JSON Value
Creates Struct from map of Values
Creates Struct from map of JSON Values
Value Conversions
Converts JSON values to protobuf Values
Converts protobuf Values to JSON
Wrappers
Wrapper types for primitive values:StringValue, Int32Value, Int64Value, UInt32Value, UInt64Value, FloatValue, DoubleValue, BoolValue, BytesValue.
Conversions
All wrappers implementFrom and Into for their corresponding primitive types:
String Parsing
Numeric wrappers implementFromStr:
Display
All wrappers implementDisplay for easy formatting.
google::rpc Types
Status
Represents an RPC status with code, message, and details.Methods
Creates a new Status with the given code, message, and error details.
Tonic Integration
When thetonic feature is enabled:
Converts from tonic Status, decoding the details
Converts to tonic Status, encoding the details
Serde Helpers
detail_serde module - For single Any details:Code
RPC status codes enum. Supported codes:Ok(0)Cancelled(1)Unknown(2)InvalidArgument(3)DeadlineExceeded(4)NotFound(5)AlreadyExists(6)PermissionDenied(7)ResourceExhausted(8)FailedPrecondition(9)Aborted(10)OutOfRange(11)Unimplemented(12)Internal(13)Unavailable(14)DataLoss(15)Unauthenticated(16)
Methods
Converts RPC code to HTTP status code following Google API design guidelines.Mappings:
InvalidArgument,FailedPrecondition,OutOfRange→ 400 BAD_REQUESTUnauthenticated→ 401 UNAUTHORIZEDPermissionDenied→ 403 FORBIDDENNotFound→ 404 NOT_FOUNDAborted,AlreadyExists→ 409 CONFLICTResourceExhausted→ 429 TOO_MANY_REQUESTSCancelled→ 499- Others → 500 INTERNAL_SERVER_ERROR
Tonic Integration
When thetonic feature is enabled:
Converts from tonic Code
Converts to tonic Code
Error Detail Types
The following error detail types support conversion to/fromAny:
- ErrorInfo - Additional error information with reason, domain, and metadata
- RetryInfo - Information about when to retry
- DebugInfo - Debug information with stack trace and detail
- QuotaFailure - Quota violation details
- PreconditionFailure - Precondition failure details
- BadRequest - Bad request field violations
- RequestInfo - Request metadata
- ResourceInfo - Resource information
- Help - Help links
- LocalizedMessage - Localized error messages
TryFrom conversions with Any: