Skip to content

Commit

Permalink
Add more docs
Browse files Browse the repository at this point in the history
  • Loading branch information
levkk committed Dec 3, 2024
1 parent fbc8fdd commit 6400f57
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 0 deletions.
6 changes: 6 additions & 0 deletions rwf/src/colors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,17 @@
use crate::config::get_config;
use colored::Colorize;

/// Use terminal colors only if terminal is TTY.
pub trait MaybeColorize {
/// Make text green.
fn green(&self) -> String;
/// Make text red.
fn red(&self) -> String;
/// Make text purple.
fn purple(&self) -> String;
/// Make text yellow.
fn yellow(&self) -> String;
/// Make text bold.
fn bold(&self) -> String;
}

Expand Down
9 changes: 9 additions & 0 deletions rwf/src/comms.rs
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,10 @@ impl std::ops::Deref for WebsocketSender {
}
}

/// Receiver for WebSocket messages.
///
/// Once this receiver is created, all subsequent messages will be sent to this
/// receiver as well as all others.
#[derive(Debug)]
pub struct WebsocketReceiver {
receiver: Option<Receiver<Message>>,
Expand All @@ -172,6 +176,7 @@ pub struct WebsocketReceiver {
}

impl WebsocketReceiver {
/// Get the session ID for this WebSocket receiver.
pub fn session_id(&self) -> &SessionId {
&self.session_id
}
Expand Down Expand Up @@ -200,11 +205,14 @@ impl Drop for WebsocketReceiver {
}
}

/// Send messages to every single connected
/// WebSocket session.
pub struct Broadcast {
everyone: Vec<Websocket>,
}

impl Broadcast {
/// Send a message to all connected sessions.
pub fn send(&self, message: impl ToMessage) -> Result<(), Error> {
for socket in &self.everyone {
socket.sender.send(message.clone().to_message())?;
Expand All @@ -218,6 +226,7 @@ impl Broadcast {
///
/// If a model is passed in, the `id` field is used.
pub trait IntoSessionId {
/// Convert a struct to a session identifier.
fn into_session_id(self) -> SessionId;
}

Expand Down
10 changes: 10 additions & 0 deletions rwf/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,21 +22,28 @@ static CONFIG: OnceCell<Config> = OnceCell::new();
/// Configuration error.
#[derive(Error, Debug)]
pub enum Error {
/// Config file is not valid TOML.
#[error("config: {0}")]
Toml(#[from] toml::de::Error),

/// Configuration file doesn't exist or something went wrong
/// while reading it.
#[error("config file not found")]
Io(#[from] std::io::Error),

/// Secret key is not encoded using correct Base64 encoding.
#[error("secret key is not valid")]
Base64(#[from] base64::DecodeError),

/// Secret key is not correctly created.
#[error("secret key is incorrect length")]
SecretKey,

/// Configuration is already loaded.
#[error("config is already loaded")]
ConfigLoaded,

/// Configuration was not loaded.
#[error("config not found")]
NoConfig,
}
Expand Down Expand Up @@ -168,6 +175,7 @@ pub struct General {
/// AES-128 encryption key. Derived from the secret key. Used for encrypting cookies, sessions, and arbitrary user data.
#[serde(skip)]
pub aes_key: Key<AesGcmSiv<Aes128>>,
/// AES key used for encrypting secure identifiers.
#[serde(skip)]
pub secure_id_key: Key<AesGcmSiv<Aes128>>,
/// Enable logging all queries executed by the ORM.
Expand Down Expand Up @@ -527,6 +535,8 @@ name = "test"
}
}

/// Configuration for packaging Rwf apps built
/// with `rwf-cli`.
#[derive(Serialize, Deserialize, Debug, Clone)]
pub struct PackageConfig {
/// Paths to include into the build. Default: migrations, static, templates.
Expand Down
1 change: 1 addition & 0 deletions rwf/src/controller/auth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ impl Authentication for BasicAuth {
/// Not very secure since the token can leak, but helpful if you need
/// to quickly protect an endpoint.
pub struct Token {
/// A token string.
pub token: String,
}

Expand Down
1 change: 1 addition & 0 deletions rwf/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@
//! }
//! ```
//!
#![warn(missing_docs)]
pub mod analytics;
pub mod colors;
pub mod comms;
Expand Down

0 comments on commit 6400f57

Please sign in to comment.