#![doc(html_root_url = "https://docs.rs/maplike")]
#![doc = include_str!("../README.md")]
#![deny(missing_docs)]
#![forbid(unsafe_code)]
#![no_std]
use core::ops::Index;
#[cfg(feature = "std")]
extern crate std as std_;
#[cfg(feature = "alloc")]
extern crate alloc as alloc_;
#[cfg(feature = "maplike_derive")]
pub use maplike_derive::{Assign, Container};
pub trait Container {
type Key;
type Value;
}
pub trait Assign<V = Self>: Container {
fn assign(&mut self, value: V);
}
pub trait Get<K>: Container {
fn get(&self, key: &K) -> Option<&Self::Value>;
}
pub trait Set<K>: Container {
fn set(&mut self, key: K, value: Self::Value);
}
pub trait Insert<K>: Container {
fn insert(&mut self, key: K, value: Self::Value);
}
pub trait Remove<K>: Container {
fn remove(&mut self, key: &K) -> Option<Self::Value>;
}
pub trait Push<K>: Container {
fn push(&mut self, value: Self::Value) -> K;
}
pub trait Pop: Container {
fn pop(&mut self) -> Option<Self::Value>;
}
pub trait Clear: Container {
fn clear(&mut self);
}
pub trait Len: Container {
fn len(&self) -> Self::Key;
}
pub trait IntoIter<K>: Container {
type IntoIter: Iterator<Item = (K, Self::Value)>;
fn into_iter(self) -> Self::IntoIter;
}
pub trait Scalarlike<V = Self>: Assign<V> {}
impl<V, T: Assign<V>> Scalarlike<V> for T {}
pub trait Maplike<K>: Get<K> + Set<K> + Insert<K> + Remove<K> + Clear
where
for<'a> Self: Index<&'a K>,
{
}
impl<K, T: Get<K> + Set<K> + Insert<K> + Remove<K> + Clear> Maplike<K> for T where
for<'a> Self: Index<&'a K>
{
}
pub trait Setlike<K>: Maplike<K, Value = ()> {}
impl<K, T: Maplike<K, Value = ()>> Setlike<K> for T {}
pub trait Arraylike<K>: Index<K> + Get<K> + Set<K> + Len {}
impl<K, T: Index<K> + Get<K> + Set<K> + Len> Arraylike<K> for T {}
pub trait Veclike<K>: Index<K> + Get<K> + Set<K> + Push<K> + Pop + Clear + Len {}
impl<K, T: Arraylike<K> + Push<K> + Pop + Clear> Veclike<K> for T {}
mod compounds;
mod scalars;
#[cfg(feature = "std")]
mod std;
#[cfg(feature = "alloc")]
mod alloc;
#[cfg(feature = "stable-vec")]
mod stable_vec;
#[cfg(feature = "thunderdome")]
mod thunderdome;
#[cfg(feature = "rstar")]
mod rstar;