af_sui_pkg_sdk::sui_pkg_sdk!(std @ "0x1" {
module ascii {
#[serde(transparent)]
struct String has copy, drop, store {
bytes: vector<u8>,
}
struct Char has copy, drop, store {
byte: u8,
}
}
module bit_vector {
struct BitVector has copy, drop, store {
length: u64,
bit_field: vector<bool>,
}
}
module fixed_point32 {
struct FixedPoint32 has copy, drop, store { value: u64 }
}
module option {
struct Option<Element> has copy, drop, store {
vec: vector<Element>
}
}
module string {
struct String has copy, drop, store {
bytes: vector<u8>,
}
}
module type_name {
struct TypeName has copy, drop, store {
name: String
}
}
});
impl TryFrom<String> for ascii::String {
type Error = NotAscii;
fn try_from(value: String) -> Result<Self, Self::Error> {
if !value.is_ascii() {
return Err(NotAscii);
}
Ok(Self {
bytes: value.bytes().collect::<Vec<_>>().into(),
})
}
}
#[derive(thiserror::Error, Debug)]
#[error("Not an ascii string")]
pub struct NotAscii;
impl TryFrom<ascii::String> for String {
type Error = std::string::FromUtf8Error;
fn try_from(value: ascii::String) -> Result<Self, Self::Error> {
Self::from_utf8(value.bytes.into())
}
}