Add missing documentation to accounts.rs

This commit is contained in:
link2xt
2022-12-12 10:49:44 +00:00
parent cc96c436a9
commit 552a8044b0
2 changed files with 14 additions and 0 deletions

View File

@@ -4,6 +4,7 @@
### Changes ### Changes
- Don't use deprecated `chrono` functions #3798 - Don't use deprecated `chrono` functions #3798
- Document accounts manager #3837
### API-Changes ### API-Changes

View File

@@ -1,5 +1,7 @@
//! # Account manager module. //! # Account manager module.
#![warn(missing_docs)]
use std::collections::BTreeMap; use std::collections::BTreeMap;
use std::path::{Path, PathBuf}; use std::path::{Path, PathBuf};
@@ -265,12 +267,14 @@ impl Accounts {
true true
} }
/// Starts background tasks such as IMAP and SMTP loops for all accounts.
pub async fn start_io(&self) { pub async fn start_io(&self) {
for account in self.accounts.values() { for account in self.accounts.values() {
account.start_io().await; account.start_io().await;
} }
} }
/// Stops background tasks for all accounts.
pub async fn stop_io(&self) { pub async fn stop_io(&self) {
// Sending an event here wakes up event loop even // Sending an event here wakes up event loop even
// if there are no accounts. // if there are no accounts.
@@ -280,12 +284,14 @@ impl Accounts {
} }
} }
/// Notifies all accounts that the network may have become available.
pub async fn maybe_network(&self) { pub async fn maybe_network(&self) {
for account in self.accounts.values() { for account in self.accounts.values() {
account.maybe_network().await; account.maybe_network().await;
} }
} }
/// Notifies all accounts that the network connection may have been lost.
pub async fn maybe_network_lost(&self) { pub async fn maybe_network_lost(&self) {
for account in self.accounts.values() { for account in self.accounts.values() {
account.maybe_network_lost().await; account.maybe_network_lost().await;
@@ -303,7 +309,10 @@ impl Accounts {
} }
} }
/// Configuration file name.
pub const CONFIG_NAME: &str = "accounts.toml"; pub const CONFIG_NAME: &str = "accounts.toml";
/// Database file name.
pub const DB_NAME: &str = "dc.db"; pub const DB_NAME: &str = "dc.db";
/// Account manager configuration file. /// Account manager configuration file.
@@ -325,6 +334,7 @@ struct InnerConfig {
} }
impl Config { impl Config {
/// Creates a new configuration file in the given account manager directory.
pub async fn new(dir: &Path) -> Result<Self> { pub async fn new(dir: &Path) -> Result<Self> {
let inner = InnerConfig { let inner = InnerConfig {
accounts: Vec::new(), accounts: Vec::new(),
@@ -432,14 +442,17 @@ impl Config {
self.sync().await self.sync().await
} }
/// Returns configuration file section for the given account ID.
fn get_account(&self, id: u32) -> Option<AccountConfig> { fn get_account(&self, id: u32) -> Option<AccountConfig> {
self.inner.accounts.iter().find(|e| e.id == id).cloned() self.inner.accounts.iter().find(|e| e.id == id).cloned()
} }
/// Returns the ID of selected account.
pub fn get_selected_account(&self) -> u32 { pub fn get_selected_account(&self) -> u32 {
self.inner.selected_account self.inner.selected_account
} }
/// Changes selected account ID.
pub async fn select_account(&mut self, id: u32) -> Result<()> { pub async fn select_account(&mut self, id: u32) -> Result<()> {
{ {
ensure!( ensure!(