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§
Sourcepub fn to_nat(self) -> Option<u128>
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));Sourcepub fn to_nat8(self) -> Option<u8>
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));Sourcepub fn to_nat16(self) -> Option<u16>
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));Sourcepub fn to_nat32(self) -> Option<u32>
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));Sourcepub fn to_nat64(self) -> Option<u64>
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));Sourcepub fn to_int(self) -> Option<i128>
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));Sourcepub fn to_int8(self) -> Option<i8>
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));Sourcepub fn to_int16(self) -> Option<i16>
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));Sourcepub fn to_int32(self) -> Option<i32>
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));Sourcepub fn to_int64(self) -> Option<i64>
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));Sourcepub fn to_float(self) -> Option<f64>
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));Sourcepub fn to_bool(self) -> Option<bool>
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));Sourcepub fn to_principal(self) -> Option<Principal>
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));Sourcepub fn to_blob(self) -> Vec<u8> ⓘ
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]);Sourcepub fn to_json(self) -> String
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());Sourcepub fn to_value_array(self) -> Option<Vec<CandyShared>>
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()]));Sourcepub fn get_value_size(&self) -> u128
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);pub fn stringify_array_of_values(vals: &[CandyShared]) -> String
Trait Implementations§
Source§fn clone(&self) -> CandyShared
fn clone(&self) -> CandyShared
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more