Skip to content

Commit

Permalink
Tidy up
Browse files Browse the repository at this point in the history
  • Loading branch information
flosse committed Jan 27, 2020
1 parent fbd36a4 commit f9ff1b2
Show file tree
Hide file tree
Showing 12 changed files with 41 additions and 55 deletions.
13 changes: 5 additions & 8 deletions src/client/mod.rs
Expand Up @@ -9,17 +9,16 @@ pub mod tcp;

pub mod util;

use crate::frame::*;
use crate::slave::*;
use crate::{frame::*, slave::*};

use futures::prelude::*;
use std::io::{Error, ErrorKind};

use std::pin::Pin;
use std::{
io::{Error, ErrorKind},
pin::Pin,
};

/// A transport independent asynchronous client trait.
pub trait Client: SlaveContext + Send {
//fn call(&self, request: Request) -> Pin<Box<dyn Future<Output = Response>>>;
fn call<'a>(
&'a mut self,
request: Request,
Expand Down Expand Up @@ -340,9 +339,7 @@ impl Writer for Context {
#[cfg(test)]
mod tests {
use super::*;

use futures::future;

use std::sync::Mutex;

#[derive(Default, Debug)]
Expand Down
3 changes: 1 addition & 2 deletions src/client/tcp.rs
Expand Up @@ -5,8 +5,7 @@ use super::*;
use crate::service;

use futures::Future;
use std::io::Error;
use std::net::SocketAddr;
use std::{io::Error, net::SocketAddr};

/// Establish a direct connection to a Modbus TCP coupler.
pub fn connect(socket_addr: SocketAddr) -> impl Future<Output = Result<Context, Error>> {
Expand Down
1 change: 0 additions & 1 deletion src/client/util.rs
Expand Up @@ -3,7 +3,6 @@
use super::*;

use futures::Future;

use std::{cell::RefCell, io::Error, pin::Pin, rc::Rc};

/// Helper for sharing a context between multiple clients,
Expand Down
3 changes: 1 addition & 2 deletions src/codec/rtu.rs
@@ -1,7 +1,6 @@
use super::*;

use crate::frame::rtu::*;
use crate::slave::SlaveId;
use crate::{frame::rtu::*, slave::SlaveId};

use byteorder::BigEndian;
use bytes::{Buf, BufMut, Bytes, BytesMut};
Expand Down
2 changes: 1 addition & 1 deletion src/codec/tcp.rs
Expand Up @@ -292,7 +292,7 @@ mod tests {
assert_eq!(buf[5], 0x6);
assert_eq!(buf[6], UNIT_ID);

buf.split_to(7);
let _ = buf.split_to(7);
let pdu: Bytes = req.into();
assert_eq!(buf, pdu);
}
Expand Down
3 changes: 1 addition & 2 deletions src/frame/mod.rs
Expand Up @@ -32,7 +32,6 @@ pub(crate) type Quantity = u16;
/// A request represents a message from the client (master) to the server (slave).
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum Request {

/// A request to read multiple coils.
/// The first parameter is the address of the first coil to read.
/// The second parameter is the number of coils to read.
Expand Down Expand Up @@ -72,7 +71,7 @@ pub enum Request {
/// The first parameter is the address of the first register to write.
/// The second parameter is the vector of values to write to the registers.
WriteMultipleRegisters(Address, Vec<Word>),

/// A request to simultaneously read multiple registers and write multiple registers.
/// The first parameter is the address of the first register to read.
/// The second parameter is the number of registers to read.
Expand Down
4 changes: 1 addition & 3 deletions src/prelude.rs
Expand Up @@ -33,9 +33,7 @@ pub use crate::slave::{Slave, SlaveId};
///////////////////////////////////////////////////////////////////
/// Traits
///////////////////////////////////////////////////////////////////
pub use crate::client::Client;
pub use crate::client::Reader;
pub use crate::client::Writer;
pub use crate::client::{Client, Reader, Writer};

#[cfg(feature = "sync")]
pub use crate::client::sync::Client as SyncClient;
Expand Down
6 changes: 1 addition & 5 deletions src/server/service.rs
@@ -1,8 +1,4 @@
use std::io;
use std::rc::Rc;
use std::sync::Arc;

use std::future::Future;
use std::{future::Future, io, rc::Rc, sync::Arc};

pub trait Service {
/// Requests handled by the service.
Expand Down
8 changes: 4 additions & 4 deletions src/server/tcp.rs
@@ -1,9 +1,9 @@
use super::service::NewService;
use crate::frame::*;
use crate::server::tcp_server::TcpServer;

use crate::{frame::*, server::tcp_server::TcpServer};

use futures::{self, Future};
use std::io::Error;
use std::net::SocketAddr;
use std::{io::Error, net::SocketAddr};

#[derive(Debug, Clone, PartialEq, Eq)]
pub struct Server {
Expand Down
8 changes: 2 additions & 6 deletions src/server/tcp_server.rs
Expand Up @@ -2,14 +2,10 @@ use super::service::{NewService, Service};
use crate::codec;

use futures::{future::Future, select};
use futures_util::future::FutureExt;
use futures_util::sink::SinkExt;
use futures_util::stream::StreamExt;
use futures_util::{future::FutureExt, sink::SinkExt, stream::StreamExt};
use log::{error, trace};
use net2;
use std::io;
use std::net::SocketAddr;
use std::sync::Arc;
use std::{io, net::SocketAddr, sync::Arc};
use tokio::net::{TcpListener, TcpStream};
use tokio_util::codec::Framed;

Expand Down
20 changes: 11 additions & 9 deletions src/service/rtu.rs
@@ -1,17 +1,19 @@
use crate::client::Client;
use crate::codec;
use crate::frame::{rtu::*, *};
use crate::slave::*;
use crate::{
client::Client,
codec,
frame::{rtu::*, *},
slave::*,
};

use futures::{future, Future};
use std::io::{Error, ErrorKind};
use std::pin::Pin;
use futures_util::{sink::SinkExt, stream::StreamExt};
use std::{
io::{Error, ErrorKind},
pin::Pin,
};
use tokio::io::{AsyncRead, AsyncWrite};
use tokio_util::codec::Framed;

use futures_util::sink::SinkExt;
use futures_util::stream::StreamExt;

pub(crate) fn connect_slave<T>(
transport: T,
slave: Slave,
Expand Down
25 changes: 13 additions & 12 deletions src/service/tcp.rs
@@ -1,20 +1,21 @@
use crate::client::Client;
use crate::codec;
use crate::frame::{tcp::*, *};
use crate::slave::*;
use crate::{
client::Client,
codec,
frame::{tcp::*, *},
slave::*,
};

use futures::Future;
use std::io::{Error, ErrorKind};
use std::net::SocketAddr;
use std::sync::atomic::{AtomicU16, Ordering};
use futures_util::{sink::SinkExt, stream::StreamExt};
use std::{
io::{Error, ErrorKind},
net::SocketAddr,
pin::Pin,
sync::atomic::{AtomicU16, Ordering},
};
use tokio::net::TcpStream;
use tokio_util::codec::Framed;

use futures_util::sink::SinkExt;
use futures_util::stream::StreamExt;

use std::pin::Pin;

pub(crate) fn connect_slave(
socket_addr: SocketAddr,
slave: Slave,
Expand Down

0 comments on commit f9ff1b2

Please sign in to comment.