Remove clone

This commit is contained in:
Bastian Gruber 2023-05-01 10:30:52 +02:00
parent 7e7cf010a0
commit a86d38f913
No known key found for this signature in database
GPG key ID: BE9F8C772B188CBF

View file

@ -14,30 +14,23 @@ async fn main() -> io::Result<()> {
tokio::spawn(async move {
while let Some((bytes, addr)) = rx.recv().await {
let len = s.send_to(&bytes, &addr).await.unwrap();
println!("{:?} bytes sent", len);
}
});
let mut buf = [0; 1024];
loop {
let (len, addr) = r.recv_from(&mut buf).await?;
println!("{:?} bytes received from {:?}", len, addr);
let message = str::from_utf8(&buf[..len]).unwrap().trim_matches('\n');
let storage = storage.clone();
if message.contains("=") {
println!("Insert request");
let (key, value) = message.split_once('=').unwrap();
println!("Key: {key}");
println!("Value: {value}");
storage
.lock()
.unwrap()
.insert(key.to_string(), value.to_string());
// continue;
} else {
println!("Get request: {}", message);
let value = storage.lock().unwrap().get(message).unwrap().clone();
tx.send((value.as_bytes().to_vec(), addr)).await.unwrap();
}