From 0ffb62a7dc4fb10a5e3e1edb0f72464d41184b3a Mon Sep 17 00:00:00 2001 From: Rafael Bradley Date: Sun, 10 Aug 2025 22:03:58 -0300 Subject: [PATCH] Add state module docs --- src/cli.rs | 2 +- src/state.rs | 20 ++++++++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/src/cli.rs b/src/cli.rs index 8f605b6..da31351 100644 --- a/src/cli.rs +++ b/src/cli.rs @@ -26,7 +26,7 @@ //! //! # Parsing Arguments //! -//! The arguments are parsed using the [`Args::parse`] method, which returns an instance of the +//! The arguments are parsed using the `Args::parse()` method, which returns an instance of the //! [`Args`] struct. This struct contains the parsed values of the command line arguments, and //! can be used to initialize the bot and start the event loop. //! diff --git a/src/state.rs b/src/state.rs index 99b77ba..4f621ef 100644 --- a/src/state.rs +++ b/src/state.rs @@ -1,3 +1,23 @@ +//! Application state at runtime, including the database connection and other shared resources. +//! +//! Currently, it only contains the database connection, but it can be extended in the future to +//! include other resources that need to be shared across the application, such as caches or +//! configuration settings. +//! +//! It is shared around the application using an `Arc`, allowing it to be cloned and passed around +//! without needing to worry about ownership or lifetimes. This is particularly useful in an +//! asynchronous context. +//! +//! ``` +//! let state = State { +//! db: database::init("127.0.0.1:9042").await?, +//! }; +//! +//! fn handler_which_needs_state(state: Arc) { +//! // Use the state here +//! } +//! ``` + use scylla::client::session::Session; pub struct State {