Skip to content

Commit

Permalink
feat: deref
Browse files Browse the repository at this point in the history
  • Loading branch information
pk5ls20 committed Feb 6, 2025
1 parent 166e2de commit ed20f81
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 20 deletions.
14 changes: 2 additions & 12 deletions mania/src/message/entity/face.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,20 +37,10 @@ impl MessageEntity for FaceEntity {
}));
}

let pb_elem = |common_elem: &CommonElem| {
Bytes::from(
common_elem
.pb_elem
.bytes()
.filter_map(Result::ok)
.collect::<Vec<_>>(),
)
};

elem.common_elem
.as_ref()
.and_then(|common_elem| match common_elem.service_type {
37 => QBigFaceExtra::decode(pb_elem(common_elem))
37 => QBigFaceExtra::decode(&*common_elem.pb_elem)
.ok()
.and_then(|qface| {
qface.face_id.map(|id| {
Expand All @@ -60,7 +50,7 @@ impl MessageEntity for FaceEntity {
})
})
}),
33 => QSmallFaceExtra::decode(pb_elem(common_elem))
33 => QSmallFaceExtra::decode(&*common_elem.pb_elem)
.ok()
.map(|small_face| {
dda!(Self {
Expand Down
8 changes: 1 addition & 7 deletions mania/src/message/entity/forward.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,7 @@ impl MessageEntity for ForwardEntity {
fn unpack_element(elem: &Elem) -> Option<Self> {
match elem.src_msg.as_ref() {
Some(src) => {
let pb_reserve = src
.pb_reserve
.as_ref()?
.bytes()
.filter_map(Result::ok)
.collect::<Vec<_>>();
let reserve = Preserve::decode(Bytes::from(pb_reserve)).ok()?;
let reserve = Preserve::decode(&*src.pb_reserve.clone()?).ok()?;
Some(dda!(Self {
time: DateTime::from_timestamp(src.time.unwrap_or(0) as i64, 0)?,
sequence: reserve.client_sequence.unwrap_or(src.orig_seqs[0]),
Expand Down
1 change: 1 addition & 0 deletions mania/src/message/entity/json.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ pub struct JsonEntity {
pub json: String,
pub res_id: String,
}

impl Debug for JsonEntity {
fn fmt(&self, f: &mut Formatter<'_>) -> FmtResult {
write!(f, "[Json]: {}", self.json)
Expand Down
1 change: 0 additions & 1 deletion mania/src/message/entity/text.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use super::prelude::*;
use std::fmt::Debug;

#[derive(Default)]
pub struct TextEntity {
Expand Down

0 comments on commit ed20f81

Please sign in to comment.