diff --git a/Cargo.lock b/Cargo.lock index 5ff3c038..ced37c0f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2600,7 +2600,7 @@ dependencies = [ "actix-web", "confik", "deadpool-postgres", - "derive_more 0.99.19", + "derive_more 2.0.1", "dotenvy", "serde", "tokio-pg-mapper", @@ -2740,7 +2740,16 @@ version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4a9b99b9cbbe49445b21764dc0625032a89b145a2642e67603e1c936f5458d05" dependencies = [ - "derive_more-impl", + "derive_more-impl 1.0.0", +] + +[[package]] +name = "derive_more" +version = "2.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "093242cf7570c207c83073cf82f79706fe7b8317e98620a47d5be7c3d8497678" +dependencies = [ + "derive_more-impl 2.0.1", ] [[package]] @@ -2755,6 +2764,18 @@ dependencies = [ "unicode-xid", ] +[[package]] +name = "derive_more-impl" +version = "2.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bda628edc44c4bb645fbe0f758797143e4e07926f7ebf4e9bdfbd3d2ce621df3" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.98", + "unicode-xid", +] + [[package]] name = "derive_utils" version = "0.15.0" @@ -3026,7 +3047,7 @@ name = "error-handling" version = "1.0.0" dependencies = [ "actix-web", - "derive_more 0.99.19", + "derive_more 2.0.1", "env_logger", "log", "rand 0.9.0", @@ -5261,7 +5282,7 @@ name = "mysql" version = "1.0.0" dependencies = [ "actix-web", - "derive_more 0.99.19", + "derive_more 2.0.1", "dotenvy", "env_logger", "log", @@ -7410,7 +7431,7 @@ dependencies = [ "actix-session", "actix-web", "chrono", - "derive_more 0.99.19", + "derive_more 2.0.1", "diesel", "dotenvy", "env_logger", @@ -8064,7 +8085,7 @@ name = "templating-yarte" version = "1.0.0" dependencies = [ "actix-web", - "derive_more 0.99.19", + "derive_more 2.0.1", "env_logger", "log", "yarte", diff --git a/Cargo.toml b/Cargo.toml index 8a1e25ad..792fd300 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -98,7 +98,7 @@ actix-ws = "0.3" awc = "3.2" chrono = { version = "0.4.30", features = ["serde"] } -derive_more = "0.99.7" +derive_more = "2" dotenvy = "0.15" env_logger = "0.11" eyre = { version = "0.6", default-features = false, features = ["auto-install", "track-caller"] } diff --git a/auth/simple-auth-server/Cargo.toml b/auth/simple-auth-server/Cargo.toml index 22370232..d9db50d8 100644 --- a/auth/simple-auth-server/Cargo.toml +++ b/auth/simple-auth-server/Cargo.toml @@ -9,7 +9,7 @@ actix-session = { workspace = true, features = ["cookie-session"] } actix-web.workspace = true chrono.workspace = true -derive_more.workspace = true +derive_more = { workspace = true, features = ["display"] } diesel = { version = "2", features = ["postgres", "r2d2", "uuid", "chrono"] } dotenvy.workspace = true env_logger.workspace = true diff --git a/auth/simple-auth-server/src/errors.rs b/auth/simple-auth-server/src/errors.rs index 09365c43..0ddd6e20 100644 --- a/auth/simple-auth-server/src/errors.rs +++ b/auth/simple-auth-server/src/errors.rs @@ -5,13 +5,13 @@ use uuid::Error as ParseError; #[derive(Debug, Display)] pub enum ServiceError { - #[display(fmt = "Internal Server Error")] + #[display("Internal Server Error")] InternalServerError, - #[display(fmt = "BadRequest: {_0}")] + #[display("BadRequest: {_0}")] BadRequest(String), - #[display(fmt = "Unauthorized")] + #[display("Unauthorized")] Unauthorized, } diff --git a/basics/error-handling/Cargo.toml b/basics/error-handling/Cargo.toml index ef59575e..fc738793 100644 --- a/basics/error-handling/Cargo.toml +++ b/basics/error-handling/Cargo.toml @@ -6,7 +6,7 @@ edition = "2021" [dependencies] actix-web.workspace = true -derive_more.workspace = true +derive_more = { workspace = true, features = ["display"] } env_logger.workspace = true log.workspace = true rand.workspace = true diff --git a/basics/error-handling/src/main.rs b/basics/error-handling/src/main.rs index fda0b2f3..72d00fc3 100644 --- a/basics/error-handling/src/main.rs +++ b/basics/error-handling/src/main.rs @@ -13,7 +13,7 @@ http errors will be chosen, each with an equal chance of being selected: */ use actix_web::{web, App, Error, HttpResponse, HttpServer, ResponseError}; -use derive_more::Display; // naming it clearly for illustration purposes +use derive_more::Display; use rand::{ distr::{Distribution, StandardUniform}, Rng, @@ -21,13 +21,13 @@ use rand::{ #[derive(Debug, Display)] pub enum CustomError { - #[display(fmt = "Custom Error 1")] + #[display("Custom Error 1")] CustomOne, - #[display(fmt = "Custom Error 2")] + #[display("Custom Error 2")] CustomTwo, - #[display(fmt = "Custom Error 3")] + #[display("Custom Error 3")] CustomThree, - #[display(fmt = "Custom Error 4")] + #[display("Custom Error 4")] CustomFour, } diff --git a/databases/mysql/Cargo.toml b/databases/mysql/Cargo.toml index 02484879..8b2a15b3 100644 --- a/databases/mysql/Cargo.toml +++ b/databases/mysql/Cargo.toml @@ -5,7 +5,7 @@ edition = "2021" [dependencies] actix-web.workspace = true -derive_more.workspace = true +derive_more = { workspace = true, features = ["display", "error", "from"] } dotenvy.workspace = true env_logger.workspace = true log.workspace = true diff --git a/databases/postgres/Cargo.toml b/databases/postgres/Cargo.toml index 6727cd60..71413f77 100644 --- a/databases/postgres/Cargo.toml +++ b/databases/postgres/Cargo.toml @@ -7,7 +7,7 @@ edition = "2021" actix-web.workspace = true confik = "0.11" deadpool-postgres = { version = "0.12", features = ["serde"] } -derive_more.workspace = true +derive_more = { workspace = true, features = ["display", "error", "from"] } dotenvy.workspace = true serde.workspace = true tokio-pg-mapper = "0.2.0" diff --git a/templating/yarte/Cargo.toml b/templating/yarte/Cargo.toml index 5cda319b..863f3c55 100644 --- a/templating/yarte/Cargo.toml +++ b/templating/yarte/Cargo.toml @@ -11,7 +11,7 @@ ignored = [ [dependencies] actix-web.workspace = true -derive_more.workspace = true +derive_more = { workspace = true, features = ["display"] } env_logger.workspace = true log.workspace = true yarte = { version = "0.15", features = ["bytes-buf", "html-min"] } diff --git a/websockets/chat-broker/src/message.rs b/websockets/chat-broker/src/message.rs index 4fb4e91f..e96c1f95 100644 --- a/websockets/chat-broker/src/message.rs +++ b/websockets/chat-broker/src/message.rs @@ -5,12 +5,12 @@ use actix::prelude::*; pub struct ChatMessage(pub String); #[derive(Clone, Message)] -#[rtype(result = "usize")] +#[rtype(result = "u64")] pub struct JoinRoom(pub String, pub Option, pub Recipient); #[derive(Clone, Message)] #[rtype(result = "()")] -pub struct LeaveRoom(pub String, pub usize); +pub struct LeaveRoom(pub String, pub u64); #[derive(Clone, Message)] #[rtype(result = "Vec")] @@ -18,4 +18,4 @@ pub struct ListRooms; #[derive(Clone, Message)] #[rtype(result = "()")] -pub struct SendMessage(pub String, pub usize, pub String); +pub struct SendMessage(pub String, pub u64, pub String); diff --git a/websockets/chat-broker/src/server.rs b/websockets/chat-broker/src/server.rs index 8908e6ea..de242eae 100644 --- a/websockets/chat-broker/src/server.rs +++ b/websockets/chat-broker/src/server.rs @@ -6,7 +6,7 @@ use actix_broker::BrokerSubscribe; use crate::message::{ChatMessage, JoinRoom, LeaveRoom, ListRooms, SendMessage}; type Client = Recipient; -type Room = HashMap; +type Room = HashMap; #[derive(Default)] pub struct WsChatServer { @@ -20,13 +20,13 @@ impl WsChatServer { Some(room) } - fn add_client_to_room(&mut self, room_name: &str, id: Option, client: Client) -> usize { - let mut id = id.unwrap_or_else(rand::random::); + fn add_client_to_room(&mut self, room_name: &str, id: Option, client: Client) -> u64 { + let mut id = id.unwrap_or_else(rand::random); if let Some(room) = self.rooms.get_mut(room_name) { loop { if room.contains_key(&id) { - id = rand::random::(); + id = rand::random(); } else { break; } @@ -45,7 +45,7 @@ impl WsChatServer { id } - fn send_chat_message(&mut self, room_name: &str, msg: &str, _src: usize) -> Option<()> { + fn send_chat_message(&mut self, room_name: &str, msg: &str, _src: u64) -> Option<()> { let mut room = self.take_room(room_name)?; for (id, client) in room.drain() { diff --git a/websockets/chat-broker/src/session.rs b/websockets/chat-broker/src/session.rs index ae41f2c2..1ad87528 100644 --- a/websockets/chat-broker/src/session.rs +++ b/websockets/chat-broker/src/session.rs @@ -9,7 +9,7 @@ use crate::{ #[derive(Default)] pub struct WsChatSession { - id: usize, + id: u64, room: String, name: Option, } diff --git a/websockets/chat-tcp/src/main.rs b/websockets/chat-tcp/src/main.rs index 65f8bc75..d6dd388b 100644 --- a/websockets/chat-tcp/src/main.rs +++ b/websockets/chat-tcp/src/main.rs @@ -40,7 +40,7 @@ async fn chat_route( struct WsChatSession { /// unique session id - id: usize, + id: u64, /// Client must send ping at least once per 10 seconds (CLIENT_TIMEOUT), /// otherwise we drop connection. hb: Instant, diff --git a/websockets/chat-tcp/src/server.rs b/websockets/chat-tcp/src/server.rs index 9b310a4d..e7bad640 100644 --- a/websockets/chat-tcp/src/server.rs +++ b/websockets/chat-tcp/src/server.rs @@ -5,7 +5,7 @@ use std::collections::{HashMap, HashSet}; use actix::prelude::*; -use rand::{rngs::ThreadRng, Rng}; +use rand::Rng as _; use crate::session; @@ -13,7 +13,7 @@ use crate::session; /// /// New chat session is created #[derive(Message)] -#[rtype(usize)] +#[rtype(u64)] pub struct Connect { pub addr: Recipient, } @@ -22,7 +22,7 @@ pub struct Connect { #[derive(Message)] #[rtype(result = "()")] pub struct Disconnect { - pub id: usize, + pub id: u64, } /// Send message to specific room @@ -30,7 +30,7 @@ pub struct Disconnect { #[rtype(result = "()")] pub struct Message { /// Id of the client session - pub id: usize, + pub id: u64, /// Peer message pub msg: String, /// Room name @@ -49,7 +49,7 @@ impl actix::Message for ListRooms { #[rtype(result = "()")] pub struct Join { /// Client id - pub id: usize, + pub id: u64, /// Room name pub name: String, } @@ -57,8 +57,8 @@ pub struct Join { /// `ChatServer` manages chat rooms and responsible for coordinating chat /// session. implementation is super primitive pub struct ChatServer { - sessions: HashMap>, - rooms: HashMap>, + sessions: HashMap>, + rooms: HashMap>, } impl Default for ChatServer { @@ -76,7 +76,7 @@ impl Default for ChatServer { impl ChatServer { /// Send message to all users in the room - fn send_message(&self, room: &str, message: &str, skip_id: usize) { + fn send_message(&self, room: &str, message: &str, skip_id: u64) { if let Some(sessions) = self.rooms.get(room) { for id in sessions { if *id != skip_id { @@ -100,7 +100,7 @@ impl Actor for ChatServer { /// /// Register new session and assign unique id to this session impl Handler for ChatServer { - type Result = usize; + type Result = u64; fn handle(&mut self, msg: Connect, _: &mut Context) -> Self::Result { println!("Someone joined"); @@ -109,7 +109,7 @@ impl Handler for ChatServer { self.send_message("main", "Someone joined", 0); // register session with random id - let id = rand::rng().random::(); + let id = rand::rng().random::(); self.sessions.insert(id, msg.addr); // auto join session to main room diff --git a/websockets/chat-tcp/src/session.rs b/websockets/chat-tcp/src/session.rs index d7d5c782..a30accff 100644 --- a/websockets/chat-tcp/src/session.rs +++ b/websockets/chat-tcp/src/session.rs @@ -27,7 +27,7 @@ pub struct Message(pub String); /// `ChatSession` actor is responsible for tcp peer communications. pub struct ChatSession { /// unique session id - id: usize, + id: u64, /// this is address of chat server addr: Addr, /// Client must send ping at least once per 10 seconds, otherwise we drop