-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #86 from H1rono/fix-macro-scope
Fix macro scope
- Loading branch information
Showing
10 changed files
with
21 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,36 +1,37 @@ | ||
#[macro_export] | ||
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_export] | ||
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))) | ||
) | ||
} | ||
} | ||
}; | ||
} | ||
|
||
#[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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters