From f2ccdee9d5a258e7efe19ff61ccc182fc6dd2033 Mon Sep 17 00:00:00 2001 From: homycdev Date: Mon, 22 Apr 2024 07:44:16 +0300 Subject: [PATCH] - change trait's signature --- crates/projection-irc/src/commands/mod.rs | 11 +++++++-- .../src/commands/whois/error.rs | 24 +++++++++++-------- .../projection-irc/src/commands/whois/mod.rs | 8 +++---- .../src/commands/whois/response.rs | 24 +++++++++---------- 4 files changed, 39 insertions(+), 28 deletions(-) diff --git a/crates/projection-irc/src/commands/mod.rs b/crates/projection-irc/src/commands/mod.rs index b4d948b..3c68f84 100644 --- a/crates/projection-irc/src/commands/mod.rs +++ b/crates/projection-irc/src/commands/mod.rs @@ -1,12 +1,19 @@ use lavina_core::prelude::Str; use lavina_core::repo::Storage; +use proto_irc::response::SendResponseBody; use std::future::Future; use tokio::io::AsyncWrite; -use proto_irc::response::SendResponseBody; pub mod whois; -pub trait Handler { +struct HandlerY { + server_name: Str, + client: Str, + writer: T, + storage: Storage, +} + +pub trait Handler { fn handle( &self, server_name: &Str, diff --git a/crates/projection-irc/src/commands/whois/error.rs b/crates/projection-irc/src/commands/whois/error.rs index d7fd63b..ab2af75 100644 --- a/crates/projection-irc/src/commands/whois/error.rs +++ b/crates/projection-irc/src/commands/whois/error.rs @@ -3,33 +3,37 @@ use tokio::io::{AsyncWrite, AsyncWriteExt}; use lavina_core::prelude::Str; use proto_irc::response::SendResponseBody; -pub struct ERR_NOSUCHNICK_401 { +/// ERR_NOSUCHNICK (401) +pub struct ErrNoSuchNick401 { client: Str, nick: Str, } -impl ERR_NOSUCHNICK_401 { +impl ErrNoSuchNick401 { pub fn new(client: Str, nick: Str) -> Self { - ERR_NOSUCHNICK_401 { client, nick } + ErrNoSuchNick401 { client, nick } } } -struct ERR_NOSUCHSERVER_402 { +/// ERR_NOSUCHSERVER (402) +struct ErrNoSuchServer402 { client: Str, /// target parameter in WHOIS /// example: `/whois ` server_name: Str, } -pub struct ERR_NONICKNAMEGIVEN_431 { + +/// ERR_NONICKNAMEGIVEN (431) +pub struct ErrNoNicknameGiven431 { client: Str, } -impl ERR_NONICKNAMEGIVEN_431 { +impl ErrNoNicknameGiven431 { pub fn new(client: Str) -> Self { - ERR_NONICKNAMEGIVEN_431 { client } + ErrNoNicknameGiven431 { client } } } -impl SendResponseBody for ERR_NOSUCHNICK_401 { +impl SendResponseBody for ErrNoSuchNick401 { async fn write_response(self, writer: &mut (impl AsyncWrite + Unpin)) -> std::io::Result<()> { writer.write_all(b"401 ").await?; writer.write_all(self.client.as_bytes()).await?; @@ -41,7 +45,7 @@ impl SendResponseBody for ERR_NOSUCHNICK_401 { } } -impl SendResponseBody for ERR_NONICKNAMEGIVEN_431 { +impl SendResponseBody for ErrNoNicknameGiven431 { async fn write_response(self, writer: &mut (impl AsyncWrite + Unpin)) -> std::io::Result<()> { writer.write_all(b"431").await?; writer.write_all(self.client.as_bytes()).await?; @@ -51,7 +55,7 @@ impl SendResponseBody for ERR_NONICKNAMEGIVEN_431 { } } -impl SendResponseBody for ERR_NOSUCHSERVER_402 { +impl SendResponseBody for ErrNoSuchServer402 { async fn write_response(self, writer: &mut (impl AsyncWrite + Unpin)) -> std::io::Result<()> { writer.write_all(b"402 ").await?; writer.write_all(self.client.as_bytes()).await?; diff --git a/crates/projection-irc/src/commands/whois/mod.rs b/crates/projection-irc/src/commands/whois/mod.rs index f233328..3ef741e 100644 --- a/crates/projection-irc/src/commands/whois/mod.rs +++ b/crates/projection-irc/src/commands/whois/mod.rs @@ -6,14 +6,14 @@ use lavina_core::repo::Storage; use proto_irc::client::command_args::Whois; use proto_irc::response::{IrcResponseMessage, SendResponseBody, SendResponseMessage}; -use crate::commands::whois::error::{ERR_NONICKNAMEGIVEN_431, ERR_NOSUCHNICK_401}; +use crate::commands::whois::error::{ErrNoNicknameGiven431, ErrNoSuchNick401}; use crate::commands::whois::response::{RplWhoIsUser311, RPL_ENDOFWHOIS_318}; use crate::commands::Handler; pub mod error; pub mod response; -impl Handler for Whois { +impl Handler for Whois { async fn handle( &self, server_name: &Str, @@ -29,7 +29,7 @@ impl Handler for Whois { Whois::EmptyArgs => { IrcResponseMessage::empty_tags( Some(server_name.clone()), - ERR_NONICKNAMEGIVEN_431::new(server_name.clone()), + ErrNoNicknameGiven431::new(server_name.clone()), ) .write_response(writer) .await? @@ -68,7 +68,7 @@ async fn handle_nick_target( .write_response(writer) .await? } else { - ERR_NOSUCHNICK_401::new(client.clone(), nick.clone()).write_response(writer).await? + ErrNoSuchNick401::new(client.clone(), nick.clone()).write_response(writer).await? } Ok(()) } diff --git a/crates/projection-irc/src/commands/whois/response.rs b/crates/projection-irc/src/commands/whois/response.rs index 05213f1..c0d3ad2 100644 --- a/crates/projection-irc/src/commands/whois/response.rs +++ b/crates/projection-irc/src/commands/whois/response.rs @@ -3,8 +3,8 @@ use tokio::io::{AsyncWrite, AsyncWriteExt}; use lavina_core::prelude::Str; use proto_irc::response::SendResponseBody; -struct RplWhoiscertfp276; -struct RplWhoIsRegNick307; +struct RplWhoisCertfp276; +struct RplWhoisRegNick307; pub struct RplWhoIsUser311 { client: Str, /// unique name @@ -26,16 +26,16 @@ impl RplWhoIsUser311 { } } -struct _RplWhoisserver312; -struct _RplWhoisoperator313; -struct _RplWhoisidle317; -struct _RplWhoischannels319; -struct _RplWhoisspecial320; -struct _RplWhoisaccount330; -struct _RplWhoisactually338; -struct _RplWhoishost378; -struct _RplWhoismodes379; -struct _RplWhoissecure671; +struct _RplWhoisServer312; +struct _RplWhoisOperator313; +struct _RplWhoisIdle317; +struct _RplWhoisChannels319; +struct _RplWhoisSpecial320; +struct _RplWhoisAccount330; +struct _RplWhoisActually338; +struct _RplWhoisHost378; +struct _RplWhoisModes379; +struct _RplWhoisSecure671; struct _RplAway301; pub struct RPL_ENDOFWHOIS_318 { client: Str,