Added a missing blank line at the EOF of main.rs
This commit is contained in:
@@ -1,49 +0,0 @@
|
|||||||
use std::fs::{create_dir, File, remove_file};
|
|
||||||
use std::io::{Read, Write, Result};
|
|
||||||
|
|
||||||
pub struct Bucket {
|
|
||||||
pub name: String,
|
|
||||||
pub path: String,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Bucket {
|
|
||||||
pub fn new(name: &str) -> Bucket {
|
|
||||||
Bucket {
|
|
||||||
name: String::from(name),
|
|
||||||
path: format!("./{name}")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn create(&self) -> Result<()> {
|
|
||||||
return create_dir(&self.path);
|
|
||||||
}
|
|
||||||
|
|
||||||
fn get_file_path(&self, name: &str) -> &str {
|
|
||||||
return &format!("{}/{}", &self.path, name);
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn eq(&self, other: &Bucket) -> bool {
|
|
||||||
return &self.name == other.name;
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn create_object(&self, name: &str, data: &[u8]) -> Result<()> {
|
|
||||||
let file_path: &str = &self.get_file_path(name);
|
|
||||||
let mut file: File = File::create(file_path)?;
|
|
||||||
file.write_all(&data)?;
|
|
||||||
|
|
||||||
return Ok(());
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn read_object(&self, name: &str) -> &[u8] {
|
|
||||||
let file_path: &str = &self.get_file_path(name);
|
|
||||||
let mut data: Vec<u8> = Vec::new();
|
|
||||||
let mut file: File = File::open(file_path)?;
|
|
||||||
file.read_to_end(&mut data)?;
|
|
||||||
return data.as_slice();
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn remove_object(&self, name: &str) -> Result<()> {
|
|
||||||
let file_path: &str = &self.get_file_path(name);
|
|
||||||
return remove_file(file_path);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
use std::net::UdpSocket;
|
|
||||||
use std::io::stdin;
|
use std::io::stdin;
|
||||||
|
use std::net::UdpSocket;
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let server_address: String = get_server_address();
|
let server_address: String = get_server_address();
|
||||||
@@ -21,6 +21,7 @@ fn listen(server_address: &str) {
|
|||||||
let socket: UdpSocket = UdpSocket::bind(server_address).expect("Error while binding the socket.");
|
let socket: UdpSocket = UdpSocket::bind(server_address).expect("Error while binding the socket.");
|
||||||
let (num_bytes, src_addr) = socket.recv_from(&mut buf).expect("Error while receiving message");
|
let (num_bytes, src_addr) = socket.recv_from(&mut buf).expect("Error while receiving message");
|
||||||
message.push_str(std::str::from_utf8(&buf[..num_bytes]).expect("Invalid UTF-8 data"));
|
message.push_str(std::str::from_utf8(&buf[..num_bytes]).expect("Invalid UTF-8 data"));
|
||||||
|
|
||||||
println!("{}:{}", src_addr.to_string(), message);
|
println!("{}:{}", src_addr.to_string(), message);
|
||||||
|
|
||||||
if message.trim() == "!STOP" {
|
if message.trim() == "!STOP" {
|
||||||
|
|||||||
Reference in New Issue
Block a user