Browse Source

Fix clippy warnings and no_std build

interface-2
Lev 3 years ago
parent
commit
3b17d437d3
  1. 4
      src/interface.rs
  2. 14
      src/interfaces/ip.rs

4
src/interface.rs

@ -14,7 +14,7 @@ pub(crate) type TargetingData = String;
pub trait InterfaceRequirements {}
#[cfg(feature = "std")]
pub trait InterfaceRequirements = Send + Sync;
pub trait InterfaceRequirements: Send + Sync {}
/// An interface that can be used to
@ -53,6 +53,8 @@ pub mod test_interface {
messages: Vec<(Vec<u8>, TargetingData)>,
}
impl InterfaceRequirements for TestInterface {}
impl Interface for TestInterface {
fn main_loop_iteration(&mut self) -> IFResult<()> {
Ok(())

14
src/interfaces/ip.rs

@ -1,9 +1,7 @@
use std::net;
use alloc::vec;
use alloc::vec::Vec;
use alloc::string::String;
use crate::interface;
use crate::interface::{Interface, InterfaceRequirements, TargetingData};
use crate::message::MessageBytes;
use crate::res::{IFError, IFResult};
@ -18,6 +16,8 @@ pub struct IPInterface {
pub listener: net::TcpListener,
}
impl InterfaceRequirements for IPInterface {}
impl Interface for IPInterface {
fn main_loop_iteration(&mut self) -> IFResult<()> {
println!("Mainloop {:?}", self.listener.local_addr());
@ -43,10 +43,10 @@ impl Interface for IPInterface {
for mut connection in &self.connections {
let mut size_arr: [u8; 4] = [0, 0, 0, 0];
connection.read(&mut size_arr);
connection.read_exact(&mut size_arr)?;
let mut size: u32 = 0;
for i in 0..4 {
size = size * 256 + size_arr[i] as u32;
for size_byte in &size_arr {
size = size * 256 + *size_byte as u32;
}
println!("Size: {:?}", size);
@ -63,7 +63,7 @@ impl Interface for IPInterface {
&*self.id
}
fn send(&mut self, message: &[u8], interface_data: Option<TargetingData>) -> IFResult<()> {
let mut addr: net::SocketAddr = match interface_data {
let addr: net::SocketAddr = match interface_data {
Some(ip_string) => ip_string.parse().expect("Unable to parse address"),
None => return Err(IFError::General(String::from("Not enough info to create connection")))
};
@ -79,7 +79,7 @@ impl Interface for IPInterface {
println!("Sending message to {:?}", self.connections[index].peer_addr().unwrap());
self.connections[index].write(message);
self.connections[index].write_all(message)?;
println!("Sent message");

Loading…
Cancel
Save