use crate::access::dict::BDictAccess;
use crate::access::list::BListAccess;
pub enum RefKind<'a, K, V> {
Int(i64),
Bytes(&'a [u8]),
List(&'a dyn BListAccess<V>),
Dict(&'a dyn BDictAccess<K, V>),
}
pub trait BRefAccess: Sized {
type BKey;
type BType: BRefAccess<BKey = Self::BKey>;
fn kind(&self) -> RefKind<'_, Self::BKey, Self::BType>;
fn str(&self) -> Option<&str>;
fn int(&self) -> Option<i64>;
fn bytes(&self) -> Option<&[u8]>;
fn list(&self) -> Option<&dyn BListAccess<Self::BType>>;
fn dict(&self) -> Option<&dyn BDictAccess<Self::BKey, Self::BType>>;
}
pub trait BRefAccessExt<'a>: BRefAccess {
fn str_ext(&self) -> Option<&'a str>;
fn bytes_ext(&self) -> Option<&'a [u8]>;
}
impl<'a, T> BRefAccess for &'a T
where
T: BRefAccess,
{
type BKey = T::BKey;
type BType = T::BType;
fn kind(&self) -> RefKind<'_, Self::BKey, Self::BType> {
(*self).kind()
}
fn str(&self) -> Option<&str> {
(*self).str()
}
fn int(&self) -> Option<i64> {
(*self).int()
}
fn bytes(&self) -> Option<&[u8]> {
(*self).bytes()
}
fn list(&self) -> Option<&dyn BListAccess<Self::BType>> {
(*self).list()
}
fn dict(&self) -> Option<&dyn BDictAccess<Self::BKey, Self::BType>> {
(*self).dict()
}
}
impl<'a: 'b, 'b, T> BRefAccessExt<'a> for &'b T
where
T: BRefAccessExt<'a>,
{
fn str_ext(&self) -> Option<&'a str> {
(*self).str_ext()
}
fn bytes_ext(&self) -> Option<&'a [u8]> {
(*self).bytes_ext()
}
}
pub enum MutKind<'a, K, V> {
Int(i64),
Bytes(&'a [u8]),
List(&'a mut dyn BListAccess<V>),
Dict(&'a mut dyn BDictAccess<K, V>),
}
pub trait BMutAccess: Sized + BRefAccess {
fn kind_mut(&mut self) -> MutKind<'_, Self::BKey, Self::BType>;
fn list_mut(&mut self) -> Option<&mut dyn BListAccess<Self::BType>>;
fn dict_mut(&mut self) -> Option<&mut dyn BDictAccess<Self::BKey, Self::BType>>;
}