pub trait IO {
type StorageValue: StorageIntermediate;
Show 16 methods
// Required methods
fn read_input(&self) -> Self::StorageValue;
fn return_output(&mut self, value: &[u8]);
fn read_storage(&self, key: &[u8]) -> Option<Self::StorageValue>;
fn storage_has_key(&self, key: &[u8]) -> bool;
fn write_storage(
&mut self,
key: &[u8],
value: &[u8],
) -> Option<Self::StorageValue>;
fn write_storage_direct(
&mut self,
key: &[u8],
value: Self::StorageValue,
) -> Option<Self::StorageValue>;
fn remove_storage(&mut self, key: &[u8]) -> Option<Self::StorageValue>;
// Provided methods
fn read_storage_len(&self, key: &[u8]) -> Option<usize> { ... }
fn read_input_borsh<U: BorshDeserialize>(
&self,
) -> Result<U, BorshDeserializeError> { ... }
fn read_input_arr20(&self) -> Result<[u8; 20], IncorrectInputLength> { ... }
fn read_input_arr32(&self) -> Result<[u8; 32], IncorrectInputLength> { ... }
fn read_input_and_store(&mut self, key: &[u8]) { ... }
fn read_u32(&self, key: &[u8]) -> Result<u32, ReadU32Error> { ... }
fn read_u64(&self, key: &[u8]) -> Result<u64, ReadU64Error> { ... }
fn read_u256(&self, key: &[u8]) -> Result<U256, ReadU256Error> { ... }
fn write_borsh<T: BorshSerialize>(
&mut self,
key: &[u8],
value: &T,
) -> Option<Self::StorageValue> { ... }
}Expand description
Trait for reading/writing values from storage and a generalized stdin/stdout.
Required Associated Types§
Sourcetype StorageValue: StorageIntermediate
type StorageValue: StorageIntermediate
A type giving a reference to a value obtained by IO without loading it into memory. For example, in the case of a wasm contract on NEAR this will correspond to a register index.
Required Methods§
Sourcefn read_input(&self) -> Self::StorageValue
fn read_input(&self) -> Self::StorageValue
Read bytes that were passed as input to the process. This can be thought of as a
generalization of stdin or command-line arguments. In the case of wasm contracts
on NEAR these would be the arguments to the method.
Sourcefn return_output(&mut self, value: &[u8])
fn return_output(&mut self, value: &[u8])
Return a value to an external process. In the case of wasm contracts on NEAR this corresponds to the return value from the contract method.
Sourcefn read_storage(&self, key: &[u8]) -> Option<Self::StorageValue>
fn read_storage(&self, key: &[u8]) -> Option<Self::StorageValue>
Read the value in storage at the given key, if any.
Sourcefn storage_has_key(&self, key: &[u8]) -> bool
fn storage_has_key(&self, key: &[u8]) -> bool
Check if there is a value in storage at the given key, but do not read the value.
Equivalent to self.read_storage(key).is_some() but more efficient.
Sourcefn write_storage(
&mut self,
key: &[u8],
value: &[u8],
) -> Option<Self::StorageValue>
fn write_storage( &mut self, key: &[u8], value: &[u8], ) -> Option<Self::StorageValue>
Write the given value to storage under the given key. Returns a reference to the old value stored at that key (if any).
Sourcefn write_storage_direct(
&mut self,
key: &[u8],
value: Self::StorageValue,
) -> Option<Self::StorageValue>
fn write_storage_direct( &mut self, key: &[u8], value: Self::StorageValue, ) -> Option<Self::StorageValue>
Write a StorageIntermediate to storage directly under the given key
(without ever needing to load the value into memory).Returns a reference
to the old value stored at that key (if any).
Sourcefn remove_storage(&mut self, key: &[u8]) -> Option<Self::StorageValue>
fn remove_storage(&mut self, key: &[u8]) -> Option<Self::StorageValue>
Remove entry from storage and capture the value present at the given key (if any)
Provided Methods§
Sourcefn read_storage_len(&self, key: &[u8]) -> Option<usize>
fn read_storage_len(&self, key: &[u8]) -> Option<usize>
Read the length of the bytes stored at the given key.
Sourcefn read_input_borsh<U: BorshDeserialize>(
&self,
) -> Result<U, BorshDeserializeError>
fn read_input_borsh<U: BorshDeserialize>( &self, ) -> Result<U, BorshDeserializeError>
Convenience function to read the input and deserialize the bytes using borsh.
Sourcefn read_input_arr20(&self) -> Result<[u8; 20], IncorrectInputLength>
fn read_input_arr20(&self) -> Result<[u8; 20], IncorrectInputLength>
Convenience function to read the input into a 20-byte array.
Sourcefn read_input_arr32(&self) -> Result<[u8; 32], IncorrectInputLength>
fn read_input_arr32(&self) -> Result<[u8; 32], IncorrectInputLength>
Convenience function to read the input into a 32-byte array.
Sourcefn read_input_and_store(&mut self, key: &[u8])
fn read_input_and_store(&mut self, key: &[u8])
Convenience function to store the input directly in storage under the given key (without ever loading it into memory).
Sourcefn read_u32(&self, key: &[u8]) -> Result<u32, ReadU32Error>
fn read_u32(&self, key: &[u8]) -> Result<u32, ReadU32Error>
Convenience function to read a 32-bit unsigned integer from storage (assumes little-endian encoding).
Sourcefn read_u64(&self, key: &[u8]) -> Result<u64, ReadU64Error>
fn read_u64(&self, key: &[u8]) -> Result<u64, ReadU64Error>
Convenience function to read a 64-bit unsigned integer from storage (assumes little-endian encoding).
Sourcefn read_u256(&self, key: &[u8]) -> Result<U256, ReadU256Error>
fn read_u256(&self, key: &[u8]) -> Result<U256, ReadU256Error>
Convenience function to read a 256-bit unsigned integer from storage (assumes big-endian encoding).
fn write_borsh<T: BorshSerialize>( &mut self, key: &[u8], value: &T, ) -> Option<Self::StorageValue>
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.