diff --git a/Cargo.lock b/Cargo.lock index 540a3cd..d81e93c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -249,6 +249,7 @@ dependencies = [ "async-trait", "clap", "cookie", + "cove-config", "crossterm", "directories", "edit", @@ -259,19 +260,25 @@ dependencies = [ "open", "parking_lot", "rusqlite", - "serde", "serde_json", "thiserror", "time", "tokio", "tokio-tungstenite", - "toml", "toss", "unicode-segmentation", "unicode-width", "vault", ] +[[package]] +name = "cove-config" +version = "0.6.1" +dependencies = [ + "serde", + "toml", +] + [[package]] name = "cpufeatures" version = "0.2.6" diff --git a/Cargo.toml b/Cargo.toml index e47762f..2873003 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [workspace] resolver = "2" -members = ["cove"] +members = ["cove", "cove-*"] [workspace.package] version = "0.6.1" diff --git a/cove-config/Cargo.toml b/cove-config/Cargo.toml new file mode 100644 index 0000000..2e21781 --- /dev/null +++ b/cove-config/Cargo.toml @@ -0,0 +1,8 @@ +[package] +name = "cove-config" +version = { workspace = true } +edition = { workspace = true } + +[dependencies] +serde = { version = "1.0.159", features = ["derive"] } +toml = "0.7.3" diff --git a/cove/src/config.rs b/cove-config/src/lib.rs similarity index 81% rename from cove/src/config.rs rename to cove-config/src/lib.rs index 2a8d13f..2beb8db 100644 --- a/cove/src/config.rs +++ b/cove-config/src/lib.rs @@ -1,11 +1,20 @@ +#![forbid(unsafe_code)] +// Rustc lint groups +#![warn(future_incompatible)] +#![warn(rust_2018_idioms)] +#![warn(unused)] +// Rustc lints +#![warn(noop_method_call)] +#![warn(single_use_lifetimes)] +// Clippy lints +#![warn(clippy::use_self)] + use std::collections::HashMap; use std::fs; use std::path::{Path, PathBuf}; use serde::Deserialize; -use crate::macros::ok_or_return; - #[derive(Debug, Clone, Copy, Default, Deserialize)] #[serde(rename_all = "snake_case")] pub enum RoomsSortOrder { @@ -45,7 +54,7 @@ pub struct Config { impl Config { pub fn load(path: &Path) -> Self { - let content = ok_or_return!(fs::read_to_string(path), Self::default()); + let Ok(content) = fs::read_to_string(path) else { return Self::default(); }; match toml::from_str(&content) { Ok(config) => config, Err(err) => { diff --git a/cove/Cargo.toml b/cove/Cargo.toml index 5821137..123b7c9 100644 --- a/cove/Cargo.toml +++ b/cove/Cargo.toml @@ -4,6 +4,8 @@ version = { workspace = true } edition = { workspace = true } [dependencies] +cove-config = { path = "../cove-config" } + anyhow = "1.0.70" async-trait = "0.1.68" clap = { version = "4.2.1", features = ["derive", "deprecated"] } @@ -17,11 +19,9 @@ once_cell = "1.17.1" open = "4.0.1" parking_lot = "0.12.1" rusqlite = { version = "0.29.0", features = ["bundled", "time"] } -serde = { version = "1.0.159", features = ["derive"] } serde_json = "1.0.95" thiserror = "1.0.40" tokio = { version = "1.27.0", features = ["full"] } -toml = "0.7.3" unicode-segmentation = "1.10.1" unicode-width = "0.1.10" diff --git a/cove/src/main.rs b/cove/src/main.rs index d5a402b..494d710 100644 --- a/cove/src/main.rs +++ b/cove/src/main.rs @@ -14,7 +14,6 @@ // TODO Time zones other than UTC // TODO Fix password room auth -mod config; mod euph; mod export; mod logger; @@ -28,12 +27,12 @@ use std::path::PathBuf; use clap::Parser; use cookie::CookieJar; +use cove_config::Config; use directories::{BaseDirs, ProjectDirs}; use log::info; use tokio::sync::mpsc; use toss::Terminal; -use crate::config::Config; use crate::logger::Logger; use crate::ui::Ui; use crate::vault::Vault; diff --git a/cove/src/ui.rs b/cove/src/ui.rs index 42235bf..1e9d55c 100644 --- a/cove/src/ui.rs +++ b/cove/src/ui.rs @@ -10,6 +10,7 @@ use std::io; use std::sync::{Arc, Weak}; use std::time::{Duration, Instant}; +use cove_config::Config; use parking_lot::FairMutex; use tokio::sync::mpsc::error::TryRecvError; use tokio::sync::mpsc::{self, UnboundedReceiver, UnboundedSender}; @@ -17,7 +18,6 @@ use tokio::task; use toss::widgets::BoxedAsync; use toss::{Terminal, WidgetExt}; -use crate::config::Config; use crate::logger::{LogMsg, Logger}; use crate::macros::{logging_unwrap, ok_or_return, some_or_return}; use crate::util::InfallibleExt; diff --git a/cove/src/ui/euph/room.rs b/cove/src/ui/euph/room.rs index a03e6e1..8dc6ed0 100644 --- a/cove/src/ui/euph/room.rs +++ b/cove/src/ui/euph/room.rs @@ -11,7 +11,6 @@ use tokio::sync::{mpsc, oneshot}; use toss::widgets::{BoxedAsync, EditorState, Join2, Layer, Text}; use toss::{Style, Styled, Terminal, Widget, WidgetExt}; -use crate::config; use crate::euph; use crate::macros::logging_unwrap; use crate::ui::chat::{ChatState, Reaction}; @@ -46,7 +45,7 @@ type EuphChatState = ChatState; pub struct EuphRoom { server_config: ServerConfig, - config: config::EuphRoom, + config: cove_config::EuphRoom, ui_event_tx: mpsc::UnboundedSender, room: Option, @@ -64,7 +63,7 @@ pub struct EuphRoom { impl EuphRoom { pub fn new( server_config: ServerConfig, - config: config::EuphRoom, + config: cove_config::EuphRoom, vault: EuphRoomVault, ui_event_tx: mpsc::UnboundedSender, ) -> Self { diff --git a/cove/src/ui/rooms.rs b/cove/src/ui/rooms.rs index 8a347e2..b401372 100644 --- a/cove/src/ui/rooms.rs +++ b/cove/src/ui/rooms.rs @@ -2,6 +2,7 @@ use std::collections::{HashMap, HashSet}; use std::iter; use std::sync::{Arc, Mutex}; +use cove_config::{Config, RoomsSortOrder}; use crossterm::style::Stylize; use euphoxide::api::SessionType; use euphoxide::bot::instance::{Event, ServerConfig}; @@ -11,7 +12,6 @@ use tokio::sync::mpsc; use toss::widgets::{BoxedAsync, EditorState, Empty, Join2, Text}; use toss::{Style, Styled, Terminal, Widget, WidgetExt}; -use crate::config::{Config, RoomsSortOrder}; use crate::euph; use crate::macros::logging_unwrap; use crate::vault::Vault;