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
impl GenerationConfig
Sourcepub fn new(module_name: impl Into<String>) -> Self
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");Sourcepub fn lean(module_name: impl Into<String>) -> Self
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");Sourcepub fn with_module_name(self, name: impl Into<String>) -> Self
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.Sourcepub fn with_external_sbe_rt(self, path: impl Into<String>) -> Self
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");Sourcepub fn with_conversion(self, selector: ConversionSelector) -> Self
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.
Sourcepub fn with_null_as_option(self, selector: ConversionSelector) -> Self
pub fn with_null_as_option(self, selector: ConversionSelector) -> Self
Map matching enum fields from NullVal → Option<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"));Sourcepub fn with_all_enums_as_option(self) -> Self
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();Sourcepub fn with_domain_type(
self,
selector: ConversionSelector,
rust_type: impl Into<String>,
) -> Self
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.
Sourcepub fn with_manual_domain_type(
self,
selector: ConversionSelector,
rust_type: impl Into<String>,
) -> Self
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 { ... }Sourcepub 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
pub fn with_error_from_impls(self, path: impl Into<String>) -> Self
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.
Sourcepub fn with_domain_objects(self, var_data: DomainVarData) -> Self
pub fn with_domain_objects(self, var_data: DomainVarData) -> Self
Generate owned domain structs next to flyweight codecs.
§var_data — important choice (DomainVarData)
| Mode | DTO field | Invalid UTF-8 |
|---|---|---|
DomainVarData::Bytes | Vec<u8> | n/a |
DomainVarData::Strings | String | InvalidUtf8 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::Strings → manufacturer: String.
DomainVarData::Bytes → manufacturer: Vec<u8>.
Shared module name for multi-schema generation (crate::Generator::generate_multi).
First schema owns shared enums/sets/composites; later modules
pub use super::<name>::*.
Sourcepub fn with_keyword_append_token(self, token: impl Into<String>) -> Self
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;Sourcepub fn with_bool_domain_type(self, enable: bool) -> Self
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.
Sourcepub fn with_deprecated_attrs(self, enable: bool) -> Self
pub fn with_deprecated_attrs(self, enable: bool) -> Self
Emit #[deprecated] on schema-deprecated fields/types/messages.
Sourcepub fn with_display_debug(self, enable: bool) -> Self
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.
Sourcepub fn with_meta_attributes(self, enable: bool) -> Self
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.
Sourcepub fn with_dispatch(self, enable: bool) -> Self
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.
Sourcepub fn profile(self, profile: GenerationProfile) -> Self
pub fn profile(self, profile: GenerationProfile) -> Self
Apply a product profile that sets the size knobs together.
| Profile | Display/Debug | Meta attrs | Dispatch | Domain objects |
|---|---|---|---|---|
GenerationProfile::Full | on | on | on | unchanged |
GenerationProfile::Lean | off | off | off | off |
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);Sourcepub fn with_hook<F>(self, hook: F) -> Self
pub fn with_hook<F>(self, hook: F) -> Self
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
impl Clone for GenerationConfig
Source§fn clone(&self) -> GenerationConfig
fn clone(&self) -> GenerationConfig
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for GenerationConfig
impl Debug for GenerationConfig
Auto Trait Implementations§
impl !RefUnwindSafe for GenerationConfig
impl !UnwindSafe for GenerationConfig
impl Freeze for GenerationConfig
impl Send for GenerationConfig
impl Sync for GenerationConfig
impl Unpin for GenerationConfig
impl UnsafeUnpin for GenerationConfig
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<D> OwoColorize for D
impl<D> OwoColorize for D
Source§fn fg<C>(&self) -> FgColorDisplay<'_, C, Self>where
C: Color,
fn fg<C>(&self) -> FgColorDisplay<'_, C, Self>where
C: Color,
Source§fn bg<C>(&self) -> BgColorDisplay<'_, C, Self>where
C: Color,
fn bg<C>(&self) -> BgColorDisplay<'_, C, Self>where
C: Color,
Source§fn black(&self) -> FgColorDisplay<'_, Black, Self>
fn black(&self) -> FgColorDisplay<'_, Black, Self>
Source§fn on_black(&self) -> BgColorDisplay<'_, Black, Self>
fn on_black(&self) -> BgColorDisplay<'_, Black, Self>
Source§fn red(&self) -> FgColorDisplay<'_, Red, Self>
fn red(&self) -> FgColorDisplay<'_, Red, Self>
Source§fn on_red(&self) -> BgColorDisplay<'_, Red, Self>
fn on_red(&self) -> BgColorDisplay<'_, Red, Self>
Source§fn green(&self) -> FgColorDisplay<'_, Green, Self>
fn green(&self) -> FgColorDisplay<'_, Green, Self>
Source§fn on_green(&self) -> BgColorDisplay<'_, Green, Self>
fn on_green(&self) -> BgColorDisplay<'_, Green, Self>
Source§fn yellow(&self) -> FgColorDisplay<'_, Yellow, Self>
fn yellow(&self) -> FgColorDisplay<'_, Yellow, Self>
Source§fn on_yellow(&self) -> BgColorDisplay<'_, Yellow, Self>
fn on_yellow(&self) -> BgColorDisplay<'_, Yellow, Self>
Source§fn blue(&self) -> FgColorDisplay<'_, Blue, Self>
fn blue(&self) -> FgColorDisplay<'_, Blue, Self>
Source§fn on_blue(&self) -> BgColorDisplay<'_, Blue, Self>
fn on_blue(&self) -> BgColorDisplay<'_, Blue, Self>
Source§fn magenta(&self) -> FgColorDisplay<'_, Magenta, Self>
fn magenta(&self) -> FgColorDisplay<'_, Magenta, Self>
Source§fn on_magenta(&self) -> BgColorDisplay<'_, Magenta, Self>
fn on_magenta(&self) -> BgColorDisplay<'_, Magenta, Self>
Source§fn purple(&self) -> FgColorDisplay<'_, Magenta, Self>
fn purple(&self) -> FgColorDisplay<'_, Magenta, Self>
Source§fn on_purple(&self) -> BgColorDisplay<'_, Magenta, Self>
fn on_purple(&self) -> BgColorDisplay<'_, Magenta, Self>
Source§fn cyan(&self) -> FgColorDisplay<'_, Cyan, Self>
fn cyan(&self) -> FgColorDisplay<'_, Cyan, Self>
Source§fn on_cyan(&self) -> BgColorDisplay<'_, Cyan, Self>
fn on_cyan(&self) -> BgColorDisplay<'_, Cyan, Self>
Source§fn white(&self) -> FgColorDisplay<'_, White, Self>
fn white(&self) -> FgColorDisplay<'_, White, Self>
Source§fn on_white(&self) -> BgColorDisplay<'_, White, Self>
fn on_white(&self) -> BgColorDisplay<'_, White, Self>
Source§fn default_color(&self) -> FgColorDisplay<'_, Default, Self>
fn default_color(&self) -> FgColorDisplay<'_, Default, Self>
Source§fn on_default_color(&self) -> BgColorDisplay<'_, Default, Self>
fn on_default_color(&self) -> BgColorDisplay<'_, Default, Self>
Source§fn bright_black(&self) -> FgColorDisplay<'_, BrightBlack, Self>
fn bright_black(&self) -> FgColorDisplay<'_, BrightBlack, Self>
Source§fn on_bright_black(&self) -> BgColorDisplay<'_, BrightBlack, Self>
fn on_bright_black(&self) -> BgColorDisplay<'_, BrightBlack, Self>
Source§fn bright_red(&self) -> FgColorDisplay<'_, BrightRed, Self>
fn bright_red(&self) -> FgColorDisplay<'_, BrightRed, Self>
Source§fn on_bright_red(&self) -> BgColorDisplay<'_, BrightRed, Self>
fn on_bright_red(&self) -> BgColorDisplay<'_, BrightRed, Self>
Source§fn bright_green(&self) -> FgColorDisplay<'_, BrightGreen, Self>
fn bright_green(&self) -> FgColorDisplay<'_, BrightGreen, Self>
Source§fn on_bright_green(&self) -> BgColorDisplay<'_, BrightGreen, Self>
fn on_bright_green(&self) -> BgColorDisplay<'_, BrightGreen, Self>
Source§fn bright_yellow(&self) -> FgColorDisplay<'_, BrightYellow, Self>
fn bright_yellow(&self) -> FgColorDisplay<'_, BrightYellow, Self>
Source§fn on_bright_yellow(&self) -> BgColorDisplay<'_, BrightYellow, Self>
fn on_bright_yellow(&self) -> BgColorDisplay<'_, BrightYellow, Self>
Source§fn bright_blue(&self) -> FgColorDisplay<'_, BrightBlue, Self>
fn bright_blue(&self) -> FgColorDisplay<'_, BrightBlue, Self>
Source§fn on_bright_blue(&self) -> BgColorDisplay<'_, BrightBlue, Self>
fn on_bright_blue(&self) -> BgColorDisplay<'_, BrightBlue, Self>
Source§fn bright_magenta(&self) -> FgColorDisplay<'_, BrightMagenta, Self>
fn bright_magenta(&self) -> FgColorDisplay<'_, BrightMagenta, Self>
Source§fn on_bright_magenta(&self) -> BgColorDisplay<'_, BrightMagenta, Self>
fn on_bright_magenta(&self) -> BgColorDisplay<'_, BrightMagenta, Self>
Source§fn bright_purple(&self) -> FgColorDisplay<'_, BrightMagenta, Self>
fn bright_purple(&self) -> FgColorDisplay<'_, BrightMagenta, Self>
Source§fn on_bright_purple(&self) -> BgColorDisplay<'_, BrightMagenta, Self>
fn on_bright_purple(&self) -> BgColorDisplay<'_, BrightMagenta, Self>
Source§fn bright_cyan(&self) -> FgColorDisplay<'_, BrightCyan, Self>
fn bright_cyan(&self) -> FgColorDisplay<'_, BrightCyan, Self>
Source§fn on_bright_cyan(&self) -> BgColorDisplay<'_, BrightCyan, Self>
fn on_bright_cyan(&self) -> BgColorDisplay<'_, BrightCyan, Self>
Source§fn bright_white(&self) -> FgColorDisplay<'_, BrightWhite, Self>
fn bright_white(&self) -> FgColorDisplay<'_, BrightWhite, Self>
Source§fn on_bright_white(&self) -> BgColorDisplay<'_, BrightWhite, Self>
fn on_bright_white(&self) -> BgColorDisplay<'_, BrightWhite, Self>
Source§fn bold(&self) -> BoldDisplay<'_, Self>
fn bold(&self) -> BoldDisplay<'_, Self>
Source§fn dimmed(&self) -> DimDisplay<'_, Self>
fn dimmed(&self) -> DimDisplay<'_, Self>
Source§fn italic(&self) -> ItalicDisplay<'_, Self>
fn italic(&self) -> ItalicDisplay<'_, Self>
Source§fn underline(&self) -> UnderlineDisplay<'_, Self>
fn underline(&self) -> UnderlineDisplay<'_, Self>
Source§fn blink(&self) -> BlinkDisplay<'_, Self>
fn blink(&self) -> BlinkDisplay<'_, Self>
Source§fn blink_fast(&self) -> BlinkFastDisplay<'_, Self>
fn blink_fast(&self) -> BlinkFastDisplay<'_, Self>
Source§fn reversed(&self) -> ReversedDisplay<'_, Self>
fn reversed(&self) -> ReversedDisplay<'_, Self>
Source§fn strikethrough(&self) -> StrikeThroughDisplay<'_, Self>
fn strikethrough(&self) -> StrikeThroughDisplay<'_, Self>
Source§fn color<Color>(&self, color: Color) -> FgDynColorDisplay<'_, Color, Self>where
Color: DynColor,
fn color<Color>(&self, color: Color) -> FgDynColorDisplay<'_, Color, Self>where
Color: DynColor,
OwoColorize::fg or
a color-specific method, such as OwoColorize::green, Read moreSource§fn on_color<Color>(&self, color: Color) -> BgDynColorDisplay<'_, Color, Self>where
Color: DynColor,
fn on_color<Color>(&self, color: Color) -> BgDynColorDisplay<'_, Color, Self>where
Color: DynColor,
OwoColorize::bg or
a color-specific method, such as OwoColorize::on_yellow, Read more