#![allow(unused_variables)]
use crate::valueptr::ValuePtr;
use crate::valueptr::ValuePtrMut;
pub trait ValuePath {
fn get_index<'tr>(&'tr self, i: usize) -> Option<&'tr Self>
{
None
}
fn get_key<'tr>(&'tr self, k: &str) -> Option<&'tr Self>
{
None
}
fn get_index_mut<'tr>(&'tr mut self, i: usize) -> Option<&'tr mut Self>
{
None
}
fn get_key_mut<'tr>(&'tr mut self, k: &str) -> Option<&'tr mut Self>
{
None
}
fn path<'tr>(&'tr self) -> ValuePtr<'tr, Self>
where Self: ValueReader + Sized
{
ValuePtr::new(Some(self))
}
fn pathto<'tr>(&'tr self, p: &str) -> ValuePtr<'tr, Self>
where Self: ValueReader + Sized
{
self.path().pathto(p)
}
fn path_mut<'tr>(&'tr mut self) -> ValuePtrMut<'tr, Self>
where Self: ValueReader + ValueWriter + Sized
{
ValuePtrMut::new(Some(self))
}
fn pathto_mut<'tr>(&'tr mut self, p: &str) -> ValuePtrMut<'tr, Self>
where Self: ValueReader + ValueWriter + Sized
{
self.path_mut().pathto(p)
}
}
pub trait ScalarValue {}
impl ScalarValue for String {}
impl ScalarValue for &str {}
impl ScalarValue for i64 {}
impl ScalarValue for f64 {}
impl ScalarValue for bool {}
impl ScalarValue for () {}
pub trait ValueReader {
fn get_str<'tr>(&'tr self, rhs: &'tr str) -> &'tr str { rhs }
fn get_string(&self, rhs: String) -> String { rhs }
fn get_i64(&self, rhs: i64) -> i64 { rhs }
fn get_f64(&self, rhs: f64) -> f64 { rhs }
fn get_bool(&self, rhs: bool) -> bool { rhs }
}
pub trait ValueWriter {
fn put_value<T>(&mut self, rhs: T) -> &mut Self
where Self: From<T>, T: ScalarValue
{
self
}
fn push_object<K: ToString, T>(&mut self, key: K, val: T) -> &mut Self
where Self: From<T>
{
self
}
fn push_array<T>(&mut self, val: T) -> &mut Self
where Self: From<T>
{
self
}
}