Skip to content

Commit

Permalink
assume bytes to scval conversion never errors
Browse files Browse the repository at this point in the history
(cherry picked from commit 638dac8)
  • Loading branch information
leighmcculloch committed Feb 25, 2025
1 parent c8e2e2c commit 728ebb6
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions soroban-sdk/src/bytes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1076,18 +1076,21 @@ impl<const N: usize> From<&BytesN<N>> for Bytes {
}

#[cfg(not(target_family = "wasm"))]
impl<const N: usize> TryFrom<&BytesN<N>> for ScVal {
type Error = ConversionError;
fn try_from(v: &BytesN<N>) -> Result<Self, ConversionError> {
Ok(ScVal::try_from_val(&v.0.env, &v.0.obj.to_val())?)
impl<const N: usize> From<&BytesN<N>> for ScVal {
fn from(v: &BytesN<N>) -> Self {
// This conversion occurs only in test utilities, and theoretically all
// values should convert to an ScVal because the Env won't let the host
// type to exist otherwise, unwrapping. Even if there are edge cases
// that don't, this is a trade off for a better test developer
// experience.
ScVal::try_from_val(&v.0.env, &v.0.obj.to_val()).unwrap()
}
}

#[cfg(not(target_family = "wasm"))]
impl<const N: usize> TryFrom<BytesN<N>> for ScVal {
type Error = ConversionError;
fn try_from(v: BytesN<N>) -> Result<Self, ConversionError> {
(&v).try_into()
impl<const N: usize> From<BytesN<N>> for ScVal {
fn from(v: BytesN<N>) -> Self {
(&v).into()
}
}

Expand Down

0 comments on commit 728ebb6

Please sign in to comment.