pub enum IDLValue {
Show 26 variants
Bool(bool),
Null,
Text(String),
Number(String),
Float64(f64),
Opt(Box<IDLValue>),
Vec(Vec<IDLValue>),
Record(Vec<IDLField>),
Variant(VariantValue),
Blob(Vec<u8>),
Principal(Principal),
Service(Principal),
Func(Principal, String),
None,
Int(Int),
Nat(Nat),
Nat8(u8),
Nat16(u16),
Nat32(u32),
Nat64(u64),
Int8(i8),
Int16(i16),
Int32(i32),
Int64(i64),
Float32(f32),
Reserved,
}
Available on crate feature
value
only.Variants§
Bool(bool)
Null
Text(String)
Number(String)
Float64(f64)
Opt(Box<IDLValue>)
Vec(Vec<IDLValue>)
Record(Vec<IDLField>)
Variant(VariantValue)
Blob(Vec<u8>)
Principal(Principal)
Service(Principal)
Func(Principal, String)
None
Int(Int)
Nat(Nat)
Nat8(u8)
Nat16(u16)
Nat32(u32)
Nat64(u64)
Int8(i8)
Int16(i16)
Int32(i32)
Int64(i64)
Float32(f32)
Reserved
Implementations§
source§impl IDLValue
impl IDLValue
sourcepub fn annotate_type(
&self,
from_parser: bool,
env: &TypeEnv,
t: &Type,
) -> Result<Self>
pub fn annotate_type( &self, from_parser: bool, env: &TypeEnv, t: &Type, ) -> Result<Self>
Anotate IDLValue
with the given type, allowing subtyping. If IDLValue
is parsed from
string, we need to set from_parser
to true to enable converting numbers to the expected
types, and disable the opt rules.
pub fn value_ty(&self) -> Type
sourcepub fn try_from_candid_type<T>(data: &T) -> Result<Self>where
T: CandidType,
pub fn try_from_candid_type<T>(data: &T) -> Result<Self>where
T: CandidType,
Converts data that implements CandidType
into an IDLValue
.
§Example: Convert data to candid text format
#[derive(CandidType)]
struct MyStruct {
a: u8,
b: String,
}
let my_struct = MyStruct { a: 42, b: "hello".to_string() };
let idl_value = IDLValue::try_from_candid_type(&my_struct).unwrap();
let expected_text = "record { a = 42 : nat8; b = \"hello\" }";
let actual_text = idl_value.to_string();
assert_eq!(expected_text, actual_text);
Trait Implementations§
source§impl CandidType for IDLValue
impl CandidType for IDLValue
source§impl<'de> Deserialize<'de> for IDLValue
impl<'de> Deserialize<'de> for IDLValue
source§fn deserialize<D>(deserializer: D) -> Result<IDLValue, D::Error>where
D: Deserializer<'de>,
fn deserialize<D>(deserializer: D) -> Result<IDLValue, D::Error>where
D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
impl StructuralPartialEq for IDLValue
Auto Trait Implementations§
impl Freeze for IDLValue
impl RefUnwindSafe for IDLValue
impl Send for IDLValue
impl Sync for IDLValue
impl Unpin for IDLValue
impl UnwindSafe for IDLValue
Blanket Implementations§
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
Mutably borrows from an owned value. Read more
source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§default unsafe fn clone_to_uninit(&self, dst: *mut T)
default unsafe fn clone_to_uninit(&self, dst: *mut T)
🔬This is a nightly-only experimental API. (
clone_to_uninit
)