~soywod/pimalaya

email-lib: return Self explicitly in tcp structs v1 NEEDS REVISION

Perma Alesheikh: 1
 return Self explicitly in tcp structs

 4 files changed, 10 insertions(+), 10 deletions(-)
Export patchset (mbox)
How do I use this?

Copy & paste the following snippet into your terminal to import this patchset into git:

curl -s https://lists.sr.ht/~soywod/pimalaya/patches/49345/mbox | git am -3
Learn more about email & git

[PATCH email-lib] return Self explicitly in tcp structs Export this patch

Since the returned object can easily be used without the dynamically
returned form it is better to return in a more useful form.
Added to that the new() method call is usually reserved for a function
that directly returns the Self.
Signed-off-by: Perma Alesheikh <me@prma.dev>
---
 time/examples/pomodoro-tcp.rs      | 4 ++--
 time/src/client/tcp.rs             | 6 +++---
 time/src/server/tcp.rs             | 6 +++---
 time/tests/multiple-tcp-clients.rs | 4 ++--
 4 files changed, 10 insertions(+), 10 deletions(-)

diff --git a/time/examples/pomodoro-tcp.rs b/time/examples/pomodoro-tcp.rs
index e7dbea1..dfac804 100644
--- a/time/examples/pomodoro-tcp.rs
+++ b/time/examples/pomodoro-tcp.rs
@@ -1,6 +1,6 @@
use std::time::Duration;
use time::{
    client::tcp::TcpClient,
    client::{tcp::TcpClient, Client},
    server::{tcp::TcpBind, ServerBuilder, ServerEvent},
    timer::TimerEvent,
};
@@ -19,7 +19,7 @@ async fn main() {
            println!("timer event: {event:?}");
            Ok(())
        })
        .with_binder(TcpBind::new(HOST, PORT))
        .with_binder(Box::new(TcpBind::new(HOST, PORT)))
        .with_pomodoro_config()
        .build()
        .unwrap();
diff --git a/time/src/client/tcp.rs b/time/src/client/tcp.rs
index b9a7530..28c9f6f 100644
--- a/time/src/client/tcp.rs
+++ b/time/src/client/tcp.rs
@@ -33,11 +33,11 @@ pub struct TcpClient {

impl TcpClient {
    /// Create a new TCP client using the given host and port.
    pub fn new(host: impl ToString, port: u16) -> Box<dyn Client> {
        Box::new(Self {
    pub fn new(host: impl ToString, port: u16) -> Self {
        Self {
            host: host.to_string(),
            port,
        })
        }
    }
}

diff --git a/time/src/server/tcp.rs b/time/src/server/tcp.rs
index f5639b4..ab9d51b 100644
--- a/time/src/server/tcp.rs
+++ b/time/src/server/tcp.rs
@@ -35,11 +35,11 @@ pub struct TcpBind {

impl TcpBind {
    /// Create a new TCP binder using the given host and port.
    pub fn new(host: impl ToString, port: u16) -> Box<dyn ServerBind> {
        Box::new(Self {
    pub fn new(host: impl ToString, port: u16) -> Self {
        Self {
            host: host.to_string(),
            port,
        })
        }
    }
}

diff --git a/time/tests/multiple-tcp-clients.rs b/time/tests/multiple-tcp-clients.rs
index 8c64dbd..218c5b7 100644
--- a/time/tests/multiple-tcp-clients.rs
+++ b/time/tests/multiple-tcp-clients.rs
@@ -1,6 +1,6 @@
use std::time::Duration;
use time::{
    client::tcp::TcpClient,
    client::{tcp::TcpClient, Client},
    server::{tcp::TcpBind, ServerBuilder, ServerEvent},
    timer::{Timer, TimerCycle, TimerEvent, TimerState},
};
@@ -21,7 +21,7 @@ async fn multiple_tcp_clients() {
            println!("timer event: {event:?}");
            Ok(())
        })
        .with_binder(TcpBind::new(HOST, PORT))
        .with_binder(Box::new(TcpBind::new(HOST, PORT)))
        .with_cycle(("Work", 3))
        .with_cycle(("Break", 5))
        .build()
-- 
2.43.0