From 3312c169cad4011bd92d9b0ed4cb7cd891a908ab Mon Sep 17 00:00:00 2001 From: H1rono Date: Mon, 25 Sep 2023 20:22:10 +0900 Subject: [PATCH 1/2] :bug: Make macros `pub(crate)` --- src/lib.rs | 1 - src/macros.rs | 11 ++++++----- src/payloads/channel.rs | 2 +- src/payloads/message.rs | 2 +- src/payloads/stamp.rs | 2 +- src/payloads/system.rs | 2 +- src/payloads/tag.rs | 2 +- src/payloads/types.rs | 2 +- src/payloads/user.rs | 2 +- src/payloads/user_group.rs | 2 +- 10 files changed, 14 insertions(+), 14 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index f085a9d..00a5758 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -8,7 +8,6 @@ //! [examples](https://github.com/H1rono/traq-bot-http-rs/blob/main/examples) mod events; -#[macro_use] pub(crate) mod macros; mod parser; pub mod payloads; diff --git a/src/macros.rs b/src/macros.rs index 7d4eb99..8082322 100644 --- a/src/macros.rs +++ b/src/macros.rs @@ -1,4 +1,3 @@ -#[macro_export] macro_rules! impl_from_str { ($t:ty) => { impl FromStr for $t { @@ -11,7 +10,6 @@ macro_rules! impl_from_str { }; } -#[macro_export] macro_rules! impl_display { ($t:ty) => { impl std::fmt::Display for $t { @@ -27,10 +25,13 @@ macro_rules! impl_display { }; } -#[macro_export] macro_rules! payload_impl { ($t:ty) => { - impl_from_str! {$t} - impl_display! {$t} + $crate::macros::impl_from_str! {$t} + $crate::macros::impl_display! {$t} }; } + +pub(crate) use impl_display; +pub(crate) use impl_from_str; +pub(crate) use payload_impl; diff --git a/src/payloads/channel.rs b/src/payloads/channel.rs index 0528c0b..c1b4689 100644 --- a/src/payloads/channel.rs +++ b/src/payloads/channel.rs @@ -5,7 +5,7 @@ use std::str::FromStr; use serde::{Deserialize, Serialize}; use super::types::{Channel, TimeStamp, User}; -use crate::payload_impl; +use crate::macros::payload_impl; /// CHANNEL_CREATEDペイロード /// - [traQの型定義](https://github.com/traPtitech/traQ/blob/d2bc98f1e0e68f4acc371eb78e6a49a167446761/service/bot/event/payload/ev_channel_created.go#L9-L13) diff --git a/src/payloads/message.rs b/src/payloads/message.rs index f3d7ad0..e3939ca 100644 --- a/src/payloads/message.rs +++ b/src/payloads/message.rs @@ -5,7 +5,7 @@ use std::str::FromStr; use serde::{Deserialize, Serialize}; use super::types::{DeletedDirectMessage, DeletedMessage, Message, MessageStamp, TimeStamp, Uuid}; -use crate::payload_impl; +use crate::macros::payload_impl; /// MESSAGE_CREATEDペイロード /// - [traQの型定義](https://github.com/traPtitech/traQ/blob/d2bc98f1e0e68f4acc371eb78e6a49a167446761/service/bot/event/payload/ev_message_created.go#L10-L14) diff --git a/src/payloads/stamp.rs b/src/payloads/stamp.rs index e1b3443..25acae7 100644 --- a/src/payloads/stamp.rs +++ b/src/payloads/stamp.rs @@ -5,7 +5,7 @@ use std::str::FromStr; use serde::{Deserialize, Serialize}; use super::types::{TimeStamp, User, Uuid}; -use crate::payload_impl; +use crate::macros::payload_impl; /// STAMP_CREATEDペイロード /// - [traQの型定義](https://github.com/traPtitech/traQ/blob/d2bc98f1e0e68f4acc371eb78e6a49a167446761/service/bot/event/payload/ev_stamp_created.go#L11-L18) diff --git a/src/payloads/system.rs b/src/payloads/system.rs index ccc0269..e7da762 100644 --- a/src/payloads/system.rs +++ b/src/payloads/system.rs @@ -5,7 +5,7 @@ use std::str::FromStr; use serde::{Deserialize, Serialize}; use super::types::{Channel, TimeStamp}; -use crate::payload_impl; +use crate::macros::payload_impl; /// PINGペイロード /// - [traQの型定義](https://github.com/traPtitech/traQ/blob/d2bc98f1e0e68f4acc371eb78e6a49a167446761/service/bot/event/payload/ev_ping.go#L5-L8) diff --git a/src/payloads/tag.rs b/src/payloads/tag.rs index 8529d8d..b8274e9 100644 --- a/src/payloads/tag.rs +++ b/src/payloads/tag.rs @@ -5,7 +5,7 @@ use std::str::FromStr; use serde::{Deserialize, Serialize}; use super::types::{TimeStamp, Uuid}; -use crate::payload_impl; +use crate::macros::payload_impl; /// TAG_ADDEDペイロード /// - [traQの型定義](https://github.com/traPtitech/traQ/blob/d2bc98f1e0e68f4acc371eb78e6a49a167446761/service/bot/event/payload/ev_tag_added.go#L11-L16) diff --git a/src/payloads/types.rs b/src/payloads/types.rs index 80358f6..d6ef4af 100644 --- a/src/payloads/types.rs +++ b/src/payloads/types.rs @@ -11,7 +11,7 @@ use chrono::{DateTime, Utc}; #[cfg(feature = "time")] use time::OffsetDateTime; -use crate::payload_impl; +use crate::macros::payload_impl; #[cfg(feature = "chrono")] pub type TimeStamp = DateTime; diff --git a/src/payloads/user.rs b/src/payloads/user.rs index d3b4079..5aecdb9 100644 --- a/src/payloads/user.rs +++ b/src/payloads/user.rs @@ -5,7 +5,7 @@ use std::str::FromStr; use serde::{Deserialize, Serialize}; use super::types::{TimeStamp, User}; -use crate::payload_impl; +use crate::macros::payload_impl; /// USER_CREATEDペイロード /// - [traQの型定義](https://github.com/traPtitech/traQ/blob/d2bc98f1e0e68f4acc371eb78e6a49a167446761/service/bot/event/payload/ev_user_created.go#L9-L13) diff --git a/src/payloads/user_group.rs b/src/payloads/user_group.rs index 1bada1f..c24caa1 100644 --- a/src/payloads/user_group.rs +++ b/src/payloads/user_group.rs @@ -5,7 +5,7 @@ use std::str::FromStr; use serde::{Deserialize, Serialize}; use super::types::{GroupMember, TimeStamp, UserGroup, Uuid}; -use crate::payload_impl; +use crate::macros::payload_impl; /// USER_GROUP_CREATEDペイロード /// - [traQの型定義](https://github.com/traPtitech/traQ/blob/a1aaf12d089a9033461d0f1fcabb69a92873a3b1/service/bot/event/payload/ev_user_group_created.go#L9-L13) From 86ed621bede313afd7801ee2862d45cc03805e44 Mon Sep 17 00:00:00 2001 From: H1rono Date: Mon, 25 Sep 2023 20:28:09 +0900 Subject: [PATCH 2/2] :recycle: Make macros hygienic --- src/macros.rs | 14 +++++++------- src/payloads/channel.rs | 2 -- src/payloads/message.rs | 2 -- src/payloads/stamp.rs | 2 -- src/payloads/system.rs | 2 -- src/payloads/tag.rs | 2 -- src/payloads/types.rs | 2 -- src/payloads/user.rs | 2 -- src/payloads/user_group.rs | 2 -- 9 files changed, 7 insertions(+), 23 deletions(-) diff --git a/src/macros.rs b/src/macros.rs index 8082322..c701dae 100644 --- a/src/macros.rs +++ b/src/macros.rs @@ -1,10 +1,10 @@ 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 { - serde_json::from_str(s) + fn from_str(s: &str) -> ::std::result::Result { + ::serde_json::from_str(s) } } }; @@ -12,12 +12,12 @@ macro_rules! impl_from_str { 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))) ) } diff --git a/src/payloads/channel.rs b/src/payloads/channel.rs index c1b4689..b0750db 100644 --- a/src/payloads/channel.rs +++ b/src/payloads/channel.rs @@ -1,7 +1,5 @@ //! チャンネル関連のイベントペイロード -use std::str::FromStr; - use serde::{Deserialize, Serialize}; use super::types::{Channel, TimeStamp, User}; diff --git a/src/payloads/message.rs b/src/payloads/message.rs index e3939ca..f28e15d 100644 --- a/src/payloads/message.rs +++ b/src/payloads/message.rs @@ -1,7 +1,5 @@ //! メッセージ関連のイベントペイロード -use std::str::FromStr; - use serde::{Deserialize, Serialize}; use super::types::{DeletedDirectMessage, DeletedMessage, Message, MessageStamp, TimeStamp, Uuid}; diff --git a/src/payloads/stamp.rs b/src/payloads/stamp.rs index 25acae7..61c6cc6 100644 --- a/src/payloads/stamp.rs +++ b/src/payloads/stamp.rs @@ -1,7 +1,5 @@ //! スタンプ関連のイベントペイロード -use std::str::FromStr; - use serde::{Deserialize, Serialize}; use super::types::{TimeStamp, User, Uuid}; diff --git a/src/payloads/system.rs b/src/payloads/system.rs index e7da762..931424c 100644 --- a/src/payloads/system.rs +++ b/src/payloads/system.rs @@ -1,7 +1,5 @@ //! システム関連のイベントペイロード -use std::str::FromStr; - use serde::{Deserialize, Serialize}; use super::types::{Channel, TimeStamp}; diff --git a/src/payloads/tag.rs b/src/payloads/tag.rs index b8274e9..cac8a81 100644 --- a/src/payloads/tag.rs +++ b/src/payloads/tag.rs @@ -1,7 +1,5 @@ //! タグ関連のイベントペイロード -use std::str::FromStr; - use serde::{Deserialize, Serialize}; use super::types::{TimeStamp, Uuid}; diff --git a/src/payloads/types.rs b/src/payloads/types.rs index d6ef4af..0d35177 100644 --- a/src/payloads/types.rs +++ b/src/payloads/types.rs @@ -1,7 +1,5 @@ //! イベントペイロード内部で使われる型 -use std::str::FromStr; - use serde::{Deserialize, Serialize}; #[cfg(feature = "chrono")] diff --git a/src/payloads/user.rs b/src/payloads/user.rs index 5aecdb9..70cf094 100644 --- a/src/payloads/user.rs +++ b/src/payloads/user.rs @@ -1,7 +1,5 @@ //! ユーザー関連のイベントペイロード -use std::str::FromStr; - use serde::{Deserialize, Serialize}; use super::types::{TimeStamp, User}; diff --git a/src/payloads/user_group.rs b/src/payloads/user_group.rs index c24caa1..92f618c 100644 --- a/src/payloads/user_group.rs +++ b/src/payloads/user_group.rs @@ -1,7 +1,5 @@ //! ユーザーグループ関連のイベントペイロード -use std::str::FromStr; - use serde::{Deserialize, Serialize}; use super::types::{GroupMember, TimeStamp, UserGroup, Uuid};