Skip to content

Commit a35f56f

Browse files
committed
Allow key deserialization from owned strings
1 parent a184212 commit a35f56f

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

src/macros.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,9 +64,19 @@ macro_rules! serde_impl(
6464
fn deserialize<D: ::serde::Deserializer<'de>>(d: D) -> Result<$t, D::Error> {
6565
use ::serde::de::Error;
6666
use core::str::FromStr;
67+
#[cfg(feature = "std")]
68+
use std::borrow::Cow;
6769

6870
if d.is_human_readable() {
71+
// If std is available support deserializing from owned strings
72+
#[cfg(feature = "std")]
73+
let s_cow: Cow<'de, str> = ::serde::Deserialize::deserialize(d)?;
74+
#[cfg(feature = "std")]
75+
let sl = &s_cow;
76+
77+
#[cfg(not(feature = "std"))]
6978
let sl: &str = ::serde::Deserialize::deserialize(d)?;
79+
7080
SecretKey::from_str(sl).map_err(D::Error::custom)
7181
} else {
7282
let sl: &[u8] = ::serde::Deserialize::deserialize(d)?;

0 commit comments

Comments
 (0)