Skip to main content

GenerationConfig

Struct GenerationConfig 

Source
pub struct GenerationConfig { /* private fields */ }
Expand description

Options that shape generated Rust codecs.

Start with GenerationConfig::new, chain builder methods, then pass to crate::Generator::new.

use ergo_sbe::{DomainVarData, GenerationConfig, ConversionSelector};

let config = GenerationConfig::new("market_data")
    .with_domain_objects(DomainVarData::Strings)
    .with_domain_type(
        ConversionSelector::named_type("Decimal"),
        "rust_decimal::Decimal",
    );

Implementations§

Source§

impl GenerationConfig

Source

pub fn new(module_name: impl Into<String>) -> Self

Create a config for output module {module_name}.rs with GenerationProfile::Full defaults.

use ergo_sbe::GenerationConfig;
let c = GenerationConfig::new("msgs");
Source

pub fn lean(module_name: impl Into<String>) -> Self

Create a config with GenerationProfile::Lean defaults (no Display/Debug, no meta attributes, no dispatch, no domain objects).

Equivalent to GenerationConfig::new(name).profile(GenerationProfile::Lean) but more direct. Explicit with_* settings (conversions, domain types, auto-bool) can be added after — they are not cleared.

use ergo_sbe::GenerationConfig;
let c = GenerationConfig::lean("minimal");
Source

pub fn with_module_name(self, name: impl Into<String>) -> Self

Override the module name set in new. Use when cloning a base config across several schemas — set the placeholder in new, then call .clone().with_module_name("orderbook") on each.

use ergo_sbe::GenerationConfig;
let base = GenerationConfig::new("_");
let a = base.clone().with_module_name("md");
let b = base.clone().with_module_name("ob");
// `a` generates `md.rs`, `b` generates `ob.rs`, `base` unchanged.
Source

pub fn with_external_sbe_rt(self, path: impl Into<String>) -> Self

Re-use one sbe_rt runtime across separately generated schema modules.

path must work in pub use <path> as sbe_rt;.

// first module embeds sbe_rt; later modules do:
// pub use crate::common::sbe_rt as sbe_rt;
GenerationConfig::new("md")
    .with_external_sbe_rt("crate::common::sbe_rt");
Source

pub fn with_conversion(self, selector: ConversionSelector) -> Self

Enable generic conversion methods for matching fields.

§Generated API

In build.rs: .with_conversion(ConversionSelector::named_type("Decimal")). Application code: enc.price_from(&my_price)?; / dec.price_as::<MyPrice>()?.

§Example
use ergo_sbe::{GenerationConfig, ConversionSelector};

let config = GenerationConfig::new("msgs")
    .with_conversion(ConversionSelector::named_type("Decimal"));

sbe/tests/comprehensive_test.rs

Prefer Self::with_domain_type when one concrete Rust type is enough. Duplicate selectors are ignored; selectors matching nothing error at crate::Generator::generate time.

Source

pub fn with_null_as_option(self, selector: ConversionSelector) -> Self

Map matching enum fields from NullValOption<T>.

Wire encoding is byte-identical: None writes the NullVal discriminant, Some(v) writes v. Zero runtime cost.

use ergo_sbe::{ConversionSelector, GenerationConfig};

// EventCode fields → Option<EventCode>
let config = GenerationConfig::new("msgs")
    .with_null_as_option(ConversionSelector::named_type("EventCode"));
Source

pub fn with_all_enums_as_option(self) -> Self

Map every enum field in the schema to Option<Enum>.

Shorthand for calling with_null_as_option on every named type. Opt-out per-enum is not yet supported — the blanket flag always wins.

use ergo_sbe::GenerationConfig;
let config = GenerationConfig::new("msgs")
    .with_all_enums_as_option();
Source

pub fn with_domain_type( self, selector: ConversionSelector, rust_type: impl Into<String>, ) -> Self

Map matching fields to a concrete Rust type path.

Implies Self::with_conversion for the same selector and emits well-known TryFromSbe/TryToSbe impls for bool, rust_decimal::Decimal, and chrono::DateTime<Utc> when those paths are used. For any other rust_type, no impl is auto-generated.

To skip the built-in impl and supply your own, use Self::with_manual_domain_type.

§Generated API

In build.rs: .with_domain_type(ConversionSelector::named_type("Decimal"), "rust_decimal::Decimal") Application: enc.try_price(rust_decimal::Decimal::new(12345, 2))? / let p = dec.try_price()?.

§Example
use ergo_sbe::{GenerationConfig, ConversionSelector};

let config = GenerationConfig::new("msgs")
    .with_domain_type(
        ConversionSelector::named_type("Decimal"),
        "rust_decimal::Decimal",
    );

Do not also call Self::with_conversion for the same selector.

Source

pub fn with_manual_domain_type( self, selector: ConversionSelector, rust_type: impl Into<String>, ) -> Self

Like Self::with_domain_type, but you write impl TryFromSbe<Wire> / impl TryToSbe<Wire> yourself — e.g. a custom rounding rule, or null/validation behaviour the built-in impl does not match.

ergo-sbe still generates the concrete try_price(...)? / try_price()? signatures that call those impls. A missing impl fails closed with a named compile error, and for the three built-ins the generated accessor’s rustdoc carries the exact impl Generated would have written, ready to copy and adjust.

use ergo_sbe::{GenerationConfig, ConversionSelector};

let config = GenerationConfig::new("msgs")
    .with_manual_domain_type(
        ConversionSelector::named_type("Decimal"),
        "rust_decimal::Decimal",
    );
// Application code must provide:
//   impl TryFromSbe<Decimal> for rust_decimal::Decimal { ... }
//   impl TryToSbe<Decimal> for rust_decimal::Decimal { ... }
Source

pub fn with_error_from_impls(self, path: impl Into<String>) -> Self

👎Deprecated since 0.1.20:

implement Fromgenerated::sbe_rt::EncodeError and Fromgenerated::sbe_rt::DecodeError on your error type so wire fields (needed/available) are preserved; this helper formats through String and will be removed in 1.0

Emit From<sbe_rt::EncodeError> / From<sbe_rt::DecodeError> for your error type.

In build.rs: .with_error_from_impls("crate::AppError"). Application code: enc.group(...)?;EncodeError auto-converts via From.

Note: The generated From impl uses format!("sbe encode: {err}") — stringifying the typed error through its Display form, then calling YourType::from(String). This means (1) your error type must implement From<String>, and (2) field-level error details (e.g. EncodeError::BufferTooShort { field, needed, available }) are lost in the conversion. Implement From<generated::sbe_rt::EncodeError> and From<generated::sbe_rt::DecodeError> on your error type so those fields survive. Removal is scheduled for 1.0.

Source

pub fn with_domain_objects(self, var_data: DomainVarData) -> Self

Generate owned domain structs next to flyweight codecs.

§var_data — important choice (DomainVarData)
ModeDTO fieldInvalid UTF-8
DomainVarData::BytesVec<u8>n/a
DomainVarData::StringsStringInvalidUtf8 error (strict)
use ergo_sbe::{DomainVarData, GenerationConfig};
let text = GenerationConfig::new("msgs")
    .with_domain_objects(DomainVarData::Strings);
let bytes = GenerationConfig::new("msgs")
    .with_domain_objects(DomainVarData::Bytes);
let _ = (text, bytes);
§Generated API

DomainVarData::Stringsmanufacturer: String. DomainVarData::Bytesmanufacturer: Vec<u8>.

sbe/tests/domain_objects_test.rs

Source

pub fn with_shared_module(self, name: impl Into<String>) -> Self

Shared module name for multi-schema generation (crate::Generator::generate_multi).

First schema owns shared enums/sets/composites; later modules pub use super::<name>::*.

Source

pub fn with_keyword_append_token(self, token: impl Into<String>) -> Self

Token appended when a schema name is a Rust keyword (default ”_”).

Schema field name="type" becomes method type_(); with token "x", it becomes typex().

use ergo_sbe::GenerationConfig;
let c = GenerationConfig::new("m").with_keyword_append_token("_");
let _ = c;
Source

pub fn with_bool_domain_type(self, enable: bool) -> Self

Auto-register bool converters for every boolean enum in the schema. Syntax sugar for calling with_domain_type(named_type("BooleanType"), "bool") for each — detects by name, semanticType="Boolean", or True/False value pairs with discriminants 0 and 1.

Only the canonical {0, 1} discriminant representation is detected automatically. Schemas with non-standard boolean encodings (e.g. Yes=5, No=3) should use explicit ConversionSelector::named_type with GenerationConfig::with_conversion instead.

Source

pub fn with_deprecated_attrs(self, enable: bool) -> Self

Emit #[deprecated] on schema-deprecated fields/types/messages.

Source

pub fn with_display_debug(self, enable: bool) -> Self

Control generated Debug and Display impls (enabled by default). Pass false to omit them and shrink generated output.

Source

pub fn with_meta_attributes(self, enable: bool) -> Self

Control meta-attribute constants (enabled by default). Pass false to omit — removes *_meta_attribute, *_ENCODING_OFFSET, *_ENCODING_LENGTH, *_ID, *_SINCE_VERSION, null/min/max field constants, and the per-message *_field_meta module.

Source

pub fn with_dispatch(self, enable: bool) -> Self

Control AnyMessage / FrameCursor / MessageVisitor dispatch code (enabled by default). Pass false to omit — saves ~300 lines; only meaningful when you do not need multi-template frame dispatch.

Source

pub fn profile(self, profile: GenerationProfile) -> Self

Apply a product profile that sets the size knobs together.

ProfileDisplay/DebugMeta attrsDispatchDomain objects
GenerationProfile::Fullonononunchanged
GenerationProfile::Leanoffoffoffoff

Explicit with_* settings (conversions, domain types, auto-bool) win regardless of order — profile() only sets the knobs it owns and never clears explicit configuration. Prefer lean for a clean Lean baseline.

Chain further with_* calls after profile to override individual knobs. Example:

use ergo_sbe::{GenerationConfig, GenerationProfile};
let _ = GenerationConfig::new("feed").profile(GenerationProfile::Lean);
Source

pub fn with_hook<F>(self, hook: F) -> Self
where F: Fn(&ItemContext<'_>) -> Vec<TokenStream> + Send + Sync + 'static,

Register a code-generation hook. The closure receives an ItemContext for each generated item (enum, set, composite, message decoder/encoder, domain struct) and returns token streams appended after the item’s definition.

Hooks fire in registration order. Use quote::quote! in your closure body to build the returned tokens.

§Example — serde Serialize for enums
use ergo_sbe::{GenerationConfig, ItemContext};
use quote::quote;

let config = GenerationConfig::new("msgs")
    .with_hook(|ctx: &ItemContext| -> Vec<proc_macro2::TokenStream> {
        match ctx {
            ItemContext::Enum { name, variants, .. } => {
                // Manual Serialize impl appends after the enum definition
                vec![quote! { /* impl Serialize for ... */ }]
            }
            _ => vec![],
        }
    });

Trait Implementations§

Source§

impl Clone for GenerationConfig

Source§

fn clone(&self) -> GenerationConfig

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for GenerationConfig

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for GenerationConfig

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<D> OwoColorize for D

Source§

fn fg<C>(&self) -> FgColorDisplay<'_, C, Self>
where C: Color,

Set the foreground color generically Read more
Source§

fn bg<C>(&self) -> BgColorDisplay<'_, C, Self>
where C: Color,

Set the background color generically. Read more
Source§

fn black(&self) -> FgColorDisplay<'_, Black, Self>

Change the foreground color to black
Source§

fn on_black(&self) -> BgColorDisplay<'_, Black, Self>

Change the background color to black
Source§

fn red(&self) -> FgColorDisplay<'_, Red, Self>

Change the foreground color to red
Source§

fn on_red(&self) -> BgColorDisplay<'_, Red, Self>

Change the background color to red
Source§

fn green(&self) -> FgColorDisplay<'_, Green, Self>

Change the foreground color to green
Source§

fn on_green(&self) -> BgColorDisplay<'_, Green, Self>

Change the background color to green
Source§

fn yellow(&self) -> FgColorDisplay<'_, Yellow, Self>

Change the foreground color to yellow
Source§

fn on_yellow(&self) -> BgColorDisplay<'_, Yellow, Self>

Change the background color to yellow
Source§

fn blue(&self) -> FgColorDisplay<'_, Blue, Self>

Change the foreground color to blue
Source§

fn on_blue(&self) -> BgColorDisplay<'_, Blue, Self>

Change the background color to blue
Source§

fn magenta(&self) -> FgColorDisplay<'_, Magenta, Self>

Change the foreground color to magenta
Source§

fn on_magenta(&self) -> BgColorDisplay<'_, Magenta, Self>

Change the background color to magenta
Source§

fn purple(&self) -> FgColorDisplay<'_, Magenta, Self>

Change the foreground color to purple
Source§

fn on_purple(&self) -> BgColorDisplay<'_, Magenta, Self>

Change the background color to purple
Source§

fn cyan(&self) -> FgColorDisplay<'_, Cyan, Self>

Change the foreground color to cyan
Source§

fn on_cyan(&self) -> BgColorDisplay<'_, Cyan, Self>

Change the background color to cyan
Source§

fn white(&self) -> FgColorDisplay<'_, White, Self>

Change the foreground color to white
Source§

fn on_white(&self) -> BgColorDisplay<'_, White, Self>

Change the background color to white
Source§

fn default_color(&self) -> FgColorDisplay<'_, Default, Self>

Change the foreground color to the terminal default
Source§

fn on_default_color(&self) -> BgColorDisplay<'_, Default, Self>

Change the background color to the terminal default
Source§

fn bright_black(&self) -> FgColorDisplay<'_, BrightBlack, Self>

Change the foreground color to bright black
Source§

fn on_bright_black(&self) -> BgColorDisplay<'_, BrightBlack, Self>

Change the background color to bright black
Source§

fn bright_red(&self) -> FgColorDisplay<'_, BrightRed, Self>

Change the foreground color to bright red
Source§

fn on_bright_red(&self) -> BgColorDisplay<'_, BrightRed, Self>

Change the background color to bright red
Source§

fn bright_green(&self) -> FgColorDisplay<'_, BrightGreen, Self>

Change the foreground color to bright green
Source§

fn on_bright_green(&self) -> BgColorDisplay<'_, BrightGreen, Self>

Change the background color to bright green
Source§

fn bright_yellow(&self) -> FgColorDisplay<'_, BrightYellow, Self>

Change the foreground color to bright yellow
Source§

fn on_bright_yellow(&self) -> BgColorDisplay<'_, BrightYellow, Self>

Change the background color to bright yellow
Source§

fn bright_blue(&self) -> FgColorDisplay<'_, BrightBlue, Self>

Change the foreground color to bright blue
Source§

fn on_bright_blue(&self) -> BgColorDisplay<'_, BrightBlue, Self>

Change the background color to bright blue
Source§

fn bright_magenta(&self) -> FgColorDisplay<'_, BrightMagenta, Self>

Change the foreground color to bright magenta
Source§

fn on_bright_magenta(&self) -> BgColorDisplay<'_, BrightMagenta, Self>

Change the background color to bright magenta
Source§

fn bright_purple(&self) -> FgColorDisplay<'_, BrightMagenta, Self>

Change the foreground color to bright purple
Source§

fn on_bright_purple(&self) -> BgColorDisplay<'_, BrightMagenta, Self>

Change the background color to bright purple
Source§

fn bright_cyan(&self) -> FgColorDisplay<'_, BrightCyan, Self>

Change the foreground color to bright cyan
Source§

fn on_bright_cyan(&self) -> BgColorDisplay<'_, BrightCyan, Self>

Change the background color to bright cyan
Source§

fn bright_white(&self) -> FgColorDisplay<'_, BrightWhite, Self>

Change the foreground color to bright white
Source§

fn on_bright_white(&self) -> BgColorDisplay<'_, BrightWhite, Self>

Change the background color to bright white
Source§

fn bold(&self) -> BoldDisplay<'_, Self>

Make the text bold
Source§

fn dimmed(&self) -> DimDisplay<'_, Self>

Make the text dim
Source§

fn italic(&self) -> ItalicDisplay<'_, Self>

Make the text italicized
Source§

fn underline(&self) -> UnderlineDisplay<'_, Self>

Make the text underlined
Make the text blink
Make the text blink (but fast!)
Source§

fn reversed(&self) -> ReversedDisplay<'_, Self>

Swap the foreground and background colors
Source§

fn hidden(&self) -> HiddenDisplay<'_, Self>

Hide the text
Source§

fn strikethrough(&self) -> StrikeThroughDisplay<'_, Self>

Cross out the text
Source§

fn color<Color>(&self, color: Color) -> FgDynColorDisplay<'_, Color, Self>
where Color: DynColor,

Set the foreground color at runtime. Only use if you do not know which color will be used at compile-time. If the color is constant, use either OwoColorize::fg or a color-specific method, such as OwoColorize::green, Read more
Source§

fn on_color<Color>(&self, color: Color) -> BgDynColorDisplay<'_, Color, Self>
where Color: DynColor,

Set the background color at runtime. Only use if you do not know what color to use at compile-time. If the color is constant, use either OwoColorize::bg or a color-specific method, such as OwoColorize::on_yellow, Read more
Source§

fn fg_rgb<const R: u8, const G: u8, const B: u8>( &self, ) -> FgColorDisplay<'_, CustomColor<R, G, B>, Self>

Set the foreground color to a specific RGB value.
Source§

fn bg_rgb<const R: u8, const G: u8, const B: u8>( &self, ) -> BgColorDisplay<'_, CustomColor<R, G, B>, Self>

Set the background color to a specific RGB value.
Source§

fn truecolor(&self, r: u8, g: u8, b: u8) -> FgDynColorDisplay<'_, Rgb, Self>

Sets the foreground color to an RGB value.
Source§

fn on_truecolor(&self, r: u8, g: u8, b: u8) -> BgDynColorDisplay<'_, Rgb, Self>

Sets the background color to an RGB value.
Source§

fn style(&self, style: Style) -> Styled<&Self>

Apply a runtime-determined style
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.