Remove clone
This commit is contained in:
parent
7e7cf010a0
commit
a86d38f913
1 changed files with 0 additions and 7 deletions
|
|
@ -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();
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue