Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Include generated code

Product crates should depend on ergo-sbe at build time only, with no runtime link. Generated codecs embed sbe_rt, so plain include! is enough:

#[path = "generated/feature_tour.rs"]
pub mod feature_tour;
pub use feature_tour::*;

(From sbe-feature-tour/src/lib.rs: the #[path] pattern used by every sample crate. The feature tour’s cargo build checks that it compiles.)

or via include!:

mod messages {
    include!(concat!(env!("OUT_DIR"), "/messages.rs"));
}
use messages::*;

sbe_mod! is optional and needs ergo-sbe as a normal dependency (for macro expansion only, not for encode or decode):

// Cargo.toml: [dependencies] ergo-sbe = "0.1"
ergo_sbe::sbe_mod!(messages);
use messages::*;
// Or only the include: ergo_sbe::include_sbe!("messages");

See Samples for which crates use which pattern.