Skip to main content

custom_data

Attribute Macro custom_data 

Source
#[custom_data]
Expand description

Expands a struct into a custom data type with generated impls: #[derive(Debug, Clone, Serialize, Deserialize, PartialEq)], constructor, HasTsInit, CustomDataTrait, ArrowSchemaProvider, EncodeToRecordBatch, DecodeDataFromRecordBatch, CatalogPathPrefix, From/TryFrom for Data. Call nautilus_serialization::ensure_custom_data_registered::<T>() and (for Python) nautilus_model::data::register_rust_extractor::<T>() once per type. Requires fields to include ts_event and ts_init (e.g. nautilus_core::UnixNanos). Supported field types include InstrumentId, AccountId, Currency, BarType, Params, UnixNanos, f64, f32, bool, String, u64, i64, u32, i32, Vec<f64>, and Vec<u8>.

Use #[custom_data(pyo3)] or #[custom_data(python)] to also generate Python bindings: #[cfg_attr(feature = "python", pyo3::pyclass)] on the struct and a #[pymethods] impl with #[new] constructor and #[getter] per field. When pyo3 is set, the Rust constructor is named new; Python __init__ forwards to it. Use #[custom_data(pyo3, no_display)] to skip generating repr() and Display so you can implement them manually.