Skip to content

Commit

Permalink
♻️ Make macros hygienic
Browse files Browse the repository at this point in the history
  • Loading branch information
H1rono committed Sep 25, 2023
1 parent 3312c16 commit 86ed621
Show file tree
Hide file tree
Showing 9 changed files with 7 additions and 23 deletions.
14 changes: 7 additions & 7 deletions src/macros.rs
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
macro_rules! impl_from_str {
($t:ty) => {
impl FromStr for $t {
type Err = serde_json::Error;
impl ::std::str::FromStr for $t {
type Err = ::serde_json::Error;

fn from_str(s: &str) -> Result<Self, Self::Err> {
serde_json::from_str(s)
fn from_str(s: &str) -> ::std::result::Result<Self, Self::Err> {
::serde_json::from_str(s)
}
}
};
}

macro_rules! impl_display {
($t:ty) => {
impl std::fmt::Display for $t {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
impl ::std::fmt::Display for $t {
fn fmt(&self, f: &mut ::std::fmt::Formatter<'_>) -> ::std::fmt::Result {
write!(
f,
"{}",
serde_json::to_string(self)
::serde_json::to_string(self)
.expect(concat!("failed to serialize ", stringify!($t)))
)
}
Expand Down
2 changes: 0 additions & 2 deletions src/payloads/channel.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
//! チャンネル関連のイベントペイロード
use std::str::FromStr;

use serde::{Deserialize, Serialize};

use super::types::{Channel, TimeStamp, User};
Expand Down
2 changes: 0 additions & 2 deletions src/payloads/message.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
//! メッセージ関連のイベントペイロード
use std::str::FromStr;

use serde::{Deserialize, Serialize};

use super::types::{DeletedDirectMessage, DeletedMessage, Message, MessageStamp, TimeStamp, Uuid};
Expand Down
2 changes: 0 additions & 2 deletions src/payloads/stamp.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
//! スタンプ関連のイベントペイロード
use std::str::FromStr;

use serde::{Deserialize, Serialize};

use super::types::{TimeStamp, User, Uuid};
Expand Down
2 changes: 0 additions & 2 deletions src/payloads/system.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
//! システム関連のイベントペイロード
use std::str::FromStr;

use serde::{Deserialize, Serialize};

use super::types::{Channel, TimeStamp};
Expand Down
2 changes: 0 additions & 2 deletions src/payloads/tag.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
//! タグ関連のイベントペイロード
use std::str::FromStr;

use serde::{Deserialize, Serialize};

use super::types::{TimeStamp, Uuid};
Expand Down
2 changes: 0 additions & 2 deletions src/payloads/types.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
//! イベントペイロード内部で使われる型
use std::str::FromStr;

use serde::{Deserialize, Serialize};

#[cfg(feature = "chrono")]
Expand Down
2 changes: 0 additions & 2 deletions src/payloads/user.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
//! ユーザー関連のイベントペイロード
use std::str::FromStr;

use serde::{Deserialize, Serialize};

use super::types::{TimeStamp, User};
Expand Down
2 changes: 0 additions & 2 deletions src/payloads/user_group.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
//! ユーザーグループ関連のイベントペイロード
use std::str::FromStr;

use serde::{Deserialize, Serialize};

use super::types::{GroupMember, TimeStamp, UserGroup, Uuid};
Expand Down

0 comments on commit 86ed621

Please sign in to comment.