-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
adds feature-gated serde traits to TransactionMetadata (#77)
* adds feature-gated serde traits to TransactionMetadata * update changelog and serde version --------- Co-authored-by: eric <>
- Loading branch information
1 parent
3fa14bf
commit 446167f
Showing
5 changed files
with
32 additions
and
1 deletion.
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
use { | ||
serde::{de, Deserializer, Serializer}, | ||
serde::{Deserialize, Serialize}, | ||
std::str::FromStr, | ||
}; | ||
|
||
pub fn serialize<T, S>(t: &T, serializer: S) -> Result<S::Ok, S::Error> | ||
where | ||
T: ToString, | ||
S: Serializer, | ||
{ | ||
t.to_string().serialize(serializer) | ||
} | ||
|
||
pub fn deserialize<'de, T, D>(deserializer: D) -> Result<T, D::Error> | ||
where | ||
T: FromStr, | ||
D: Deserializer<'de>, | ||
<T as FromStr>::Err: std::fmt::Debug, | ||
{ | ||
let s: String = String::deserialize(deserializer)?; | ||
s.parse() | ||
.map_err(|e| de::Error::custom(format!("Parse error: {e:?}"))) | ||
} |