Skip to content

Commit

Permalink
use cfg! for io error creation
Browse files Browse the repository at this point in the history
  • Loading branch information
DanikVitek committed Jan 29, 2025
1 parent ae05c33 commit c57e5e6
Showing 1 changed file with 22 additions and 6 deletions.
28 changes: 22 additions & 6 deletions borsh/src/de/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ use crate::{
boxed::Box,
collections::{BTreeMap, BTreeSet, LinkedList, VecDeque},
format,
string::String,
string::{String, ToString},
vec,
vec::Vec,
},
Expand Down Expand Up @@ -571,7 +571,13 @@ impl BorshDeserialize for String {
} else {
<Vec<u8> as BorshDeserializeAsync>::deserialize_reader(reader).await
}?)
.map_err(|err| Error::new(ErrorKind::InvalidData, err))
.map_err(|err| {
if cfg!(feature = "std") {
Error::new(ErrorKind::InvalidData, err)
} else {
Error::new(ErrorKind::InvalidData, err.to_string())
}
})
}
}

Expand Down Expand Up @@ -606,8 +612,13 @@ pub mod ascii {
} else {
<Vec<u8> as BorshDeserializeAsync>::deserialize_reader(reader).await
}?;
ascii::AsciiString::from_ascii(bytes)
.map_err(|err| Error::new(ErrorKind::InvalidData, err))
ascii::AsciiString::from_ascii(bytes).map_err(|err| {
if cfg!(feature = "std") {
Error::new(ErrorKind::InvalidData, err)
} else {
Error::new(ErrorKind::InvalidData, err.to_string())
}
})
}
}

Expand All @@ -624,8 +635,13 @@ pub mod ascii {
} else {
<u8 as BorshDeserializeAsync>::deserialize_reader(reader).await
}?;
ascii::AsciiChar::from_ascii(byte)
.map_err(|err| Error::new(ErrorKind::InvalidData, err))
ascii::AsciiChar::from_ascii(byte).map_err(|err| {
if cfg!(feature = "std") {
Error::new(ErrorKind::InvalidData, err)
} else {
Error::new(ErrorKind::InvalidData, err.to_string())
}
})
}
}
}
Expand Down

0 comments on commit c57e5e6

Please sign in to comment.