split out more files
This commit is contained in:
parent
db8370e642
commit
6b5fdca654
7 changed files with 112 additions and 105 deletions
|
@ -1,10 +1,14 @@
|
|||
use std::net::{ToSocketAddrs, UdpSocket};
|
||||
use crate::{Command, Packet};
|
||||
use crate::{Packet};
|
||||
|
||||
pub struct Connection {
|
||||
socket: UdpSocket,
|
||||
}
|
||||
|
||||
pub trait ToPacket {
|
||||
fn to_packet(self) -> Packet;
|
||||
}
|
||||
|
||||
impl Connection {
|
||||
/// Open a new UDP socket and create a display instance
|
||||
pub fn open(addr: impl ToSocketAddrs) -> std::io::Result<Self> {
|
||||
|
@ -14,9 +18,9 @@ impl Connection {
|
|||
}
|
||||
|
||||
/// Send a command to the display
|
||||
pub fn send(&self, command: Command) -> std::io::Result<()> {
|
||||
let packet: Packet = command.into();
|
||||
self.socket.send(&packet)?;
|
||||
pub fn send(&self, packet: impl ToPacket) -> std::io::Result<()> {
|
||||
let packet = packet.to_packet();
|
||||
self.socket.send(&*packet.to_bytes())?;
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue