Struct ink::EnvAccess

source ·
pub struct EnvAccess<'a, E> { /* private fields */ }
Expand description

The API behind the self.env() and Self::env() syntax in ink!.

This allows ink! messages to make use of the environment efficiently and user friendly while also maintaining access invariants.

Implementations§

source§

impl<'a, E> EnvAccess<'a, E>where E: Environment, <E as Environment>::ChainExtension: ChainExtensionInstance,

source

pub fn extension( self ) -> <<E as Environment>::ChainExtension as ChainExtensionInstance>::Instance

Allows to call one of the available defined chain extension methods.

source§

impl<'a, E> EnvAccess<'a, E>where E: Environment,

source

pub fn caller(self) -> E::AccountId

Returns the address of the caller of the executed contract.

Example
#[ink(message)]
pub fn call_me(&self) {
    let caller = self.env().caller();
    ink::env::debug_println!("got a call from {:?}", &caller);
}
Note

For more details visit: [ink_env::caller]

source

pub fn transferred_value(self) -> E::Balance

Returns the transferred value for the contract execution.

Example
/// Allows funding the contract. Prints a debug message with the transferred value.
#[ink(message, payable)]
pub fn fund(&self) {
    let caller = self.env().caller();
    let value = self.env().transferred_value();
    ink::env::debug_println!(
        "thanks for the funding of {:?} from {:?}",
        value,
        caller
    );
}
Note

For more details visit: [ink_env::transferred_value]

source

pub fn weight_to_fee(self, gas: u64) -> E::Balance

Returns the price for the specified amount of gas.

Example
/// Returns a tuple of
///   - the result of adding the `rhs` to the `lhs`
///   - the gas costs of this addition operation
///   - the price for the gas
#[ink(message)]
pub fn addition_gas_cost(&self, rhs: i32, lhs: i32) -> (i32, u64, Balance) {
    let before = self.env().gas_left();
    let result = rhs + lhs;
    let after = self.env().gas_left();
    let gas_used = after - before;
    let gas_cost = self.env().weight_to_fee(gas_used);
    (result, gas_used, gas_cost)
}
Note

For more details visit: [ink_env::weight_to_fee]

source

pub fn gas_left(self) -> u64

Returns the amount of gas left for the contract execution.

Example
/// Returns a tuple of
///   - the result of adding the `rhs` to the `lhs` and
///   - the gas used for this addition operation.
#[ink(message)]
pub fn addition_gas_cost(&self, rhs: i32, lhs: i32) -> (i32, u64) {
    let before = self.env().gas_left();
    let result = rhs + lhs;
    let after = self.env().gas_left();
    (result, after - before)
}
Note

For more details visit: [ink_env::gas_left]

source

pub fn block_timestamp(self) -> E::Timestamp

Returns the timestamp of the current block.

Example
#[ink::contract]
pub mod my_contract {
    #[ink(storage)]
    pub struct MyContract {
        last_invocation: Timestamp,
    }

    impl MyContract {
        #[ink(constructor)]
        pub fn new() -> Self {
            Self {
                last_invocation: Self::env().block_timestamp(),
            }
        }

        /// Records the last time the message was invoked.
        #[ink(message)]
        pub fn execute_me(&mut self) {
            self.last_invocation = self.env().block_timestamp();
        }
    }
}
Note

The Substrate default for the timestamp type is the milliseconds since the Unix epoch. However, this is not guaranteed: the specific timestamp is defined by the chain environment on which this contract runs.

For more details visit: [ink_env::block_timestamp]

source

pub fn account_id(self) -> E::AccountId

Returns the account ID of the executed contract.

Example
#[ink::contract]
pub mod only_owner {
    #[ink(storage)]
    pub struct OnlyOwner {
        owner: AccountId,
        value: u32,
    }

    impl OnlyOwner {
        #[ink(constructor)]
        pub fn new() -> Self {
            Self {
                owner: Self::env().caller(),
                value: 0,
            }
        }

        /// Allows incrementing the contract's `value` only
        /// for the owner (i.e. the account which instantiated
        /// this contract.
        ///
        /// The contract panics if the caller is not the owner.
        #[ink(message)]
        pub fn increment(&mut self) {
            let caller = self.env().caller();
            assert!(self.owner == caller);
            self.value = self.value + 1;
        }
    }
}
Note

For more details visit: [ink_env::account_id]

source

pub fn balance(self) -> E::Balance

Returns the balance of the executed contract.

Example
/// Returns the contract's balance.
#[ink(message)]
pub fn my_balance(&self) -> Balance {
    self.env().balance()
}
Note

For more details visit: [ink_env::balance]

source

pub fn block_number(self) -> E::BlockNumber

Returns the current block number.

Example
#[ink::contract]
pub mod my_contract {
    #[ink(storage)]
    pub struct MyContract {
        last_invocation: BlockNumber,
    }

    impl MyContract {
        #[ink(constructor)]
        pub fn new() -> Self {
            Self {
                last_invocation: Self::env().block_number(),
            }
        }

        /// The function can be executed at most once every 100 blocks.
        #[ink(message)]
        pub fn execute_me(&mut self) {
            let now = self.env().block_number();
            assert!(now - self.last_invocation > 100);
            self.last_invocation = now;
        }
    }
}
Note

For more details visit: [ink_env::block_number]

source

pub fn minimum_balance(self) -> E::Balance

Returns the minimum balance that is required for creating an account (i.e. the chain’s existential deposit).

Example
#[ink(message)]
pub fn minimum_balance(&self) -> Balance {
    self.env().minimum_balance()
}
Note

For more details visit: [ink_env::minimum_balance]

source

pub fn emit_event<Evt>(self, event: Evt)where Evt: Event,

Emits an event.

source

pub fn instantiate_contract<ContractRef, Args, Salt, R>( self, params: &CreateParams<E, ContractRef, Args, Salt, R> ) -> Result<ConstructorResult<<R as ConstructorReturnType<ContractRef>>::Output>>where ContractRef: FromAccountId<E>, Args: Encode, Salt: AsRef<[u8]>, R: ConstructorReturnType<ContractRef>,

Instantiates another contract.

Example
use ink::env::{
    DefaultEnvironment,
    call::{build_create, Selector, ExecutionInput}
};
use other_contract::OtherContractRef;

/// Instantiates another contract.
#[ink(message)]
pub fn instantiate_contract(&self) -> MyContractRef {
    let create_params = build_create::<OtherContractRef>()
        .code_hash(Hash::from([0x42; 32]))
        .gas_limit(4000)
        .endowment(25)
        .exec_input(
            ExecutionInput::new(Selector::new(ink::selector_bytes!("new")))
                .push_arg(42)
                .push_arg(true)
                .push_arg(&[0x10u8; 32]),
        )
        .salt_bytes(&[0xCA, 0xFE, 0xBA, 0xBE])
        .returns::<OtherContractRef>()
        .params();
    self.env()
        .instantiate_contract(&create_params)
        .unwrap_or_else(|error| {
            panic!(
                "Received an error from the Contracts pallet while instantiating: {:?}",
                error
            )
        })
        .unwrap_or_else(|error| panic!("Received a `LangError` while instatiating: {:?}", error))
}

See our delegator example for a complete contract example.

Note

For more details visit: [ink_env::instantiate_contract]

source

pub fn invoke_contract_v1<Args, R>( self, params: &CallParams<E, CallV1<E>, Args, R> ) -> Result<MessageResult<R>>where Args: Encode, R: Decode,

Invokes a contract message and returns its result.

Example
use ink::env::{
    call::{
        build_call,
        CallV1,
        ExecutionInput,
        Selector,
    },
    DefaultEnvironment,
};

/// Invokes a contract message and fetches the result.
#[ink(message)]
pub fn invoke_contract(&self) -> i32 {
    let call_params = build_call::<DefaultEnvironment>()
        .call_type(
            CallV1::new(AccountId::from([0x42; 32]))
                .gas_limit(5000)
                .transferred_value(10),
        )
        .exec_input(
            ExecutionInput::new(Selector::new([0xCA, 0xFE, 0xBA, 0xBE]))
                .push_arg(42u8)
                .push_arg(true)
                .push_arg(&[0x10u8; 32]),
        )
        .returns::<i32>()
        .params();

    self.env()
        .invoke_contract_v1(&call_params)
        .unwrap_or_else(|env_err| {
            panic!("Received an error from the Environment: {:?}", env_err)
        })
        .unwrap_or_else(|lang_err| panic!("Received a `LangError`: {:?}", lang_err))
}
Note

For more details visit: [ink_env::invoke_contract_v1]

source

pub fn invoke_contract<Args, R>( self, params: &CallParams<E, Call<E>, Args, R> ) -> Result<MessageResult<R>>where Args: Encode, R: Decode,

Invokes a contract message and returns its result.

Example
use ink::env::{
    call::{
        build_call,
        CallV1,
        ExecutionInput,
        Selector,
    },
    DefaultEnvironment,
};

/// Invokes a contract message and fetches the result.
#[ink(message)]
pub fn invoke_contract_v2(&self) -> i32 {
    let call_params = build_call::<DefaultEnvironment>()
        .call(AccountId::from([0x42; 32]))
        .ref_time_limit(500_000_000)
        .proof_time_limit(100_000)
        .storage_deposit_limit(1_000_000_000)
        .exec_input(
            ExecutionInput::new(Selector::new([0xCA, 0xFE, 0xBA, 0xBE]))
                .push_arg(42u8)
                .push_arg(true)
                .push_arg(&[0x10u8; 32]),
        )
        .returns::<i32>()
        .params();

    self.env()
        .invoke_contract(&call_params)
        .unwrap_or_else(|env_err| {
            panic!("Received an error from the Environment: {:?}", env_err)
        })
        .unwrap_or_else(|lang_err| panic!("Received a `LangError`: {:?}", lang_err))
}
Note

For more details visit: [ink_env::invoke_contract]

source

pub fn invoke_contract_delegate<Args, R>( self, params: &CallParams<E, DelegateCall<E>, Args, R> ) -> Result<MessageResult<R>>where Args: Encode, R: Decode,

Invokes in delegate manner a code message and returns its result.

Example
use ink::env::{
    call::{
        build_call,
        utils::ReturnType,
        DelegateCall,
        ExecutionInput,
        Selector,
    },
    DefaultEnvironment,
};
use ink_primitives::Clear;

/// Invokes in delegate manner a contract message and fetches the result.
#[ink(message)]
pub fn invoke_contract_delegate(&self) -> i32 {
    let call_params = build_call::<DefaultEnvironment>()
        .call_type(DelegateCall::new(
            <DefaultEnvironment as ink::env::Environment>::Hash::CLEAR_HASH,
        ))
        .exec_input(
            ExecutionInput::new(Selector::new([0xCA, 0xFE, 0xBA, 0xBE]))
                .push_arg(42u8)
                .push_arg(true)
                .push_arg(&[0x10u8; 32]),
        )
        .returns::<i32>()
        .params();
    self.env()
        .invoke_contract_delegate(&call_params)
        .unwrap_or_else(|env_err| {
            panic!("Received an error from the Environment: {:?}", env_err)
        })
        .unwrap_or_else(|lang_err| panic!("Received a `LangError`: {:?}", lang_err))
}
Note

For more details visit: [ink_env::invoke_contract_delegate]

source

pub fn terminate_contract(self, beneficiary: E::AccountId) -> !

Terminates the existence of a contract.

Example
/// Terminates with the caller as beneficiary.
#[ink(message)]
pub fn terminate_me(&mut self) {
    self.env().terminate_contract(self.env().caller());
}
Note

For more details visit: [ink_env::terminate_contract]

source

pub fn transfer( self, destination: E::AccountId, value: E::Balance ) -> Result<()>

Transfers value from the contract to the destination account ID.

Example
/// Transfers the token amount ten to the caller.
#[ink(message)]
pub fn give_me_ten(&mut self) {
    let value: Balance = 10;
    self.env()
        .transfer(self.env().caller(), value)
        .unwrap_or_else(|err| panic!("transfer failed: {:?}", err));
}
Note

For more details visit: [ink_env::transfer]

source

pub fn hash_bytes<H>(self, input: &[u8]) -> <H as HashOutput>::Typewhere H: CryptoHash,

Computes the hash of the given bytes using the cryptographic hash H.

Example
use ink_env::hash::{
    HashOutput,
    Sha2x256,
};

let input: &[u8] = &[13, 14, 15];
let mut output = <Sha2x256 as HashOutput>::Type::default(); // 256-bit buffer
let hash = ink_env::hash_bytes::<Sha2x256>(input, &mut output);
Note

For more details visit: [ink_env::hash_bytes]

source

pub fn hash_encoded<H, V>(self, value: &V) -> <H as HashOutput>::Typewhere H: CryptoHash, V: Encode,

Computes the hash of the given SCALE encoded value using the cryptographic hash H.

Example
use ink_env::hash::{
    HashOutput,
    Sha2x256,
};

let encodable = (42, "foo", true); // Implements `scale::Encode`
let mut output = <Sha2x256 as HashOutput>::Type::default(); // 256-bit buffer
ink_env::hash_encoded::<Sha2x256, _>(&encodable, &mut output);

const EXPECTED: [u8; 32] = [
    243, 242, 58, 110, 205, 68, 100, 244, 187, 55, 188, 248, 29, 136, 145, 115, 186,
    134, 14, 175, 178, 99, 183, 21, 4, 94, 92, 69, 199, 207, 241, 179,
];
assert_eq!(output, EXPECTED);
Note

For more details visit: [ink_env::hash_encoded]

source

pub fn ecdsa_recover( self, signature: &[u8; 65], message_hash: &[u8; 32] ) -> Result<[u8; 33]>

Recovers the compressed ECDSA public key for given signature and message_hash, and stores the result in output.

Example
/// Recovery from pre-defined signature and message hash
#[ink(message)]
pub fn ecdsa_recover(&self) {
    const signature: [u8; 65] = [
        195, 218, 227, 165, 226, 17, 25, 160, 37, 92, 142, 238, 4, 41, 244, 211, 18,
        94, 131, 116, 231, 116, 255, 164, 252, 248, 85, 233, 173, 225, 26, 185, 119,
        235, 137, 35, 204, 251, 134, 131, 186, 215, 76, 112, 17, 192, 114, 243, 102,
        166, 176, 140, 180, 124, 213, 102, 117, 212, 89, 89, 92, 209, 116, 17, 28,
    ];
    const message_hash: [u8; 32] = [
        167, 124, 116, 195, 220, 156, 244, 20, 243, 69, 1, 98, 189, 205, 79, 108,
        213, 78, 65, 65, 230, 30, 17, 37, 184, 220, 237, 135, 1, 209, 101, 229,
    ];
    const EXPECTED_COMPRESSED_PUBLIC_KEY: [u8; 33] = [
        3, 110, 192, 35, 209, 24, 189, 55, 218, 250, 100, 89, 40, 76, 222, 208, 202,
        127, 31, 13, 58, 51, 242, 179, 13, 63, 19, 22, 252, 164, 226, 248, 98,
    ];
    let result = self.env().ecdsa_recover(&signature, &message_hash);
    assert!(result.is_ok());
    assert_eq!(
        result.unwrap().as_ref(),
        EXPECTED_COMPRESSED_PUBLIC_KEY.as_ref()
    );

    // Pass invalid zero message hash
    let failed_result = self.env().ecdsa_recover(&signature, &[0; 32]);
    assert!(failed_result.is_err());
    if let Err(e) = failed_result {
        assert_eq!(e, ink::env::ReturnErrorCode::EcdsaRecoveryFailed.into());
    }
}
source

pub fn ecdsa_to_eth_address(self, pubkey: &[u8; 33]) -> Result<[u8; 20]>

Returns an Ethereum address from the ECDSA compressed public key.

Example
#[ink(message)]
pub fn ecdsa_to_eth_address(&self) {
    let pub_key = [
        3, 110, 192, 35, 209, 24, 189, 55, 218, 250, 100, 89, 40, 76, 222, 208, 202, 127,
        31, 13, 58, 51, 242, 179, 13, 63, 19, 22, 252, 164, 226, 248, 98,
    ];
    let EXPECTED_ETH_ADDRESS = [
        253, 240, 181, 194, 143, 66, 163, 109, 18, 211, 78, 49, 177, 94, 159, 79, 207,
        37, 21, 191,
    ];
    let output = self
        .env()
        .ecdsa_to_eth_address(&pub_key)
        .unwrap_or_else(|err| panic!("must return an Ethereum address for the compressed public key: {:?}", err));
    assert_eq!(output, EXPECTED_ETH_ADDRESS);
}
Note

For more details visit: [ink_env::ecdsa_to_eth_address]

source

pub fn sr25519_verify( self, signature: &[u8; 64], message: &[u8], pub_key: &[u8; 32] ) -> Result<()>

Verifies a SR25519 signature against a message and a public key.

Example
#[ink(message)]
pub fn sr25519_verify(&self) {
    let mut signature: [u8; 64] = [
        10, 125, 162, 182, 49, 112, 76, 220, 254, 147, 199, 64, 228, 18, 23, 185,
        172, 102, 122, 12, 135, 85, 216, 218, 26, 130, 50, 219, 82, 127, 72, 124,
        135, 231, 128, 210, 237, 193, 137, 106, 235, 107, 27, 239, 11, 199, 195, 141,
        157, 242, 19, 91, 99, 62, 171, 139, 251, 23, 119, 232, 47, 173, 58, 143,
    ];
    let mut message: [u8; 49] = [
        60, 66, 121, 116, 101, 115, 62, 48, 120, 52, 54, 102, 98, 55, 52, 48, 56,
        100, 52, 102, 50, 56, 53, 50, 50, 56, 102, 52, 97, 102, 53, 49, 54, 101, 97,
        50, 53, 56, 53, 49, 98, 60, 47, 66, 121, 116, 101, 115, 62,
    ];
    let mut public_key: [u8; 32] = [
        212, 53, 147, 199, 21, 253, 211, 28, 97, 20, 26, 189, 4, 169, 159, 214, 130,
        44, 133, 88, 133, 76, 205, 227, 154, 86, 132, 231, 165, 109, 162, 125,
    ];
    let result = ink::env::sr25519_verify(&signature, &message, &public_key);
    assert_eq!(result, Ok(()));
}
Note

The context for sr25519 signing is hard-coded to “substrate” to match sr25519 signing in substrate.

For more details visit: [ink_env::sr25519_verify]

WARNING: this function is from the unstable interface, which is unsafe and normally is not available on production chains.

source

pub fn is_contract(self, account_id: &E::AccountId) -> bool

Checks whether a specified account belongs to a contract.

Example
#[ink(message)]
pub fn is_contract(&mut self, account_id: AccountId) -> bool {
    self.env().is_contract(&account_id)
}
Note

For more details visit: [ink_env::is_contract]

source

pub fn caller_is_origin(self) -> bool

Checks whether the caller of the current contract is the origin of the whole call stack.

Example
#[ink(message)]
pub fn caller_is_origin(&mut self) -> bool {
    self.env().caller_is_origin()
}
Note

For more details visit: [ink_env::caller_is_origin]

source

pub fn code_hash(self, account_id: &E::AccountId) -> Result<E::Hash>

Returns the code hash of the contract at the given account id.

Example
#[ink(message)]
pub fn code_hash(&mut self, account_id: AccountId) -> Option<Hash> {
    self.env().code_hash(&account_id).ok()
}
Note

For more details visit: [ink_env::code_hash]

source

pub fn own_code_hash(self) -> Result<E::Hash>

Returns the code hash of the contract at the given account id.

Example
#[ink(message)]
pub fn own_code_hash(&mut self) -> Hash {
    self.env()
        .own_code_hash()
        .unwrap_or_else(|err| panic!("contract should have a code hash: {:?}", err))
}
Note

For more details visit: [ink_env::own_code_hash]

source

pub fn set_code_hash(self, code_hash: &E::Hash) -> Result<()>

Replace the contract code at the specified address with new code.

Example
#[ink(message)]
pub fn set_code_hash(&mut self, code_hash: Hash) {
    self.env()
        .set_code_hash(&code_hash)
        .unwrap_or_else(|err| panic!("failed to set code hash: {:?}", err))
}
Note

For more details visit: [ink_env::set_code_hash]

source

pub fn call_runtime<Call: Encode>(self, call: &Call) -> Result<()>

Trait Implementations§

source§

impl<'a, E: Clone> Clone for EnvAccess<'a, E>

source§

fn clone(&self) -> EnvAccess<'a, E>

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl<'a, E> Debug for EnvAccess<'a, E>

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl<'a, E> Default for EnvAccess<'a, E>

source§

fn default() -> Self

Returns the “default value” for a type. Read more
source§

impl<'a, E: Copy> Copy for EnvAccess<'a, E>

Auto Trait Implementations§

§

impl<'a, E> RefUnwindSafe for EnvAccess<'a, E>

§

impl<'a, E> Send for EnvAccess<'a, E>

§

impl<'a, E> Sync for EnvAccess<'a, E>

§

impl<'a, E> Unpin for EnvAccess<'a, E>

§

impl<'a, E> UnwindSafe for EnvAccess<'a, E>

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
§

impl<T> Conv for T

§

fn conv<T>(self) -> Twhere Self: Into<T>,

Converts self into T using Into<T>. Read more
source§

impl<T> DynClone for Twhere T: Clone,

source§

fn __clone_box(&self, _: Private) -> *mut ()

§

impl<T> FmtForward for T

§

fn fmt_binary(self) -> FmtBinary<Self>where Self: Binary,

Causes self to use its Binary implementation when Debug-formatted.
§

fn fmt_display(self) -> FmtDisplay<Self>where Self: Display,

Causes self to use its Display implementation when Debug-formatted.
§

fn fmt_lower_exp(self) -> FmtLowerExp<Self>where Self: LowerExp,

Causes self to use its LowerExp implementation when Debug-formatted.
§

fn fmt_lower_hex(self) -> FmtLowerHex<Self>where Self: LowerHex,

Causes self to use its LowerHex implementation when Debug-formatted.
§

fn fmt_octal(self) -> FmtOctal<Self>where Self: Octal,

Causes self to use its Octal implementation when Debug-formatted.
§

fn fmt_pointer(self) -> FmtPointer<Self>where Self: Pointer,

Causes self to use its Pointer implementation when Debug-formatted.
§

fn fmt_upper_exp(self) -> FmtUpperExp<Self>where Self: UpperExp,

Causes self to use its UpperExp implementation when Debug-formatted.
§

fn fmt_upper_hex(self) -> FmtUpperHex<Self>where Self: UpperHex,

Causes self to use its UpperHex implementation when Debug-formatted.
§

fn fmt_list(self) -> FmtList<Self>where &'a Self: for<'a> IntoIterator,

Formats each item in a sequence. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

§

impl<T> Pipe for Twhere T: ?Sized,

§

fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere Self: Sized,

Pipes by value. This is generally the method you want to use. Read more
§

fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere R: 'a,

Borrows self and passes that borrow into the pipe function. Read more
§

fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere R: 'a,

Mutably borrows self and passes that borrow into the pipe function. Read more
§

fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> Rwhere Self: Borrow<B>, B: 'a + ?Sized, R: 'a,

Borrows self, then passes self.borrow() into the pipe function. Read more
§

fn pipe_borrow_mut<'a, B, R>( &'a mut self, func: impl FnOnce(&'a mut B) -> R ) -> Rwhere Self: BorrowMut<B>, B: 'a + ?Sized, R: 'a,

Mutably borrows self, then passes self.borrow_mut() into the pipe function. Read more
§

fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> Rwhere Self: AsRef<U>, U: 'a + ?Sized, R: 'a,

Borrows self, then passes self.as_ref() into the pipe function.
§

fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> Rwhere Self: AsMut<U>, U: 'a + ?Sized, R: 'a,

Mutably borrows self, then passes self.as_mut() into the pipe function.
§

fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> Rwhere Self: Deref<Target = T>, T: 'a + ?Sized, R: 'a,

Borrows self, then passes self.deref() into the pipe function.
§

fn pipe_deref_mut<'a, T, R>( &'a mut self, func: impl FnOnce(&'a mut T) -> R ) -> Rwhere Self: DerefMut<Target = T> + Deref, T: 'a + ?Sized, R: 'a,

Mutably borrows self, then passes self.deref_mut() into the pipe function.
source§

impl<T> Same for T

§

type Output = T

Should always be Self
§

impl<T> Tap for T

§

fn tap(self, func: impl FnOnce(&Self)) -> Self

Immutable access to a value. Read more
§

fn tap_mut(self, func: impl FnOnce(&mut Self)) -> Self

Mutable access to a value. Read more
§

fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Selfwhere Self: Borrow<B>, B: ?Sized,

Immutable access to the Borrow<B> of a value. Read more
§

fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Selfwhere Self: BorrowMut<B>, B: ?Sized,

Mutable access to the BorrowMut<B> of a value. Read more
§

fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Selfwhere Self: AsRef<R>, R: ?Sized,

Immutable access to the AsRef<R> view of a value. Read more
§

fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Selfwhere Self: AsMut<R>, R: ?Sized,

Mutable access to the AsMut<R> view of a value. Read more
§

fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Selfwhere Self: Deref<Target = T>, T: ?Sized,

Immutable access to the Deref::Target of a value. Read more
§

fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Selfwhere Self: DerefMut<Target = T> + Deref, T: ?Sized,

Mutable access to the Deref::Target of a value. Read more
§

fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self

Calls .tap() only in debug builds, and is erased in release builds.
§

fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self

Calls .tap_mut() only in debug builds, and is erased in release builds.
§

fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Selfwhere Self: Borrow<B>, B: ?Sized,

Calls .tap_borrow() only in debug builds, and is erased in release builds.
§

fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Selfwhere Self: BorrowMut<B>, B: ?Sized,

Calls .tap_borrow_mut() only in debug builds, and is erased in release builds.
§

fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Selfwhere Self: AsRef<R>, R: ?Sized,

Calls .tap_ref() only in debug builds, and is erased in release builds.
§

fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Selfwhere Self: AsMut<R>, R: ?Sized,

Calls .tap_ref_mut() only in debug builds, and is erased in release builds.
§

fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Selfwhere Self: Deref<Target = T>, T: ?Sized,

Calls .tap_deref() only in debug builds, and is erased in release builds.
§

fn tap_deref_mut_dbg<T>(self, func: impl FnOnce(&mut T)) -> Selfwhere Self: DerefMut<Target = T> + Deref, T: ?Sized,

Calls .tap_deref_mut() only in debug builds, and is erased in release builds.
source§

impl<T> ToOwned for Twhere T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
§

impl<T> TryConv for T

§

fn try_conv<T>(self) -> Result<T, Self::Error>where Self: TryInto<T>,

Attempts to convert self into T using TryInto<T>. Read more
source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<V, T> VZip<V> for Twhere V: MultiLane<T>,

§

fn vzip(self) -> V

source§

impl<T> ImpliesReturn<T> for T