]>
code.octet-stream.net Git - m17rt/blob - m17app/src/tnc.rs
99bacc721aa9a5e99dd96fa31989472f32c0b6c8
1 use std
::io
::{Read
, Write
};
3 /// A TNC that supports reading and writing M17 KISS messages.
5 /// TNCs must be cloneable to support reading and writing from different threads,
6 /// via a working implementation of try_clone(). We do not require `Clone` directly
7 /// as this could not be fulfilled by `TcpStream`.
8 pub trait Tnc
: Read
+ Write
+ Sized
+ Send
+ '
static {
9 fn try_clone(&mut self) -> Result
<Self, TncError
>;
10 fn start(&mut self) -> Result
<(), TncError
>;
11 fn close(&mut self) -> Result
<(), TncError
>;
14 #[derive(Debug, PartialEq, Eq, Clone)]
16 // TODO: Good error cases
20 impl Tnc
for std
::net
::TcpStream
{
21 fn try_clone(&mut self) -> Result
<Self, TncError
> {
22 self.try_clone().map_err(|_
| TncError
::Unknown
)
25 fn start(&mut self) -> Result
<(), TncError
> {
26 // already started, hopefully we get onto reading the socket quickly
30 fn close(&mut self) -> Result
<(), TncError
> {
31 self.shutdown(std
::net
::Shutdown
::Both
)
32 .map_err(|_
| TncError
::Unknown
)