INDAPlus21 / INDAPlus21/ogronman-sockets

Pass

Open
#1 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Rust
Stars
0
Forks
0
PR merge metrics
No merged PRs in 30d

Description

**Very well done Oskar!**

Dude,
```
PS C:\[...]\ogronman-sockets\chat> cargo run
[...]
(C:\Users\viola\Documents\INDA_2021\tasks\plus-sockets\ogronman\ogronman-sockets\chat)
Finished dev [unoptimized + debuginfo] target(s) in 5.31s
Running `target\debug\chat.exe`
create
create 3000
help
ks
s
s

s

s
s
```

I'm sure it works on your machine.

A couple of notes:

- Why don't you format your strings?

_Your code_:
```rs
"whisper" => {
if /*...*/ {
let mut send_msg = "/whisper ".to_string();
send_msg.push_str(&msg[1]);
send_msg.push_str(" ");
send_msg.push_str("whisper from ");
send_msg.push_str(&name);
send_msg.push_str(": ");
let n_msg = &msg[2..msg.len()];
let rest_msg = n_msg.join(" ");
send_msg.push_str(&rest_msg);
sender.send(send_msg).expect("Failed to send");
}
}
```
_Refactored code_:
```rs
"whisper" => {
if /*...*/ {
let send_msg =
format!("/whisper {} whisper from {}: {}", &msg[1], &name, &msg[2..msg.len()].join(" "));
sender.send(send_msg).expect("Failed to send");
}
}
```

- What?

_Your code_:
```rs
"leave" => {
let mut s_end = end.lock().unwrap();
*s_end = *s_end + 1;
//...
}
```
_Refactored code_:
```rs
"leave" => {
let s_end = end.lock().unwrap() + 1;
//...
}
```

- Whaat?

_Your code_:
```rs
match msgs[0].as_str(){
"black" => {
println!("{}", format!("{}", n_msg).on_black());
},
"red" => {
println!("{}", format!("{}",n_msg).red());
},
"green" => {
println!("{}", format!("{}",n_msg).green());
},
"yellow" => {
println!("{}", format!("{}",n_msg).yellow());
},
"blue" => {
println!("{}", format!("{}",n_msg).blue());
},
"magenta" => {
println!("{}", format!("{}",n_msg).bright_magenta());
},
"cyan" => {
println!("{}", format!("{}",n_msg).cyan());
},
"white" => {
println!("{}", format!("{}",n_msg).white());
},
_ => (),
}
```
_Refactored code_:
```rs
use colored::Color;
//...
println!("{}", format!("{}", n_msg).color(
match msgs[0].as_str() {
"black" => Color::Black,
"red" => Color::Red,
"green" => Color::Green,
"yellow" => Color::Yellow,
"blue" => Color::Blue,
"magenta" => Color::BrightMagenta,
"cyan" => Color::Cyan,
"white" => Color::White,
_ => (),
}
));
```

- Whaaat?

_Your code_:
```rs
if msg.eq("") {

}
else{
let n_msg: &str = &*msgs[0];
println!("{}", format!("{}",n_msg).white());
}
```
_Refactored code_:
```rs
if !msg.is_empty() {
println!("{}", msgs[0].white());
}
```

Remember:
[![](https://external-content.duckduckgo.com/iu/?u=https%3A%2F%2Fpeople.via.ecp.fr%2F~enizor%2FformationRust%2Fimages%2Fferris.png&f=1&nofb=1)](https://www.reddit.com/r/rustjerk/)

Keep it up!

Contributor guide

No contributing guide indexed for this repository

Research direction

No file, test, or entry point is named. Start by locating the chat command handling code containing the whisper, leave, color, and empty-message snippets, then determine whether these review suggestions still apply. Done would require an explicitly scoped refactoring task and passing project checks.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
networking
Issue type
Refactor
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
15/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.