Add missing ephemeral.rs documentation

This commit is contained in:
link2xt
2023-01-24 10:59:29 +00:00
parent 8916841e83
commit 9f8b74adf9

View File

@@ -62,8 +62,6 @@
//! the database entries which are expired either according to their //! the database entries which are expired either according to their
//! ephemeral message timers or global `delete_server_after` setting. //! ephemeral message timers or global `delete_server_after` setting.
#![allow(missing_docs)]
use std::cmp::max; use std::cmp::max;
use std::convert::{TryFrom, TryInto}; use std::convert::{TryFrom, TryInto};
use std::num::ParseIntError; use std::num::ParseIntError;
@@ -88,13 +86,25 @@ use crate::sql::{self, params_iter};
use crate::stock_str; use crate::stock_str;
use crate::tools::{duration_to_str, time}; use crate::tools::{duration_to_str, time};
/// Ephemeral timer value.
#[derive(Debug, PartialEq, Eq, Copy, Clone, Serialize, Deserialize)] #[derive(Debug, PartialEq, Eq, Copy, Clone, Serialize, Deserialize)]
pub enum Timer { pub enum Timer {
/// Timer is disabled.
Disabled, Disabled,
Enabled { duration: u32 },
/// Timer is enabled.
Enabled {
/// Timer duration in seconds.
///
/// The value cannot be 0.
duration: u32,
},
} }
impl Timer { impl Timer {
/// Converts epehmeral timer value to integer.
///
/// If the timer is disabled, return 0.
pub fn to_u32(self) -> u32 { pub fn to_u32(self) -> u32 {
match self { match self {
Self::Disabled => 0, Self::Disabled => 0,
@@ -102,6 +112,9 @@ impl Timer {
} }
} }
/// Converts integer to ephemeral timer value.
///
/// 0 value is treated as disabled timer.
pub fn from_u32(duration: u32) -> Self { pub fn from_u32(duration: u32) -> Self {
if duration == 0 { if duration == 0 {
Self::Disabled Self::Disabled