diff -r f43ab2bd76ae -r 65861ba8b4e8 rust/hedgewars-server/src/server/core.rs --- a/rust/hedgewars-server/src/server/core.rs Tue Apr 09 21:08:35 2019 +0300 +++ b/rust/hedgewars-server/src/server/core.rs Tue Apr 09 23:03:12 2019 +0300 @@ -8,8 +8,6 @@ use log::*; use slab; -use std::fs::{File, OpenOptions}; -use std::io::{Read, Write}; use std::{borrow::BorrowMut, iter, num::NonZeroU16}; type Slab = slab::Slab; @@ -48,18 +46,16 @@ pub struct HWServer { pub clients: IndexSlab, pub rooms: Slab, - pub io: Box, pub anteroom: HWAnteroom, } impl HWServer { - pub fn new(clients_limit: usize, rooms_limit: usize, io: Box) -> Self { + pub fn new(clients_limit: usize, rooms_limit: usize) -> Self { let rooms = Slab::with_capacity(rooms_limit); let clients = IndexSlab::with_capacity(clients_limit); Self { clients, rooms, - io, anteroom: HWAnteroom::new(clients_limit), } } @@ -205,48 +201,3 @@ } } } - -pub trait HWServerIO { - fn write_file(&mut self, name: &str, content: &str) -> std::io::Result<()>; - fn read_file(&mut self, name: &str) -> std::io::Result; -} - -pub struct EmptyServerIO {} - -impl EmptyServerIO { - pub fn new() -> Self { - Self {} - } -} - -impl HWServerIO for EmptyServerIO { - fn write_file(&mut self, _name: &str, _content: &str) -> std::io::Result<()> { - Ok(()) - } - - fn read_file(&mut self, _name: &str) -> std::io::Result { - Ok("".to_string()) - } -} - -pub struct FileServerIO {} - -impl FileServerIO { - pub fn new() -> Self { - Self {} - } -} - -impl HWServerIO for FileServerIO { - fn write_file(&mut self, name: &str, content: &str) -> std::io::Result<()> { - let mut writer = OpenOptions::new().create(true).write(true).open(name)?; - writer.write_all(content.as_bytes()) - } - - fn read_file(&mut self, name: &str) -> std::io::Result { - let mut reader = File::open(name)?; - let mut result = String::new(); - reader.read_to_string(&mut result)?; - Ok(result) - } -}