Refactor response_classes and fix clippy issues
This commit is contained in:
parent
244a7073fe
commit
463bc99b9c
8 changed files with 139 additions and 133 deletions
src/response
39
src/response/client.rs
Normal file
39
src/response/client.rs
Normal file
|
@ -0,0 +1,39 @@
|
|||
use std::fmt::{Display, Formatter};
|
||||
use crate::parameter::{parameter_find, ParameterList};
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct ResponseClient {
|
||||
pub cid: i32,
|
||||
pub clid: i32,
|
||||
pub client_database_id: i32,
|
||||
pub client_nickname: String,
|
||||
pub client_type: i32,
|
||||
}
|
||||
|
||||
impl Display for ResponseClient {
|
||||
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
|
||||
write!(f, "{} ({})", self.client_nickname, self.clid)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<ParameterList> for ResponseClient {
|
||||
fn from(value: ParameterList) -> Self {
|
||||
ResponseClient {
|
||||
cid: parameter_find(&value, "cid")
|
||||
.unwrap_or_default()
|
||||
.to_i32(-1),
|
||||
clid: parameter_find(&value, "clid")
|
||||
.unwrap_or_default()
|
||||
.to_i32(-1),
|
||||
client_database_id: parameter_find(&value, "client_database_id")
|
||||
.unwrap_or_default()
|
||||
.to_i32(-1),
|
||||
client_nickname: parameter_find(&value, "client_nickname")
|
||||
.unwrap_or_default()
|
||||
.value,
|
||||
client_type: parameter_find(&value, "channel_topic")
|
||||
.unwrap_or_default()
|
||||
.to_i32(0),
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue