pub struct UserStore { /* private fields */ }Expand description
Thread-safe, JSON-backed store for user accounts.
All mutations are persisted to disk immediately. Read operations
use an in-memory cache protected by a RwLock so multiple readers
can proceed concurrently.
Implementations§
Source§impl UserStore
impl UserStore
Sourcepub fn new(storage_dir: PathBuf) -> Result<Self, HttpError>
pub fn new(storage_dir: PathBuf) -> Result<Self, HttpError>
Create a new user store backed by {storage_dir}/users.json.
Creates the directory and file if they do not exist.
Sourcepub fn get_by_username(&self, username: &str) -> Option<User>
pub fn get_by_username(&self, username: &str) -> Option<User>
Look up a user by username.
Sourcepub fn create_user(
&self,
username: &str,
password_hash: &str,
email: Option<&str>,
) -> Result<User, HttpError>
pub fn create_user( &self, username: &str, password_hash: &str, email: Option<&str>, ) -> Result<User, HttpError>
Create a new user account.
Returns an error if the username is already taken.
Sourcepub fn update_user(&self, user: User) -> Result<(), HttpError>
pub fn update_user(&self, user: User) -> Result<(), HttpError>
Update an existing user record.
The updated_at timestamp is set to now automatically.
Sourcepub fn delete_user(&self, username: &str) -> Result<bool, HttpError>
pub fn delete_user(&self, username: &str) -> Result<bool, HttpError>
Delete a user by username.
Returns true if the user existed and was removed.
Sourcepub fn list_usernames(&self) -> Vec<String>
pub fn list_usernames(&self) -> Vec<String>
List all usernames in the store.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for UserStore
impl RefUnwindSafe for UserStore
impl Send for UserStore
impl Sync for UserStore
impl Unpin for UserStore
impl UnsafeUnpin for UserStore
impl UnwindSafe for UserStore
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more