use crate::lib::{json, Value};
use crate::internal::{type_name};
pub fn x_to_string(v: &str) -> Value {
json!(v)
}
#[doc(hidden)]
pub fn json_array_to_string_x(vec: Vec<Value>) -> String {
let mut iter = vec.into_iter();
match iter.next() {
Some(v) => {
let mut s = "".to_owned();
if v.is_null() {
s.push_str("null");
} else {
s.push_str(&*to_string_x(v));
}
for v in iter {
s.push(',');
if v.is_null() {
s.push_str("null");
} else {
s.push_str(&*to_string_x(v));
}
}
s
}
None => "".into(),
}
}
pub fn to_string_x(v: Value) -> String {
match v {
Value::Null => "".into(),
Value::Bool(b) => {
if b {
"true".into()
} else {
"false".into()
}
}
Value::Number(n) => n.to_string(),
Value::String(s) => s,
Value::Array(vec) => json_array_to_string_x(vec),
Value::Object(o) => type_name(&o).into(), }
}
pub fn to_string(v: Value) -> Value {
Value::String(to_string_x(v))
}
#[macro_export]
macro_rules! x_to_string {
() => {
json!("")
};
($a:expr $(,)*) => {
$crate::x_to_string($a)
};
($a:expr, $($rest:tt)*) => {
$crate::x_to_string($a)
};
}
#[macro_export]
macro_rules! to_string_x {
() => {
"".to_owned()
};
($a:expr $(,)*) => {
$crate::to_string_x($a)
};
($a:expr, $($rest:tt)*) => {
$crate::to_string_x($a)
};
}
#[macro_export]
macro_rules! to_string {
() => {
json!("")
};
($a:expr $(,)*) => {
$crate::to_string($a)
};
($a:expr, $($rest:tt)*) => {
$crate::to_string($a)
};
}