pub struct UserData {
pub name: String,
pub email: String,
pub balance: u128,
pub addresses: Vec<UserAddressData>,
pub settings: HashMap<String, UserDataSettingValue>,
/* private fields */
}Fields§
§name: String§email: String§balance: u128§addresses: Vec<UserAddressData>§settings: HashMap<String, UserDataSettingValue>Implementations§
source§impl UserData
impl UserData
pub fn new(user_args: UserDataArgs, address_args: UserAddressArgs) -> Self
sourcepub fn update(&mut self, args: UserDataArgs) -> UserDataArgs
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.
sourcepub fn create_address(
&mut self,
args: UserAddressArgs
) -> Result<UserAddressData, UserStateError>
pub fn create_address( &mut self, args: UserAddressArgs ) -> Result<UserAddressData, UserStateError>
Adds a new address for the user with the given key and address data. Returns an error if the key already exists.
sourcepub fn get_new_key(&self) -> Result<usize, UserStateError>
pub fn get_new_key(&self) -> Result<usize, UserStateError>
New derivation path based on the number of addresses created. Returns the derivation path as a vector of bytes.
sourcepub fn get_key_is_valid(&self, key: usize) -> Result<(), UserStateError>
pub fn get_key_is_valid(&self, key: usize) -> Result<(), UserStateError>
Retrieves the derivation path for the given key. Returns the derivation path as a vector of bytes.
sourcepub fn get_address(&self, key: usize) -> Result<UserAddressData, UserStateError>
pub fn get_address(&self, key: usize) -> Result<UserAddressData, UserStateError>
Retrieves an address by key for the user. Returns the address data if the key is found, or error if the key was not found.
sourcepub fn get_address_mut(
&mut self,
key: usize
) -> Result<&mut UserAddressData, UserStateError>
pub fn get_address_mut( &mut self, key: usize ) -> Result<&mut UserAddressData, UserStateError>
Retrieves a mutable reference to the address by key for the user. Returns the address data if the key is found, or error if the key was not found.
sourcepub fn get_addresses(&self) -> &Vec<UserAddressData>
pub fn get_addresses(&self) -> &Vec<UserAddressData>
Retrieves all the addresses created by the user. Returns a Vec of UserAddressData objects.
sourcepub fn set_password(&mut self, password: &str) -> Result<(), UserStateError>
pub fn set_password(&mut self, password: &str) -> Result<(), UserStateError>
Sets the password for the user.
sourcepub fn check_password(&self, password: &str) -> Result<bool, UserStateError>
pub fn check_password(&self, password: &str) -> Result<bool, UserStateError>
Checks if the provided password matches the user’s password.
sourcepub fn get_setting(
&self,
key: &str
) -> Result<UserDataSettingValue, UserStateError>
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.
sourcepub fn get_setting_mut(
&mut self,
key: &str
) -> Result<&mut UserDataSettingValue, UserStateError>
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.
sourcepub fn get_settings(&self) -> &HashMap<String, UserDataSettingValue>
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.
sourcepub fn set_setting(&mut self, key: String, value: UserDataSettingValue)
pub fn set_setting(&mut self, key: String, value: UserDataSettingValue)
Sets a setting key-value pair for the user.
sourcepub fn remove_setting(&mut self, key: &str) -> Result<bool, UserStateError>
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.
sourcepub fn update_settings(
&mut self,
new_settings: HashMap<String, UserDataSettingValue>
)
pub fn update_settings( &mut self, new_settings: HashMap<String, UserDataSettingValue> )
Updates all the settings for the user with the new settings.