Added a missing blank line at the EOF of main.rs

This commit is contained in:
Namularbre (Thomas Sazerat)
2023-11-14 22:47:44 +01:00
parent ec7165b37d
commit 5fa298e9eb
2 changed files with 2 additions and 50 deletions

View File

@@ -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);
}
}

View File

@@ -1,5 +1,5 @@
use std::net::UdpSocket;
use std::io::stdin;
use std::net::UdpSocket;
fn main() {
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 (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"));
println!("{}:{}", src_addr.to_string(), message);
if message.trim() == "!STOP" {