use super::{FromSchema, FromSchemaError, IntoSchema, SchemaBuilder, value_kind};
use crate::schema::metadata::TypeId;
use crate::schema::schema_type::SchemaType;
use crate::schema::schema_value::SchemaValue;
#[cfg(feature = "guest")]
crate::schema::wit::direct::wire_string!(
::num_bigint::BigInt,
|value: &::num_bigint::BigInt| value.to_string(),
|value: &str| value.parse::<::num_bigint::BigInt>()
);
impl IntoSchema for ::num_bigint::BigInt {
fn type_id() -> TypeId {
TypeId::new("num_bigint.BigInt")
}
fn register_in(_b: &mut SchemaBuilder) -> SchemaType {
SchemaType::string()
}
fn to_value(&self) -> SchemaValue {
SchemaValue::String(self.to_string())
}
}
impl FromSchema for ::num_bigint::BigInt {
fn from_value(v: &SchemaValue) -> Result<Self, FromSchemaError> {
match v {
SchemaValue::String(value) => value
.parse()
.map_err(|e| FromSchemaError::custom(format!("invalid BigInt: {e}"))),
other => Err(FromSchemaError::shape_mismatch(
"string",
value_kind(other),
"BigInt",
)),
}
}
}