Skip to main content

CandyShared

Enum CandyShared 

Source
pub enum CandyShared {
Show 24 variants Int(Int), Int8(i8), Int16(i16), Int32(i32), Int64(i64), Ints(Vec<Int>), Nat(Nat), Nat8(u8), Nat16(u16), Nat32(u32), Nat64(u64), Float(f64), Text(String), Bool(bool), Blob(Vec<u8>), Bytes(Vec<u8>), Class(Vec<PropertyShared>), Principal(Principal), Option(Option<Box<CandyShared>>), Array(Vec<CandyShared>), Nats(Vec<Nat>), Floats(Vec<f64>), Map(HashMap<CandyShared, CandyShared>), Set(HashSet<CandyShared>),
}
Expand description

CandyShared is a Rust enum that provides a wrapper type for convenient data manipulation inside ICP canisters. This enum includes various data types that can be used for communication between canisters, including integers, floats, text, boolean, and more.

Variants§

§

Int(Int)

§

Int8(i8)

§

Int16(i16)

§

Int32(i32)

§

Int64(i64)

§

Ints(Vec<Int>)

§

Nat(Nat)

§

Nat8(u8)

§

Nat16(u16)

§

Nat32(u32)

§

Nat64(u64)

§

Float(f64)

§

Text(String)

§

Bool(bool)

§

Blob(Vec<u8>)

§

Bytes(Vec<u8>)

§

Class(Vec<PropertyShared>)

§

Principal(Principal)

§

Option(Option<Box<CandyShared>>)

§

Array(Vec<CandyShared>)

§

Nats(Vec<Nat>)

§

Floats(Vec<f64>)

§

Map(HashMap<CandyShared, CandyShared>)

§

Set(HashSet<CandyShared>)

Implementations§

Source§

impl CandyShared

Source

pub fn to_nat(self) -> Option<u128>

to_nat is a method defined on the CandyShared Rust enum that provides a convenient way to convert a value to a natural number of size u128. This method uses the to_nat_of_size! macro to perform the conversion.

§Examples
use candy::value::{CandyShared, ToCandyValue};

let value = 42_u128.to_candy();
let result = value.to_nat();
assert_eq!(result, Some(42));
Source

pub fn to_nat8(self) -> Option<u8>

to_nat8 is a method defined on the CandyShared Rust enum that provides a convenient way to convert a value to an 8-bit natural number (u8). This method uses the to_nat_of_size! macro to perform the conversion.

§Examples
use candy::value::{CandyShared, ToCandyValue};

let value = 420000_u128.to_candy();
let result = value.to_nat8();
assert_eq!(result, None);

let value = 42_u8.to_candy();
let result = value.to_nat8();
assert_eq!(result, Some(42));
Source

pub fn to_nat16(self) -> Option<u16>

to_nat16 is a method defined on the CandyShared Rust enum that provides a convenient way to convert a value to a natural number of size u16. This method uses the to_nat_of_size! macro to perform the conversion.

§Examples
use candy::value::{CandyShared,ToCandyValue};

let value = 42_u16.to_candy();
let result = value.to_nat16();
assert_eq!(result, Some(42));
Source

pub fn to_nat32(self) -> Option<u32>

to_nat32 is a method defined on the CandyShared Rust enum that provides a convenient way to convert a value to a natural number of size u32. This method uses the to_nat_of_size! macro to perform the conversion.

§Examples
use candy::value::{CandyShared,ToCandyValue};

let value = 42_u32.to_candy();
let result = value.to_nat32();
assert_eq!(result, Some(42));
Source

pub fn to_nat64(self) -> Option<u64>

to_nat64 is a method defined on the CandyShared Rust enum that provides a convenient way to convert a value to a natural number of size u64. This method returns an Option<u64> that contains the resulting u64 value if the conversion is successful, and None otherwise.

§Examples
use candy::value::{CandyShared, ToCandyValue};

let value = 42_u128.to_candy();
let result = value.to_nat64();
assert_eq!(result, Some(42));
Source

pub fn to_int(self) -> Option<i128>

to_int is a method defined on the CandyShared Rust enum that provides a convenient way to convert a value to a signed integer of size i128. This method uses the to_int_of_size! macro to perform the conversion.

§Examples
use candy::value::{CandyShared, ToCandyValue};

let value = 42_u128.to_candy();
let result = value.to_int();
assert_eq!(result, Some(42));
Source

pub fn to_int8(self) -> Option<i8>

to_int8 is a method defined on the CandyShared Rust enum that provides a convenient way to convert a value to an i8 signed integer. This method returns an Option<i8> that contains the resulting i8 value if the conversion is successful, and None otherwise.

§Examples
use candy::value::{CandyShared,ToCandyValue};

let value = 42_u128.to_candy();
let result = value.to_int8();
assert_eq!(result, Some(42));
Source

pub fn to_int16(self) -> Option<i16>

to_int16 is a method defined on the CandyShared Rust enum that provides a convenient way to convert a value to a signed 16-bit integer (i16). This method returns an Option<i16> that contains the resulting i16 value if the conversion is successful, and None otherwise.

§Examples
use candy::value::{CandyShared, ToCandyValue};

let value = 42_i128.to_candy();
let result = value.to_int16();
assert_eq!(result, Some(42));

let value = (-32768_i64).to_candy();
let result = value.to_int16();
assert_eq!(result, Some(-32768));
Source

pub fn to_int32(self) -> Option<i32>

to_int32 is a method defined on the CandyShared Rust enum that provides a convenient way to convert a value to a 32-bit signed integer. This method returns an Option<i32> that contains the resulting i32 value if the conversion is successful, and None otherwise.

§Examples
use candy::value::{CandyShared, ToCandyValue};

let value = 42_i128.to_candy();
let result = value.to_int32();
assert_eq!(result, Some(42));
Source

pub fn to_int64(self) -> Option<i64>

to_int64 is a method defined on the CandyShared Rust enum that provides a convenient way to convert a value to a signed integer of size i64. This method uses the to_int_of_size! macro to perform the conversion.

§Examples
use candy::value::{CandyShared, ToCandyValue};

let value = 42_i64.to_candy();
let result = value.to_int64();
assert_eq!(result, Some(42));
Source

pub fn to_float(self) -> Option<f64>

to_float is a method defined on the CandyShared Rust enum that provides a convenient way to convert a value to a f64 floating-point number. This method returns an Option<f64> that contains the resulting f64 value if the conversion is successful, and None otherwise.

§Examples
use candy::value::{CandyShared,ToCandyValue};

let value = 42_u128.to_candy();
let result = value.to_float();
assert_eq!(result, Some(42.0));
Source

pub fn to_bool(self) -> Option<bool>

to_bool is a method defined on the CandyShared Rust enum that provides a convenient way to convert a value to a bool boolean. This method returns an Option<bool> that contains the resulting bool value if the conversion is successful, and None otherwise.

§Examples
use candy::value::{CandyShared, ToCandyValue};

let value = true.to_candy();
let result = value.to_bool();
assert_eq!(result, Some(true));
Source

pub fn to_principal(self) -> Option<Principal>

to_principal is a method defined on the CandyShared Rust enum that provides a convenient way to convert a value to a Principal. This method returns an Option<Principal> that contains the resulting Principal value if the conversion is successful, and None otherwise.

§Examples
use candy::value::{CandyShared, ToCandyValue};
use candid::Principal;

let principal = Principal::anonymous();
let value = principal.clone().to_candy();
let result = value.to_principal();
assert_eq!(result, Some(principal));
Source

pub fn to_blob(self) -> Vec<u8>

to_blob is a method defined on the CandyShared Rust enum that provides a convenient way to convert a value to a Vec<u8> blob. This method returns a Vec<u8> that contains the binary representation of the value.

§Examples
use candy::value::{CandyShared,ToCandyValue};

let value = "Hello, world!".to_candy();
let result = value.to_blob();
assert_eq!(result, vec![0, 0, 0, 72, 0, 0, 0, 101, 0, 0, 0, 108, 0, 0, 0, 108, 0, 0, 0, 111, 0, 0, 0, 44, 0, 0, 0, 32, 0, 0, 0, 119, 0, 0, 0, 111, 0, 0, 0, 114, 0, 0, 0, 108, 0, 0, 0, 100, 0, 0, 0, 33]);
Source

pub fn to_json(self) -> String

to_json is a method defined on the CandyShared Rust enum that provides a convenient way to convert a value to a JSON string. This method returns a String that represents the resulting JSON.

§Examples
use candy::value::{CandyShared,ToCandyValue};

let value = 42_u128.to_candy();
let result = value.to_json();
assert_eq!(result, "42".to_string());
Source

pub fn to_value_array(self) -> Option<Vec<CandyShared>>

to_value_array is a method defined on the CandyShared Rust enum that provides a convenient way to convert a value to a Vec<CandyShared> array. This method returns an Option<Vec<CandyShared>> that contains the resulting array if the conversion is successful, and None otherwise.

§Examples
use candy::value::{CandyShared,ToCandyValue};

let arr = vec![42_u128.to_candy(), 50_u128.to_candy()];
let value = CandyShared::Array(arr);
let result = value.to_value_array();
assert_eq!(result, Some(vec![42_u128.to_candy(), 50_u128.to_candy()]));
Source

pub fn get_value_size(&self) -> u128

use candy::value::CandyShared;
use candy::workspace::DataZone;
use crate::candy::workspace::DataZoneTrait;
use crate::candy::value::ToCandyValue;
use candid::Principal;


let dz : CandyShared = vec![0_u8;3_000_000].to_candy();
assert_eq!(dz.get_value_size(),3000196);
Source

pub fn stringify_array_of_values(vals: &[CandyShared]) -> String

Trait Implementations§

Source§

impl CandidType for CandyShared

Source§

fn _ty() -> Type

Source§

fn id() -> TypeId

Source§

fn idl_serialize<__S>(&self, __serializer: __S) -> Result<(), __S::Error>
where __S: Serializer,

Source§

fn ty() -> Type

Source§

impl Clone for CandyShared

Source§

fn clone(&self) -> CandyShared

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for CandyShared

Source§

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

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

impl<'de> Deserialize<'de> for CandyShared

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

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

impl Display for CandyShared

Source§

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

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

impl Eq for CandyShared

Source§

impl From<&str> for CandyShared

Source§

fn from(value: &str) -> Self

Converts to this type from the input type.
Source§

impl From<BigInt> for CandyShared

Source§

fn from(value: BigInt) -> Self

Converts to this type from the input type.
Source§

impl From<BigUint> for CandyShared

Source§

fn from(value: BigUint) -> Self

Converts to this type from the input type.
Source§

impl From<HashMap<CandyShared, CandyShared>> for CandyShared

Source§

fn from(value: HashMap<CandyShared, CandyShared>) -> Self

Converts to this type from the input type.
Source§

impl From<HashSet<CandyShared>> for CandyShared

Source§

fn from(value: HashSet<CandyShared>) -> Self

Converts to this type from the input type.
Source§

impl From<Option<Box<CandyShared>>> for CandyShared

Source§

fn from(value: Option<Box<CandyShared>>) -> Self

Converts to this type from the input type.
Source§

impl From<Principal> for CandyShared

Source§

fn from(value: Principal) -> Self

Converts to this type from the input type.
Source§

impl From<String> for CandyShared

Source§

fn from(value: String) -> Self

Converts to this type from the input type.
Source§

impl From<Vec<CandyShared>> for CandyShared

Source§

fn from(value: Vec<CandyShared>) -> Self

Converts to this type from the input type.
Source§

impl From<Vec<Int>> for CandyShared

Source§

fn from(value: Vec<Int>) -> Self

Converts to this type from the input type.
Source§

impl From<Vec<Nat>> for CandyShared

Source§

fn from(value: Vec<Nat>) -> Self

Converts to this type from the input type.
Source§

impl From<Vec<PropertyShared>> for CandyShared

Source§

fn from(value: Vec<PropertyShared>) -> Self

Converts to this type from the input type.
Source§

impl From<Vec<f64>> for CandyShared

Source§

fn from(value: Vec<f64>) -> Self

Converts to this type from the input type.
Source§

impl From<Vec<i128>> for CandyShared

Source§

fn from(value: Vec<i128>) -> Self

Converts to this type from the input type.
Source§

impl From<Vec<u8>> for CandyShared

Source§

fn from(value: Vec<u8>) -> Self

Converts to this type from the input type.
Source§

impl From<Vec<u128>> for CandyShared

Source§

fn from(value: Vec<u128>) -> Self

Converts to this type from the input type.
Source§

impl From<bool> for CandyShared

Source§

fn from(value: bool) -> Self

Converts to this type from the input type.
Source§

impl From<f64> for CandyShared

Source§

fn from(value: f64) -> Self

Converts to this type from the input type.
Source§

impl From<i8> for CandyShared

Source§

fn from(value: i8) -> Self

Converts to this type from the input type.
Source§

impl From<i16> for CandyShared

Source§

fn from(value: i16) -> Self

Converts to this type from the input type.
Source§

impl From<i32> for CandyShared

Source§

fn from(value: i32) -> Self

Converts to this type from the input type.
Source§

impl From<i64> for CandyShared

Source§

fn from(value: i64) -> Self

Converts to this type from the input type.
Source§

impl From<i128> for CandyShared

Source§

fn from(value: i128) -> Self

Converts to this type from the input type.
Source§

impl From<u8> for CandyShared

Source§

fn from(value: u8) -> Self

Converts to this type from the input type.
Source§

impl From<u16> for CandyShared

Source§

fn from(value: u16) -> Self

Converts to this type from the input type.
Source§

impl From<u32> for CandyShared

Source§

fn from(value: u32) -> Self

Converts to this type from the input type.
Source§

impl From<u64> for CandyShared

Source§

fn from(value: u64) -> Self

Converts to this type from the input type.
Source§

impl From<u128> for CandyShared

Source§

fn from(value: u128) -> Self

Converts to this type from the input type.
Source§

impl Hash for CandyShared

Source§

fn hash<H: Hasher>(&self, state: &mut H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl PartialEq for CandyShared

Source§

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

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

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

Inequality operator !=. Read more
Source§

impl Serialize for CandyShared

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

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

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

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

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§

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>,

Source§

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>,

Source§

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.