Skip to main content

TradeAble

Trait TradeAble 

Source
pub trait TradeAble {
    // Required methods
    fn trade(&self) -> Result<Trade, TradeError>;
    fn trade_ref(&self) -> Result<&Trade, TradeError>;
    fn trade_mut(&mut self) -> Result<&mut Trade, TradeError>;
}
Expand description

A trait that provides functionality for accessing and modifying trade-related data.

Implementors of this trait should provide mechanisms to retrieve both immutable and mutable references to a Trade object.

Required Methods§

Source

fn trade(&self) -> Result<Trade, TradeError>

Retrieves a reference to a Trade instance associated with the current object.

§Returns

A Trade object, or a TradeError if the trade cannot be accessed.

This method allows access to the Trade data within the context of the implementing object. It ensures that the Trade is available for viewing or interaction.

Note: This method returns an owned Trade instance, allowing modification.

§Errors

Returns TradeError::InvalidTrade when the implementor cannot materialize a Trade from its current state (typically when the container does not yet hold a committed trade).

Source

fn trade_ref(&self) -> Result<&Trade, TradeError>

Returns a reference to the Trade associated with the current instance.

§Returns

A reference to the Trade object tied to this instance, or a TradeError if the trade cannot be accessed.

§Note

The returned reference has the same lifetime as the instance it is called on.

§Errors

Returns TradeError::InvalidTrade when the implementor does not currently hold a materialized Trade to borrow.

Source

fn trade_mut(&mut self) -> Result<&mut Trade, TradeError>

Provides a mutable reference to the Trade instance contained within the current structure.

§Returns

A mutable reference to the internal Trade instance, or a TradeError if the trade cannot be accessed. This allows the caller to modify the Trade directly.

§Notes
  • Since this method provides a mutable reference, it enforces Rust’s borrow rules. Only one mutable reference to the Trade is allowed at a time.
  • Ensure that concurrent access to the structure is properly managed to avoid runtime issues.
§Errors

Returns TradeError::InvalidTrade when the implementor does not currently hold a materialized Trade to borrow mutably.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§