Skip to content

Commit

Permalink
Remove conversions from String<>ScSymbol/ScVal (#329)
Browse files Browse the repository at this point in the history
* Render asset codes as strings in JSON

* fix

* fix doc comment

* fix test

* Escape asset code strings preserving their values

* test

* fix

* Update xdrgen with StringM escape change

* upd tests

* Remove conversions from String<>ScSymbol/ScVal

* upd version of escape-bytes

* upd hash
  • Loading branch information
leighmcculloch authored Dec 1, 2023
1 parent 408a39c commit 80faa4e
Showing 1 changed file with 1 addition and 79 deletions.
80 changes: 1 addition & 79 deletions src/curr/scval_conversions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use super::{
#[cfg(all(not(feature = "std"), feature = "alloc"))]
extern crate alloc;
#[cfg(all(not(feature = "std"), feature = "alloc"))]
use alloc::{string::String, vec, vec::Vec};
use alloc::{vec, vec::Vec};

// TODO: Use the Error type for conversions in this file.

Expand Down Expand Up @@ -300,84 +300,6 @@ impl TryFrom<ScVal> for ScSymbol {
}
}

#[cfg(feature = "alloc")]
impl TryFrom<String> for ScVal {
type Error = ();
fn try_from(v: String) -> Result<Self, ()> {
Ok(ScVal::Symbol(v.try_into().map_err(|()| ())?))
}
}

#[cfg(feature = "alloc")]
impl TryFrom<&String> for ScVal {
type Error = ();
fn try_from(v: &String) -> Result<Self, ()> {
Ok(ScVal::Symbol(v.try_into().map_err(|()| ())?))
}
}

#[cfg(feature = "alloc")]
impl TryFrom<String> for ScSymbol {
type Error = ();
fn try_from(v: String) -> Result<Self, Self::Error> {
Ok(ScSymbol(v.try_into().map_err(|_| ())?))
}
}

#[cfg(feature = "alloc")]
impl TryFrom<&String> for ScSymbol {
type Error = ();
fn try_from(v: &String) -> Result<Self, Self::Error> {
Ok(ScSymbol(v.try_into().map_err(|_| ())?))
}
}

#[cfg(feature = "alloc")]
impl TryFrom<&str> for ScVal {
type Error = ();
fn try_from(v: &str) -> Result<Self, ()> {
Ok(ScVal::Symbol(v.try_into().map_err(|()| ())?))
}
}

#[cfg(not(feature = "alloc"))]
impl TryFrom<&'static str> for ScVal {
type Error = ();
fn try_from(v: &'static str) -> Result<Self, ()> {
Ok(ScVal::Symbol(v.try_into().map_err(|()| ())?))
}
}

#[cfg(feature = "alloc")]
impl TryFrom<&str> for ScSymbol {
type Error = ();
fn try_from(v: &str) -> Result<Self, Self::Error> {
Ok(ScSymbol(v.try_into().map_err(|_| ())?))
}
}

#[cfg(not(feature = "alloc"))]
impl TryFrom<&'static str> for ScSymbol {
type Error = ();
fn try_from(v: &'static str) -> Result<Self, Self::Error> {
Ok(ScSymbol(v.try_into().map_err(|_| ())?))
}
}

#[cfg(feature = "alloc")]
impl TryFrom<ScVal> for String {
type Error = ();
fn try_from(v: ScVal) -> Result<Self, Self::Error> {
if let ScVal::Symbol(s) = v {
// TODO: It might be worth distinguishing the error case where this
// is an invalid symbol with invalid characters.
Ok(s.0.into_utf8_string().map_err(|_| ())?)
} else {
Err(())
}
}
}

#[cfg(feature = "alloc")]
impl TryFrom<Vec<u8>> for ScVal {
type Error = ();
Expand Down

0 comments on commit 80faa4e

Please sign in to comment.