pub struct DriftClient {
pub context: Context,
pub wallet: Wallet,
/* private fields */
}
Expand description
DriftClient
It is cheaply clone-able and consumers are encouraged to do so.
It is not recommended to create multiple instances with ::new()
as this will not re-use underlying resources such
as network connections or memory allocations
The client can be used as is to fetch data ad-hoc over RPC or subscribed to receive live updates (transparently)
let client = DriftClient::new(
Context::MainNet,
RpcClient::new("https://rpc.example.com"),
key_pair.into()
).await.expect("initializes");
// queries over RPC
let sol_perp_price = client.oracle_price(MarketId::perp(0)).await;
// Subscribe to live program changes e.g oracle prices, spot/perp market changes, user accounts
let markets = [MarketId::perp(0), MarketId::spot(2)];
client.subscribe_markets(&markets).await.expect("subscribes");
client.subscribe_oracles(&markets).await.expect("subscribes");
// after subscribing, uses Ws-backed local storage
let sol_perp_price = client.oracle_price(MarketId::perp(0)).await;
client.unsubscribe();
Fields§
§context: Context
§wallet: Wallet
Implementations§
Source§impl DriftClient
impl DriftClient
Sourcepub async fn new(
context: Context,
rpc_client: RpcClient,
wallet: Wallet,
) -> SdkResult<Self>
pub async fn new( context: Context, rpc_client: RpcClient, wallet: Wallet, ) -> SdkResult<Self>
Create a new DriftClient
instance
context
- devnet or mainnetrpc_client
- an RpcClient instancewallet
- wallet to use for tx signing convenience
Sourcepub async fn subscribe_blockhashes(&self) -> SdkResult<()>
pub async fn subscribe_blockhashes(&self) -> SdkResult<()>
Starts background subscriptions for live blockhashes
This is a no-op if already subscribed
Sourcepub async fn subscribe_markets(&self, markets: &[MarketId]) -> SdkResult<()>
pub async fn subscribe_markets(&self, markets: &[MarketId]) -> SdkResult<()>
Starts background subscriptions for live market account updates
markets
- list of markets to subscribe
This is a no-op if already subscribed
Sourcepub async fn subscribe_all_markets(&self) -> SdkResult<()>
pub async fn subscribe_all_markets(&self) -> SdkResult<()>
Subscribe to all spot and perp markets
This is a no-op if already subscribed
Sourcepub async fn subscribe_all_spot_markets(&self) -> SdkResult<()>
pub async fn subscribe_all_spot_markets(&self) -> SdkResult<()>
Subscribe to all spot markets
This is a no-op if already subscribed
Sourcepub async fn subscribe_all_perp_markets(&self) -> SdkResult<()>
pub async fn subscribe_all_perp_markets(&self) -> SdkResult<()>
Subscribe to all perp markets
This is a no-op if already subscribed
Sourcepub async fn subscribe_oracles(&self, markets: &[MarketId]) -> SdkResult<()>
pub async fn subscribe_oracles(&self, markets: &[MarketId]) -> SdkResult<()>
Starts background subscriptions for live oracle account updates by market
markets
- list of markets to subscribe for oracle updates
This is a no-op if already subscribed
Sourcepub async fn subscribe_all_oracles(&self) -> SdkResult<()>
pub async fn subscribe_all_oracles(&self) -> SdkResult<()>
Subscribe to all oracles
This is a no-op if already subscribed
Sourcepub async fn subscribe_all_spot_oracles(&self) -> SdkResult<()>
pub async fn subscribe_all_spot_oracles(&self) -> SdkResult<()>
Subscribe to all spot market oracles
This is a no-op if already subscribed
Sourcepub async fn subscribe_all_perp_oracles(&self) -> SdkResult<()>
pub async fn subscribe_all_perp_oracles(&self) -> SdkResult<()>
Subscribe to all perp market oracles
This is a no-op if already subscribed
Sourcepub async fn subscribe_swift_orders(
&self,
markets: &[MarketId],
) -> SdkResult<SwiftOrderStream>
pub async fn subscribe_swift_orders( &self, markets: &[MarketId], ) -> SdkResult<SwiftOrderStream>
Subscribe to swift order feed(s) for given markets
markets
- list of markets to watch for swift orders
Returns a stream of swift orders
Sourcepub fn get_all_spot_market_ids(&self) -> Vec<MarketId>
pub fn get_all_spot_market_ids(&self) -> Vec<MarketId>
Returns the MarketIds for all active spot markets (ignores de-listed and settled markets)
Useful for iterating over all spot markets
Sourcepub fn get_all_perp_market_ids(&self) -> Vec<MarketId>
pub fn get_all_perp_market_ids(&self) -> Vec<MarketId>
Returns the MarketIds for all active perp markets (ignores de-listed and settled markets)
Useful for iterating over all perp markets
Sourcepub fn get_all_market_ids(&self) -> Vec<MarketId>
pub fn get_all_market_ids(&self) -> Vec<MarketId>
Returns the MarketId
s for all active markets (ignores de-listed and settled markets)
Useful for iterating over all markets
Sourcepub async fn unsubscribe(&self) -> SdkResult<()>
pub async fn unsubscribe(&self) -> SdkResult<()>
Unsubscribe from network resources Subsequent queries will pull from the network ad-hoc
This is a no-op if not subscribed
Sourcepub fn ws(&self) -> Arc<PubsubClient>
pub fn ws(&self) -> Arc<PubsubClient>
Return a handle to the inner Ws client
Sourcepub fn program_data(&self) -> &ProgramData
pub fn program_data(&self) -> &ProgramData
Return on-chain program metadata
Useful for inspecting market ids and config
Sourcepub async fn get_order_by_id(
&self,
account: &Pubkey,
order_id: u32,
) -> SdkResult<Option<Order>>
pub async fn get_order_by_id( &self, account: &Pubkey, order_id: u32, ) -> SdkResult<Option<Order>>
Get an account’s open order by id
account
- the drift user PDAorder_id
- order id to query
Returns the Order
if it exists
Sourcepub async fn get_order_by_user_id(
&self,
account: &Pubkey,
user_order_id: u8,
) -> SdkResult<Option<Order>>
pub async fn get_order_by_user_id( &self, account: &Pubkey, user_order_id: u8, ) -> SdkResult<Option<Order>>
Get an account’s open order by user assigned id
account
- the drift user PDAuser_order_id
- user defined order id to query
Returns the Order
if it exists
Sourcepub async fn all_orders(&self, account: &Pubkey) -> SdkResult<Vec<Order>>
pub async fn all_orders(&self, account: &Pubkey) -> SdkResult<Vec<Order>>
Get the account’s open orders
account
- the drift user PDA
Returns the list of open orders
Sourcepub async fn unsettled_positions(
&self,
account: &Pubkey,
) -> SdkResult<Vec<PerpPosition>>
pub async fn unsettled_positions( &self, account: &Pubkey, ) -> SdkResult<Vec<PerpPosition>>
Get the account’s unsettled positions
account
- the drift user PDA
Returns the list of unsettled positions
Sourcepub async fn all_positions(
&self,
account: &Pubkey,
) -> SdkResult<(Vec<SpotPosition>, Vec<PerpPosition>)>
pub async fn all_positions( &self, account: &Pubkey, ) -> SdkResult<(Vec<SpotPosition>, Vec<PerpPosition>)>
Get all the account’s open positions
account
- the drift user PDA
Sourcepub async fn perp_position(
&self,
account: &Pubkey,
market_index: u16,
) -> SdkResult<Option<PerpPosition>>
pub async fn perp_position( &self, account: &Pubkey, market_index: u16, ) -> SdkResult<Option<PerpPosition>>
Get a perp position by market
account
- the drift user PDA
Returns the position if it exists
Sourcepub async fn spot_position(
&self,
account: &Pubkey,
market_index: u16,
) -> SdkResult<Option<SpotPosition>>
pub async fn spot_position( &self, account: &Pubkey, market_index: u16, ) -> SdkResult<Option<SpotPosition>>
Get a spot position by market
account
- the drift user PDA
Returns the position if it exists
Sourcepub async fn get_user_account(&self, account: &Pubkey) -> SdkResult<User>
pub async fn get_user_account(&self, account: &Pubkey) -> SdkResult<User>
Get the user account data Uses cached value if subscribed, falls back to network query
account
- the drift user PDA (subaccount)
Returns the deserialized account data (User
)
Sourcepub async fn get_user_stats(&self, authority: &Pubkey) -> SdkResult<UserStats>
pub async fn get_user_stats(&self, authority: &Pubkey) -> SdkResult<UserStats>
Get a stats account
Returns the deserialized account data (UserStats
)
Sourcepub async fn get_latest_blockhash(&self) -> SdkResult<Hash>
pub async fn get_latest_blockhash(&self) -> SdkResult<Hash>
Get the latest recent_block_hash uses latest cached if subscribed, otherwise falls back to network query
Sourcepub async fn get_account_value<T: AccountDeserialize>(
&self,
account: &Pubkey,
) -> SdkResult<T>
pub async fn get_account_value<T: AccountDeserialize>( &self, account: &Pubkey, ) -> SdkResult<T>
Get some account value deserialized as T Uses cached value if subscribed, falls back to network query
account
- any onchain account
Returns the deserialized account data (User
)
Sourcepub fn try_get_account<T: AccountDeserialize>(
&self,
account: &Pubkey,
) -> SdkResult<T>
pub fn try_get_account<T: AccountDeserialize>( &self, account: &Pubkey, ) -> SdkResult<T>
Try to get account
as T
using latest local value
requires account was previously subscribed too.
like get_account_value
without async/network fallback
Sourcepub fn state_account(&self) -> SdkResult<State>
pub fn state_account(&self) -> SdkResult<State>
Try get the Drift State
config account
It contains various exchange level config parameters
Sourcepub async fn sign_and_send(&self, tx: VersionedMessage) -> SdkResult<Signature>
pub async fn sign_and_send(&self, tx: VersionedMessage) -> SdkResult<Signature>
Sign and send a tx to the network
Returns the signature on success
Sourcepub async fn sign_and_send_with_config(
&self,
tx: VersionedMessage,
recent_block_hash: Option<Hash>,
config: RpcSendTransactionConfig,
) -> SdkResult<Signature>
pub async fn sign_and_send_with_config( &self, tx: VersionedMessage, recent_block_hash: Option<Hash>, config: RpcSendTransactionConfig, ) -> SdkResult<Signature>
Sign and send a tx to the network
recent_block_hash
- some block hash to use for tx signing, if not provided it will be automatically setconfig
- custom RPC config to use when submitting the tx
Returns the signature on success
Sourcepub async fn get_spot_market_account(
&self,
market_index: u16,
) -> SdkResult<SpotMarket>
pub async fn get_spot_market_account( &self, market_index: u16, ) -> SdkResult<SpotMarket>
Get spot market account
market_index
- spot market index
uses latest cached value if subscribed, otherwise falls back to network query
Sourcepub async fn get_perp_market_account(
&self,
market_index: u16,
) -> SdkResult<PerpMarket>
pub async fn get_perp_market_account( &self, market_index: u16, ) -> SdkResult<PerpMarket>
Get perp market account
market_index
- perp market index
uses latest cached value if subscribed, otherwise falls back to network query
Sourcepub fn try_get_spot_market_account(
&self,
market_index: u16,
) -> SdkResult<SpotMarket>
pub fn try_get_spot_market_account( &self, market_index: u16, ) -> SdkResult<SpotMarket>
Try to spot market account from cache
market_index
- spot market index
Returns error if not subscribed
Sourcepub fn try_get_perp_market_account(
&self,
market_index: u16,
) -> SdkResult<PerpMarket>
pub fn try_get_perp_market_account( &self, market_index: u16, ) -> SdkResult<PerpMarket>
Try to get perp market account from cache
market_index
- spot market index
Returns error if not subscribed
Sourcepub fn market_lookup(&self, symbol: &str) -> Option<MarketId>
pub fn market_lookup(&self, symbol: &str) -> Option<MarketId>
Lookup a market by symbol
This operation is not free so lookups should be reused/cached by the caller
Returns None if symbol does not map to any known market
Sourcepub async fn oracle_price(&self, market: MarketId) -> SdkResult<i64>
pub async fn oracle_price(&self, market: MarketId) -> SdkResult<i64>
Get live oracle price for market
uses latest cached if subscribed, otherwise falls back to network query
Sourcepub async fn init_tx(
&self,
account: &Pubkey,
delegated: bool,
) -> SdkResult<TransactionBuilder<'_>>
pub async fn init_tx( &self, account: &Pubkey, delegated: bool, ) -> SdkResult<TransactionBuilder<'_>>
Initialize a transaction given a (sub)account address
let tx = client
.init_tx(&wallet.sub_account(3), false)
.cancel_all_orders()
.place_orders(...)
.build();
Returns a TransactionBuilder
for composing the tx
pub async fn get_recent_priority_fees( &self, writable_markets: &[MarketId], window: Option<usize>, ) -> SdkResult<Vec<u64>>
Sourcepub fn try_get_oracle_price_data_and_slot(
&self,
market: MarketId,
) -> Option<Oracle>
pub fn try_get_oracle_price_data_and_slot( &self, market: MarketId, ) -> Option<Oracle>
Try get the latest oracle data for market
If only the price is required use oracle_price
instead
Sourcepub async fn get_oracle_price_data_and_slot(
&self,
market: MarketId,
) -> SdkResult<Oracle>
pub async fn get_oracle_price_data_and_slot( &self, market: MarketId, ) -> SdkResult<Oracle>
Get the latest oracle data for market
If only the price is required use oracle_price
instead
Sourcepub async fn subscribe_account(&self, account: &Pubkey) -> SdkResult<()>
pub async fn subscribe_account(&self, account: &Pubkey) -> SdkResult<()>
Subscribe to live WebSocket updates for some account
The latest value may be retrieved with client.get_account(..)
let subaccount = Wallet::derive_user_account(authority, 1);
client.subscribe_account(&subaccount).await;
let subaccount_data = client.get_account::<User>(&subaccount);
Sourcepub async fn subscribe_account_polled(
&self,
account: &Pubkey,
interval: Duration,
) -> SdkResult<()>
pub async fn subscribe_account_polled( &self, account: &Pubkey, interval: Duration, ) -> SdkResult<()>
Same as subscribe_account
but uses RPC polling
Sourcepub fn unsubscribe_account(&self, account: &Pubkey) -> SdkResult<()>
pub fn unsubscribe_account(&self, account: &Pubkey) -> SdkResult<()>
Unsubscribe from updates for account
Sourcepub fn check_libs() -> SdkResult<()>
pub fn check_libs() -> SdkResult<()>
Check IDL and libdrift_ffi_sys version
panics if there’s a mismatch
Sourcepub async fn grpc_subscribe(
&self,
endpoint: String,
x_token: String,
opts: GrpcSubscribeOpts,
) -> SdkResult<()>
pub async fn grpc_subscribe( &self, endpoint: String, x_token: String, opts: GrpcSubscribeOpts, ) -> SdkResult<()>
Subscribe to all: markets, oracles, users, and slot updates over gRPC
Updates are transparently handled by the DriftClient
and calls to get User accounts, markets, oracles, etc.
will utilize the latest cached updates from the gRPC subscription.
use opts
to control what is cached by the client. The gRPC connection will always subscribe
to all drift accounts regardless.
endpoint
- the gRPC endpointx_token
- gRPC authentication X tokenopts
- configure callbacks and caching
Sourcepub fn grpc_unsubscribe(&self)
pub fn grpc_unsubscribe(&self)
Unsubscribe the gRPC connection
Trait Implementations§
Source§impl Clone for DriftClient
impl Clone for DriftClient
Source§fn clone(&self) -> DriftClient
fn clone(&self) -> DriftClient
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moreSource§impl UserMargin for DriftClient
impl UserMargin for DriftClient
Source§fn calculate_perp_buying_power(
&self,
user: &User,
market: &PerpMarket,
oracle_price: i64,
collateral_buffer: u64,
) -> SdkResult<u128>
fn calculate_perp_buying_power( &self, user: &User, market: &PerpMarket, oracle_price: i64, collateral_buffer: u64, ) -> SdkResult<u128>
Calculate buying power = free collateral / initial margin ratio
Returns buying power in QUOTE_PRECISION
units
Source§fn calculate_margin_info(&self, user: &User) -> SdkResult<MarginCalculation>
fn calculate_margin_info(&self, user: &User) -> SdkResult<MarginCalculation>
Source§fn max_trade_size(
&self,
user: &Pubkey,
market: MarketId,
trade_side: PositionDirection,
) -> SdkResult<u64>
fn max_trade_size( &self, user: &Pubkey, market: MarketId, trade_side: PositionDirection, ) -> SdkResult<u64>
Auto Trait Implementations§
impl Freeze for DriftClient
impl !RefUnwindSafe for DriftClient
impl Send for DriftClient
impl Sync for DriftClient
impl Unpin for DriftClient
impl !UnwindSafe for DriftClient
Blanket Implementations§
Source§impl<T> AlignerFor<1> for T
impl<T> AlignerFor<1> for T
Source§impl<T> AlignerFor<1024> for T
impl<T> AlignerFor<1024> for T
Source§type Aligner = AlignTo1024<T>
type Aligner = AlignTo1024<T>
AlignTo*
type which aligns Self
to ALIGNMENT
.Source§impl<T> AlignerFor<128> for T
impl<T> AlignerFor<128> for T
Source§type Aligner = AlignTo128<T>
type Aligner = AlignTo128<T>
AlignTo*
type which aligns Self
to ALIGNMENT
.Source§impl<T> AlignerFor<16> for T
impl<T> AlignerFor<16> for T
Source§impl<T> AlignerFor<16384> for T
impl<T> AlignerFor<16384> for T
Source§type Aligner = AlignTo16384<T>
type Aligner = AlignTo16384<T>
AlignTo*
type which aligns Self
to ALIGNMENT
.Source§impl<T> AlignerFor<2> for T
impl<T> AlignerFor<2> for T
Source§impl<T> AlignerFor<2048> for T
impl<T> AlignerFor<2048> for T
Source§type Aligner = AlignTo2048<T>
type Aligner = AlignTo2048<T>
AlignTo*
type which aligns Self
to ALIGNMENT
.Source§impl<T> AlignerFor<256> for T
impl<T> AlignerFor<256> for T
Source§type Aligner = AlignTo256<T>
type Aligner = AlignTo256<T>
AlignTo*
type which aligns Self
to ALIGNMENT
.Source§impl<T> AlignerFor<32> for T
impl<T> AlignerFor<32> for T
Source§impl<T> AlignerFor<32768> for T
impl<T> AlignerFor<32768> for T
Source§type Aligner = AlignTo32768<T>
type Aligner = AlignTo32768<T>
AlignTo*
type which aligns Self
to ALIGNMENT
.Source§impl<T> AlignerFor<4> for T
impl<T> AlignerFor<4> for T
Source§impl<T> AlignerFor<4096> for T
impl<T> AlignerFor<4096> for T
Source§type Aligner = AlignTo4096<T>
type Aligner = AlignTo4096<T>
AlignTo*
type which aligns Self
to ALIGNMENT
.Source§impl<T> AlignerFor<512> for T
impl<T> AlignerFor<512> for T
Source§type Aligner = AlignTo512<T>
type Aligner = AlignTo512<T>
AlignTo*
type which aligns Self
to ALIGNMENT
.Source§impl<T> AlignerFor<64> for T
impl<T> AlignerFor<64> for T
Source§impl<T> AlignerFor<8> for T
impl<T> AlignerFor<8> for T
Source§impl<T> AlignerFor<8192> for T
impl<T> AlignerFor<8192> for T
Source§type Aligner = AlignTo8192<T>
type Aligner = AlignTo8192<T>
AlignTo*
type which aligns Self
to ALIGNMENT
.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<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T
in a tonic::Request
Source§impl<'a, T> RCowCompatibleRef<'a> for Twhere
T: Clone + 'a,
impl<'a, T> RCowCompatibleRef<'a> for Twhere
T: Clone + 'a,
Source§fn as_c_ref(from: &'a T) -> <T as RCowCompatibleRef<'a>>::RefC
fn as_c_ref(from: &'a T) -> <T as RCowCompatibleRef<'a>>::RefC
Source§fn as_rust_ref(from: <T as RCowCompatibleRef<'a>>::RefC) -> &'a T
fn as_rust_ref(from: <T as RCowCompatibleRef<'a>>::RefC) -> &'a T
Source§impl<S> ROExtAcc for S
impl<S> ROExtAcc for S
Source§fn f_get<F>(&self, offset: FieldOffset<S, F, Aligned>) -> &F
fn f_get<F>(&self, offset: FieldOffset<S, F, Aligned>) -> &F
offset
. Read moreSource§fn f_get_mut<F>(&mut self, offset: FieldOffset<S, F, Aligned>) -> &mut F
fn f_get_mut<F>(&mut self, offset: FieldOffset<S, F, Aligned>) -> &mut F
offset
. Read moreSource§fn f_get_ptr<F, A>(&self, offset: FieldOffset<S, F, A>) -> *const F
fn f_get_ptr<F, A>(&self, offset: FieldOffset<S, F, A>) -> *const F
offset
. Read moreSource§fn f_get_mut_ptr<F, A>(&mut self, offset: FieldOffset<S, F, A>) -> *mut F
fn f_get_mut_ptr<F, A>(&mut self, offset: FieldOffset<S, F, A>) -> *mut F
offset
. Read moreSource§impl<S> ROExtOps<Aligned> for S
impl<S> ROExtOps<Aligned> for S
Source§fn f_replace<F>(&mut self, offset: FieldOffset<S, F, Aligned>, value: F) -> F
fn f_replace<F>(&mut self, offset: FieldOffset<S, F, Aligned>, value: F) -> F
offset
) with value
,
returning the previous value of the field. Read moreSource§fn f_get_copy<F>(&self, offset: FieldOffset<S, F, Aligned>) -> Fwhere
F: Copy,
fn f_get_copy<F>(&self, offset: FieldOffset<S, F, Aligned>) -> Fwhere
F: Copy,
Source§impl<S> ROExtOps<Unaligned> for S
impl<S> ROExtOps<Unaligned> for S
Source§fn f_replace<F>(&mut self, offset: FieldOffset<S, F, Unaligned>, value: F) -> F
fn f_replace<F>(&mut self, offset: FieldOffset<S, F, Unaligned>, value: F) -> F
offset
) with value
,
returning the previous value of the field. Read moreSource§fn f_get_copy<F>(&self, offset: FieldOffset<S, F, Unaligned>) -> Fwhere
F: Copy,
fn f_get_copy<F>(&self, offset: FieldOffset<S, F, Unaligned>) -> Fwhere
F: Copy,
Source§impl<T> SelfOps for Twhere
T: ?Sized,
impl<T> SelfOps for Twhere
T: ?Sized,
Source§fn piped<F, U>(self, f: F) -> U
fn piped<F, U>(self, f: F) -> U
Source§fn piped_ref<'a, F, U>(&'a self, f: F) -> Uwhere
F: FnOnce(&'a Self) -> U,
fn piped_ref<'a, F, U>(&'a self, f: F) -> Uwhere
F: FnOnce(&'a Self) -> U,
piped
except that the function takes &Self
Useful for functions that take &Self
instead of Self
. Read moreSource§fn piped_mut<'a, F, U>(&'a mut self, f: F) -> Uwhere
F: FnOnce(&'a mut Self) -> U,
fn piped_mut<'a, F, U>(&'a mut self, f: F) -> Uwhere
F: FnOnce(&'a mut Self) -> U,
piped
, except that the function takes &mut Self
.
Useful for functions that take &mut Self
instead of Self
.Source§fn mutated<F>(self, f: F) -> Self
fn mutated<F>(self, f: F) -> Self
Source§fn observe<F>(self, f: F) -> Self
fn observe<F>(self, f: F) -> Self
Source§fn as_ref_<T>(&self) -> &T
fn as_ref_<T>(&self) -> &T
AsRef
,
using the turbofish .as_ref_::<_>()
syntax. Read more