Enum candid::types::value::IDLValue

source ·
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

source

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.

source

pub fn value_ty(&self) -> Type

source

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

source§

fn ty() -> Type

source§

fn id() -> TypeId

source§

fn _ty() -> Type

source§

fn idl_serialize<S>(&self, serializer: S) -> Result<(), S::Error>
where S: Serializer,

source§

impl Clone for IDLValue

source§

fn clone(&self) -> IDLValue

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 Debug for IDLValue

Available on crate feature printer only.
source§

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

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

impl<'de> Deserialize<'de> for IDLValue

source§

fn deserialize<D>(deserializer: D) -> Result<IDLValue, D::Error>
where D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
source§

impl Display for IDLValue

Available on crate feature printer only.
source§

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

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

impl PartialEq for IDLValue

source§

fn eq(&self, other: &IDLValue) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl StructuralPartialEq for IDLValue

Auto Trait Implementations§

Blanket Implementations§

source§

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

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

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

source§

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

Mutably borrows from an owned value. 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 T
where 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.

source§

impl<T> Same for T

§

type Output = T

Should always be Self
source§

impl<T> ToOwned for T
where 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
source§

impl<T> ToString for T
where T: Display + ?Sized,

source§

default fn to_string(&self) -> String

Converts the given value to a String. Read more
source§

impl<T, U> TryFrom<U> for T
where 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 T
where 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.
source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,