aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Smeding <tom.smeding@gmail.com>2020-09-17 21:17:35 +0200
committerTom Smeding <tom.smeding@gmail.com>2021-01-28 22:20:12 +0100
commita6d82264a5b099ebfe8f3ecf6d1b81b146804231 (patch)
treea245a10543ecf17ea0582f4d98859492505f4add
parentaba55fd071c6a8c7ef19e170dc54cd5a8a13854e (diff)
rust: Use new tomsg-rs conveniences
-rw-r--r--rust/src/main.rs24
1 files changed, 8 insertions, 16 deletions
diff --git a/rust/src/main.rs b/rust/src/main.rs
index d2377c7..937cc88 100644
--- a/rust/src/main.rs
+++ b/rust/src/main.rs
@@ -13,15 +13,7 @@ use termion::event::Key;
use termion::raw::{IntoRawMode, RawTerminal};
use termion::input::{TermRead, MouseTerminal};
use termion::screen::AlternateScreen;
-use tomsg_rs::Connection;
-use tomsg_rs::connection;
-use tomsg_rs::PushMessage;
-use tomsg_rs::Command;
-use tomsg_rs::Word;
-use tomsg_rs::Line;
-use tomsg_rs::Reply;
-use tomsg_rs::Message;
-use tomsg_rs::Id;
+use tomsg_rs::{connection, Command, Connection, Id, Line, Message, PushMessage, Reply, Word};
use unicode_width::UnicodeWidthChar;
use crate::editor::Editor;
use crate::error::IntoIOError;
@@ -111,9 +103,9 @@ impl Default for Layout {
impl Layout {
fn compute(size: (u16, u16), state: &State) -> Self {
- let rlsepx = u16::try_from(state.roomlist.iter().map(|s| s.as_str().len()).max().unwrap_or(5)).unwrap();
+ let rlsepx = u16::try_from(state.roomlist.iter().map(|s| s.len()).max().unwrap_or(5)).unwrap();
let room = state.rooms.get(&state.currentroom);
- let maxnicklen = room.map(|r| r.members.iter().map(|s| s.as_str().len()).max().unwrap_or(5)).unwrap_or(5);
+ let maxnicklen = room.map(|r| r.members.iter().map(|s| s.len()).max().unwrap_or(5)).unwrap_or(5);
let nlsepx = size.0 - u16::min(size.0, u16::try_from(maxnicklen).unwrap() + 1);
Self { rlsepx, nlsepx }
}
@@ -158,7 +150,7 @@ impl App {
layout: Layout::default(),
roomlist: Vec::new(),
rooms: HashMap::new(),
- currentroom: Word::try_from(String::new()).unwrap(),
+ currentroom: Word::default(),
msgs: HashMap::new(),
};
App {
@@ -202,7 +194,7 @@ impl App {
if state.rooms.insert(room.clone(), RoomData::default()).is_none() {
state.roomlist.push(room.clone());
- if state.currentroom.as_str().len() == 0 {
+ if state.currentroom.len() == 0 {
state.currentroom = room.clone();
}
}
@@ -434,7 +426,7 @@ impl State {
}
}
- if self.currentroom.as_str().len() > 0 {
+ if self.currentroom.len() > 0 {
let data = self.rooms.get_mut(&self.currentroom).unwrap();
for (i, user) in data.members.iter().enumerate() {
@@ -452,7 +444,7 @@ impl State {
let (prefix, text_to_format) = match item {
HItem::Message(id) => {
let msg = self.msgs.get(&id).unwrap();
- (format!("<{}>", msg.username), msg.message.as_str())
+ (format!("<{}>", msg.username), &*msg.message)
}
HItem::Service(msg) => {
@@ -496,7 +488,7 @@ impl State {
match &item {
HItem::Message(id) => {
let msg = self.msgs.get(&id).unwrap();
- data.maxnicklen = data.maxnicklen.max(msg.username.as_str().len() + 2);
+ data.maxnicklen = data.maxnicklen.max(msg.username.len() + 2);
}
HItem::Service(_) => {
data.maxnicklen = data.maxnicklen.max(2);