Skip to main content
Bomboni provides two complementary crates for working with Protocol Buffers in Rust: bomboni_prost for code generation and bomboni_proto for enhanced runtime types.

Architecture

Bomboni’s protobuf support is split into two main components:

bomboni_prost

Build-time code generation with enhanced helpers and utilities

bomboni_proto

Runtime implementations of Google’s well-known types with additional functionality

When to Use Each Crate

bomboni_prost

Use bomboni_prost in your build.rs file when you need to:
  • Compile .proto files into Rust code
  • Generate additional helper functions for messages and enums
  • Add field name constants and utilities
  • Enable serde serialization for protobuf types
  • Map protobuf types to custom Rust implementations
build.rs
use bomboni_prost::{compile, config::CompileConfig};

fn main() {
    let config = CompileConfig {
        file_descriptor_set_path: "descriptor.bin".into(),
        output_path: "src/generated".into(),
        format: true,
        ..Default::default()
    };
    
    compile(config).unwrap();
}

bomboni_proto

Use bomboni_proto in your runtime code when you need:
  • Enhanced implementations of Google’s well-known types
  • Any type conversions with automatic type URL handling
  • RPC status and error handling with detailed error types
  • Field mask operations and utilities
  • Serde serialization for protobuf well-known types
use bomboni_proto::google::protobuf::Any;
use bomboni_proto::google::rpc::{Status, Code, ErrorInfo};

// Use enhanced Any type conversions
let error = ErrorInfo {
    reason: "INVALID_ARGUMENT".to_string(),
    domain: "my.api".to_string(),
    metadata: Default::default(),
};

let any_msg = Any::from_msg(&error).unwrap();

Integration with Tonic

Bomboni seamlessly integrates with tonic, the popular Rust gRPC framework.

Build-time Integration

Use bomboni_prost alongside tonic’s build tools:
build.rs
use bomboni_prost::{compile, config::CompileConfig};

fn main() {
    // First, use tonic-build to compile your proto files
    tonic_build::configure()
        .file_descriptor_set_path("descriptor.bin")
        .compile(&["proto/api.proto"], &["proto"])
        .unwrap();
    
    // Then use bomboni_prost to generate enhanced helpers
    let config = CompileConfig {
        file_descriptor_set_path: "descriptor.bin".into(),
        output_path: "src/generated".into(),
        format: true,
        ..Default::default()
    };
    
    compile(config).unwrap();
}

Runtime Integration

With the tonic feature enabled, bomboni_proto provides automatic conversions between Bomboni’s Status type and tonic’s Status:
use bomboni_proto::google::rpc::{Status, Code, BadRequest, bad_request::FieldViolation};
use bomboni_proto::google::protobuf::Any;

// Create a detailed error status
let bad_request = BadRequest {
    field_violations: vec![
        FieldViolation {
            field: "email".to_string(),
            description: "Invalid email format".to_string(),
        }
    ],
};

let status = Status::new(
    Code::InvalidArgument,
    "Invalid request parameters".to_string(),
    vec![Any::from_msg(&bad_request).unwrap()],
);

// Convert to tonic::Status for returning from gRPC handlers
let tonic_status: tonic::Status = status.try_into().unwrap();

Key Features

bomboni_prost generates additional helper functions beyond standard prost output:
  • Field name constants for reflection
  • Enum value name arrays
  • Oneof variant utilities
  • Automatic From/Into conversions
Comprehensive serialization support for all generated types:
  • Automatic Serialize/Deserialize implementations
  • Custom serde helpers for enum fields
  • Proper handling of protobuf conventions in JSON
bomboni_proto provides enhanced implementations:
  • Any type with easy conversions
  • Status with rich error details
  • FieldMask with path operations
  • Timestamp, Duration, and wrapper types
Strong type safety throughout:
  • Compile-time guarantees for type URLs
  • Safe enum conversions
  • Type-checked field masks

Cargo Features

bomboni_proto Features

  • tonic - Enable tonic integration with Status conversions
  • chrono - Enable compatibility with chrono datetime library
  • wasm - Enable WebAssembly support
  • js - Enable JavaScript-specific type mappings
  • testing - Enable testing utilities
Cargo.toml
[dependencies]
bomboni_proto = { version = "0.1", features = ["tonic", "chrono"] }

Next Steps

Code Generation

Learn about the code generation process and generated helpers

Well-Known Types

Explore enhanced Protocol Buffer types

Build docs developers (and LLMs) love