summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKlara Modin <kasm@kasm.eu>2018-05-16 23:53:10 +0200
committerKlara Modin <kasm@kasm.eu>2018-05-16 23:53:10 +0200
commit333bc46168fc93d4e3b3817c2db316f8b0d4f0b9 (patch)
tree497516fa519959be2bc38293e88543240b85d1a9
parent1c5ca47d8b67ce411d04c232174c8023ff0bba4e (diff)
fix out of bounds error
-rw-r--r--src/ui.rs8
-rw-r--r--src/user_int.rs30
2 files changed, 13 insertions, 25 deletions
diff --git a/src/ui.rs b/src/ui.rs
index 81789ea..e189ff0 100644
--- a/src/ui.rs
+++ b/src/ui.rs
@@ -123,13 +123,13 @@ impl UI {
},
_ => {
/*
- let prefix = message.prefix.unwrap_or("".to_string());
+ let prefix = message.prefix.unwrap_or(String::new());
print!("{}: ", prefix);
self.print_params_2(message.params);
*/
let cmd = &message.command;
{
- let context = &message.params[0];
+ let context = &message.params.get(0).unwrap_or(&String::new()).clone();
match message.prefix {
Some(ref prefix) =>
self.put_str(&format!("{}({}) -> {}: ", prefix, cmd, context)),
@@ -137,12 +137,12 @@ impl UI {
self.put_str(&format!("({}) -> {}: ", cmd, context)),
}
}
- self.print_params_2(message.params.clone());
+ self.print_params_2(&message.params);
},
}
}
- fn print_params_2(&mut self, params: Vec<String>) {
+ fn print_params_2(&mut self, params: &[String]) {
let mut iter = params.iter().skip(1);
while let Some(output_x) = iter.next() {
self.put_str(&format!("{} ", output_x));
diff --git a/src/user_int.rs b/src/user_int.rs
index 4752700..4b6f4c8 100644
--- a/src/user_int.rs
+++ b/src/user_int.rs
@@ -118,32 +118,20 @@ impl Session {
let mut m = Message::from_str(&line);
match m.command.as_str() {
"NICK" => {
- if m.params.len() > 0 {
- self.nick = m.params[0].clone();
- if let Some(ref ui) = self.ui {
- let mut ui = ui.lock().unwrap();
- ui.nick(&self.nick);
- }
- Some(m)
- } else {
- None
+ self.nick = m.params.get(0).unwrap_or(&String::new()).clone();
+ if let Some(ref ui) = self.ui {
+ let mut ui = ui.lock().unwrap();
+ ui.nick(&self.nick);
}
+ Some(m)
},
"BUFFER" => {
- if m.params.len() > 0 {
- self.chan = m.params[0].clone();
- None
- } else {
- None
- }
+ self.chan = m.params.get(0).unwrap_or(&String::new()).clone();
+ None
},
"JOIN" => {
- if m.params.len() > 0 {
- self.chan = m.params[0].clone();
- Some(m)
- } else {
- None
- }
+ self.chan = m.params.get(0).unwrap_or(&String::new()).clone();
+ Some(m)
},
"PART" => {
m.params.push(self.chan.clone());