UserData

Struct UserData 

Source
pub struct UserData {
    pub name: String,
    pub email: String,
    pub balance: u128,
    pub accounts: Vec<UserAccountData>,
    pub settings: HashMap<String, UserDataSettingValue>,
    /* private fields */
}

Fields§

§name: String§email: String§balance: u128§accounts: Vec<UserAccountData>§settings: HashMap<String, UserDataSettingValue>

Implementations§

Source§

impl UserData

Source

pub fn new(user_args: UserDataArgs, account_args: UserAccountArgs) -> Self

Source

pub fn update(&mut self, args: UserDataArgs) -> UserDataArgs

Updates the user’s data based on the provided UserDataArgs struct. Only updates fields that are set to Some(value) in the options.

Source

pub fn update_profile(&mut self, args: UserProfileArgs) -> UserProfileArgs

Update the user’s profile. Only updates fields that are set to Some(value) in the options. Returns the updated profile.

Source

pub fn create_account( &mut self, args: UserAccountArgs, ) -> Result<UserAccountData, UserStateError>

Adds a new account for the user with the given key and account data. Returns an error if the key already exists.

Source

pub fn get_new_key(&self) -> Result<usize, UserStateError>

New Key to add to derivation path based on the number of accounts created. Returns the new key.

Source

pub fn get_derivation_path( &self, principal: Principal, key: u8, ) -> Result<Vec<u8>, UserStateError>

Get Derivation Path for the given key. Returns the derivation path.

Source

pub fn get_key_is_valid(&self, key: usize) -> Result<(), UserStateError>

Checks if the key is valid for the user. Returns an error if the key is invalid.

Source

pub fn get_account(&self, key: usize) -> Result<UserAccountData, UserStateError>

Retrieves an account by key for the user. Returns the account data if the key is found, or error if the key was not found.

Source

pub fn get_account_mut( &mut self, key: usize, ) -> Result<&mut UserAccountData, UserStateError>

Retrieves a mutable reference to the account by key for the user. Returns the account data if the key is found, or error if the key was not found.

Source

pub fn get_accounts(&self) -> &Vec<UserAccountData>

Retrieves all the accounts created by the user. Returns a Vec of UserAccountData objects.

Source

pub fn set_password(&mut self, password: &str) -> Result<(), UserStateError>

Sets the password for the user.

Source

pub fn check_password(&self, password: &str) -> Result<bool, UserStateError>

Checks if the provided password matches the user’s password.

Source

pub fn get_setting( &self, key: &str, ) -> Result<UserDataSettingValue, UserStateError>

Retrieves the user’s setting. Returns the value if the key is found, or None if the key was not found.

Source

pub fn get_setting_mut( &mut self, key: &str, ) -> Result<&mut UserDataSettingValue, UserStateError>

Retrieves a mutable reference to the user’s setting. Returns the value if the key is found, or None if the key was not found.

Source

pub fn get_settings(&self) -> &HashMap<String, UserDataSettingValue>

Retrieves a setting value by key for the user. Returns the value if the key is found, or None if the key was not found.

Source

pub fn set_setting(&mut self, key: String, value: UserDataSettingValue)

Sets a setting key-value pair for the user.

Source

pub fn remove_setting(&mut self, key: &str) -> Result<bool, UserStateError>

Removes a setting key for the user. Returns the removed value if it existed, or None if the key was not found.

Source

pub fn update_settings( &mut self, new_settings: HashMap<String, UserDataSettingValue>, )

Updates all the settings for the user with the new settings.

Trait Implementations§

Source§

impl CandidType for UserData

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 UserData

Source§

fn clone(&self) -> UserData

Returns a duplicate 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 UserData

Source§

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

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

impl Default for UserData

Source§

fn default() -> UserData

Returns the “default value” for a type. Read more
Source§

impl<'de> Deserialize<'de> for UserData

Source§

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

Deserialize this value from the given Serde deserializer. 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> 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, 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.
Source§

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