Skip to main content

CustomDataTrait

Trait CustomDataTrait 

Source
pub trait CustomDataTrait:
    HasTsInit
    + Send
    + Sync
    + Debug {
    // Required methods
    fn type_name(&self) -> &'static str;
    fn as_any(&self) -> &dyn Any;
    fn ts_event(&self) -> UnixNanos;
    fn to_json(&self) -> Result<String>;
    fn clone_arc(&self) -> Arc<dyn CustomDataTrait>;
    fn eq_arc(&self, other: &dyn CustomDataTrait) -> bool;

    // Provided methods
    fn to_json_py(&self) -> Result<String> { ... }
    fn to_pyobject(&self, _py: Python<'_>) -> PyResult<Py<PyAny>> { ... }
    fn type_name_static() -> &'static str
       where Self: Sized { ... }
    fn from_json(_value: Value) -> Result<Arc<dyn CustomDataTrait>>
       where Self: Sized { ... }
}
Expand description

Trait for typed custom data that can be used within the Nautilus domain model.

Required Methods§

Source

fn type_name(&self) -> &'static str

Returns the type name for the custom data.

Source

fn as_any(&self) -> &dyn Any

Returns the data as a dyn Any for downcasting.

Source

fn ts_event(&self) -> UnixNanos

Returns the event timestamp (when the data occurred).

Source

fn to_json(&self) -> Result<String>

Serializes the custom data to a JSON string.

§Errors

Returns an error if JSON serialization fails.

Source

fn clone_arc(&self) -> Arc<dyn CustomDataTrait>

Returns a cloned Arc of the custom data.

Source

fn eq_arc(&self, other: &dyn CustomDataTrait) -> bool

Returns whether the custom data is equal to another.

Provided Methods§

Source

fn to_json_py(&self) -> Result<String>

Python-facing JSON serialization. Default implementation forwards to to_json. Override if a different behavior is needed for the Python API.

§Errors

Returns an error if JSON serialization fails.

Source

fn to_pyobject(&self, _py: Python<'_>) -> PyResult<Py<PyAny>>

Converts the custom data to a Python object.

§Errors

Returns an error if PyO3 conversion fails.

Source

fn type_name_static() -> &'static str
where Self: Sized,

Returns the type name used in serialized form (e.g. in the "type" field).

Source

fn from_json(_value: Value) -> Result<Arc<dyn CustomDataTrait>>
where Self: Sized,

Deserializes from a JSON value into an Arc’d trait object.

§Errors

Returns an error if JSON deserialization fails.

Implementors§

Source§

impl CustomDataTrait for StubCustomData

Source§

impl CustomDataTrait for PythonCustomDataWrapper

Available on crate feature python only.