Enum near_sdk::PromiseOrValue
source · pub enum PromiseOrValue<T> {
Promise(Promise),
Value(T),
}
Expand description
When the method can return either a promise or a value, it can be called with PromiseOrValue::Promise
or PromiseOrValue::Value
to specify which one should be returned.
Example
#[ext_contract]
pub trait ContractA {
fn a(&mut self);
}
let value = Some(true);
let val: PromiseOrValue<bool> = if let Some(value) = value {
PromiseOrValue::Value(value)
} else {
contract_a::ext("bob_near".parse().unwrap()).a().into()
};
Variants
Promise(Promise)
Value(T)
Trait Implementations
sourceimpl<T> BorshSchema for PromiseOrValue<T>where
T: BorshSchema,
impl<T> BorshSchema for PromiseOrValue<T>where
T: BorshSchema,
sourcefn add_definitions_recursively(
definitions: &mut HashMap<Declaration, Definition>
)
fn add_definitions_recursively(
definitions: &mut HashMap<Declaration, Definition>
)
Recursively, using DFS, add type definitions required for this type. For primitive types
this is an empty map. Type definition explains how to serialize/deserialize a type. Read more
sourcefn declaration() -> Declaration
fn declaration() -> Declaration
Get the name of the type without brackets.
sourcefn add_definition(
declaration: String,
definition: Definition,
definitions: &mut HashMap<String, Definition, RandomState>
)
fn add_definition(
declaration: String,
definition: Definition,
definitions: &mut HashMap<String, Definition, RandomState>
)
Helper method to add a single type definition to the map.
fn schema_container() -> BorshSchemaContainer
sourceimpl<T: BorshSerialize> BorshSerialize for PromiseOrValue<T>
impl<T: BorshSerialize> BorshSerialize for PromiseOrValue<T>
sourceimpl<T> From<Promise> for PromiseOrValue<T>
impl<T> From<Promise> for PromiseOrValue<T>
sourceimpl<T: JsonSchema> JsonSchema for PromiseOrValue<T>
impl<T: JsonSchema> JsonSchema for PromiseOrValue<T>
sourcefn schema_name() -> String
fn schema_name() -> String
The name of the generated JSON Schema. Read more
sourcefn json_schema(gen: &mut SchemaGenerator) -> Schema
fn json_schema(gen: &mut SchemaGenerator) -> Schema
Generates a JSON Schema for this type. Read more
sourcefn is_referenceable() -> bool
fn is_referenceable() -> bool
Whether JSON Schemas generated for this type should be re-used where possible using the
$ref
keyword. Read moreAuto Trait Implementations
impl<T> !RefUnwindSafe for PromiseOrValue<T>
impl<T> !Send for PromiseOrValue<T>
impl<T> !Sync for PromiseOrValue<T>
impl<T> Unpin for PromiseOrValue<T>where
T: Unpin,
impl<T> !UnwindSafe for PromiseOrValue<T>
Blanket Implementations
sourceimpl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more