aboutsummaryrefslogtreecommitdiffstats
path: root/crates/turtle/src/atuin_daemon/daemon.rs
diff options
context:
space:
mode:
authorBenedikt Peetz <benedikt.peetz@b-peetz.de>2026-06-11 14:20:49 +0200
committerBenedikt Peetz <benedikt.peetz@b-peetz.de>2026-06-11 14:20:49 +0200
commit199563550dd41c3dfb703bd3747604a8a03cdbc5 (patch)
tree30cfa3e5539f782b7571091c742ee1c219e138fb /crates/turtle/src/atuin_daemon/daemon.rs
parentchore: Restore db migrations (diff)
downloadatuin-199563550dd41c3dfb703bd3747604a8a03cdbc5.zip
chore: Remove all `pub`s
They will not be marked by rustc/cargo as unused, and as atuin doesn't expose an API all of them _should_ be `pub(crate)`
Diffstat (limited to 'crates/turtle/src/atuin_daemon/daemon.rs')
-rw-r--r--crates/turtle/src/atuin_daemon/daemon.rs52
1 files changed, 26 insertions, 26 deletions
diff --git a/crates/turtle/src/atuin_daemon/daemon.rs b/crates/turtle/src/atuin_daemon/daemon.rs
index 77c0d8a5..3268548e 100644
--- a/crates/turtle/src/atuin_daemon/daemon.rs
+++ b/crates/turtle/src/atuin_daemon/daemon.rs
@@ -27,7 +27,7 @@ use crate::atuin_daemon::events::DaemonEvent;
///
/// This contains all the resources that components and services need access to.
/// The state is wrapped in an `Arc` and accessed via [`DaemonHandle`].
-pub struct DaemonState {
+pub(crate) struct DaemonState {
// Event bus
event_tx: broadcast::Sender<DaemonEvent>,
@@ -72,7 +72,7 @@ pub struct DaemonState {
/// let history = handle.history_db().load(id).await?;
/// ```
#[derive(Clone)]
-pub struct DaemonHandle {
+pub(crate) struct DaemonHandle {
state: Arc<DaemonState>,
}
@@ -83,7 +83,7 @@ impl DaemonHandle {
///
/// This is fire-and-forget - if no receivers are listening (which shouldn't
/// happen in normal operation), the event is dropped silently.
- pub fn emit(&self, event: DaemonEvent) {
+ pub(crate) fn emit(&self, event: DaemonEvent) {
if let Err(e) = self.state.event_tx.send(event) {
tracing::warn!("failed to emit event (no receivers?): {e}");
}
@@ -94,12 +94,12 @@ impl DaemonHandle {
/// Returns a receiver that will receive all events emitted after this call.
/// Useful for components that need to listen for events outside of the
/// normal `handle_event` callback flow.
- pub fn subscribe(&self) -> broadcast::Receiver<DaemonEvent> {
+ pub(crate) fn subscribe(&self) -> broadcast::Receiver<DaemonEvent> {
self.state.event_tx.subscribe()
}
/// Request graceful shutdown of the daemon.
- pub fn shutdown(&self) {
+ pub(crate) fn shutdown(&self) {
self.emit(DaemonEvent::ShutdownRequested);
}
@@ -109,7 +109,7 @@ impl DaemonHandle {
///
/// This acquires a read lock on the settings. For most use cases, clone
/// the settings if you need to hold onto them.
- pub async fn settings(&self) -> tokio::sync::RwLockReadGuard<'_, Settings> {
+ pub(crate) async fn settings(&self) -> tokio::sync::RwLockReadGuard<'_, Settings> {
self.state.settings.read().await
}
@@ -117,7 +117,7 @@ impl DaemonHandle {
///
/// Components listening for `SettingsReloaded` can then re-read settings
/// via `handle.settings()` to pick up the changes.
- pub async fn reload_settings(&self) -> Result<()> {
+ pub(crate) async fn reload_settings(&self) -> Result<()> {
let new_settings = Settings::new()?;
self.apply_settings(new_settings).await;
Ok(())
@@ -127,26 +127,26 @@ impl DaemonHandle {
///
/// Use this when settings have already been loaded (e.g., from a file watcher)
/// to avoid parsing the config file twice.
- pub async fn apply_settings(&self, settings: Settings) {
+ pub(crate) async fn apply_settings(&self, settings: Settings) {
*self.state.settings.write().await = settings;
self.emit(DaemonEvent::SettingsReloaded);
tracing::info!("settings applied");
}
/// Get the encryption key.
- pub fn encryption_key(&self) -> &[u8; 32] {
+ pub(crate) fn encryption_key(&self) -> &[u8; 32] {
&self.state.encryption_key
}
// ---- Database ----
/// Get a reference to the history database.
- pub fn history_db(&self) -> &HistoryDatabase {
+ pub(crate) fn history_db(&self) -> &HistoryDatabase {
&self.state.history_db
}
/// Get a reference to the record store.
- pub fn store(&self) -> &SqliteStore {
+ pub(crate) fn store(&self) -> &SqliteStore {
&self.state.store
}
}
@@ -181,7 +181,7 @@ impl std::fmt::Debug for DaemonHandle {
/// # Example
///
/// ```ignore
-/// pub struct MyComponent {
+/// pub(crate) struct MyComponent {
/// handle: Option<DaemonHandle>,
/// }
///
@@ -213,7 +213,7 @@ impl std::fmt::Debug for DaemonHandle {
/// }
/// ```
#[tonic::async_trait]
-pub trait Component: Send + Sync {
+pub(crate) trait Component: Send + Sync {
/// Human-readable name for logging and debugging.
fn name(&self) -> &'static str;
@@ -257,21 +257,21 @@ pub trait Component: Send + Sync {
///
/// Events emitted during handling are queued and processed in subsequent
/// iterations, ensuring the loop eventually drains.
-pub struct Daemon {
+pub(crate) struct Daemon {
components: Vec<Box<dyn Component>>,
handle: DaemonHandle,
}
impl Daemon {
/// Create a new daemon builder.
- pub fn builder(settings: Settings) -> DaemonBuilder {
+ pub(crate) fn builder(settings: Settings) -> DaemonBuilder {
DaemonBuilder::new(settings)
}
/// Get a clone of the daemon handle.
///
/// The handle can be used to emit events, access settings, etc.
- pub fn handle(&self) -> DaemonHandle {
+ pub(crate) fn handle(&self) -> DaemonHandle {
self.handle.clone()
}
@@ -279,7 +279,7 @@ impl Daemon {
///
/// This must be called before `run_event_loop()`. It initializes all
/// registered components with the daemon handle.
- pub async fn start_components(&mut self) -> Result<()> {
+ pub(crate) async fn start_components(&mut self) -> Result<()> {
for component in &mut self.components {
tracing::info!(component = component.name(), "starting component");
component
@@ -294,7 +294,7 @@ impl Daemon {
///
/// This processes events until a ShutdownRequested event is received.
/// Components must be started first via `start_components()`.
- pub async fn run_event_loop(&mut self) -> Result<()> {
+ pub(crate) async fn run_event_loop(&mut self) -> Result<()> {
let mut event_rx = self.handle.subscribe();
loop {
match event_rx.recv().await {
@@ -324,7 +324,7 @@ impl Daemon {
/// Stop all components.
///
/// This performs graceful shutdown of all components.
- pub async fn stop_components(&mut self) {
+ pub(crate) async fn stop_components(&mut self) {
for component in &mut self.components {
tracing::info!(component = component.name(), "stopping component");
if let Err(e) = component.stop().await {
@@ -342,7 +342,7 @@ impl Daemon {
///
/// This is a convenience method that starts components, runs the event loop,
/// and handles shutdown. It does not return until the daemon is shut down.
- pub async fn run(mut self) -> Result<()> {
+ pub(crate) async fn run(mut self) -> Result<()> {
self.start_components().await?;
self.run_event_loop().await?;
self.stop_components().await;
@@ -383,7 +383,7 @@ impl Daemon {
///
/// daemon.run().await?;
/// ```
-pub struct DaemonBuilder {
+pub(crate) struct DaemonBuilder {
settings: Settings,
store: Option<SqliteStore>,
history_db: Option<HistoryDatabase>,
@@ -392,7 +392,7 @@ pub struct DaemonBuilder {
impl DaemonBuilder {
/// Create a new daemon builder with the given settings.
- pub fn new(settings: Settings) -> Self {
+ pub(crate) fn new(settings: Settings) -> Self {
Self {
settings,
store: None,
@@ -402,13 +402,13 @@ impl DaemonBuilder {
}
/// Set the record store.
- pub fn store(mut self, store: SqliteStore) -> Self {
+ pub(crate) fn store(mut self, store: SqliteStore) -> Self {
self.store = Some(store);
self
}
/// Set the history database.
- pub fn history_db(mut self, db: HistoryDatabase) -> Self {
+ pub(crate) fn history_db(mut self, db: HistoryDatabase) -> Self {
self.history_db = Some(db);
self
}
@@ -416,7 +416,7 @@ impl DaemonBuilder {
/// Register a component.
///
/// Components are started in registration order and stopped in reverse order.
- pub fn component(mut self, component: impl Component + 'static) -> Self {
+ pub(crate) fn component(mut self, component: impl Component + 'static) -> Self {
self.components.push(Box::new(component));
self
}
@@ -424,7 +424,7 @@ impl DaemonBuilder {
/// Build the daemon.
///
/// This loads the encryption key and creates the daemon state.
- pub async fn build(self) -> Result<Daemon> {
+ pub(crate) async fn build(self) -> Result<Daemon> {
let store = self.store.ok_or_else(|| eyre::eyre!("store is required"))?;
let history_db = self
.history_db