use crate::state::State;
use crate::traits::RawState;
use core::mem::MaybeUninit;
impl<Q> State<&Q>
where
Q: RawState,
{
pub fn cloned(&self) -> State<Q>
where
Q: Clone,
{
State(self.0.clone())
}
pub fn copied(&self) -> State<Q>
where
Q: Copy,
{
State(*self.0)
}
}
impl<Q> State<&mut Q>
where
Q: RawState,
{
pub fn cloned(&self) -> State<Q>
where
Q: Clone,
{
State(self.0.clone())
}
pub fn copied(&self) -> State<Q>
where
Q: Copy,
{
State(*self.0)
}
}
impl<Q> State<*const Q> where Q: RawState {}
impl<Q> State<*mut Q> where Q: RawState {}
impl<Q> State<MaybeUninit<Q>>
where
Q: RawState,
{
pub fn uninit() -> State<MaybeUninit<Q>> {
State(MaybeUninit::uninit())
}
pub fn init(value: Q) -> State<MaybeUninit<Q>> {
State(MaybeUninit::new(value))
}
}
impl<Q> State<Option<Q>>
where
Q: RawState,
{
pub fn none() -> State<Option<Q>> {
State(None)
}
pub fn some(value: Q) -> State<Option<Q>> {
State(Some(value))
}
pub fn is_none(&self) -> bool {
self.get().is_none()
}
pub fn is_some(&self) -> bool {
self.get().is_some()
}
}
impl<Q> AsRef<Q> for State<Q>
where
Q: RawState,
{
fn as_ref(&self) -> &Q {
self.get()
}
}
impl<Q> AsMut<Q> for State<Q>
where
Q: RawState,
{
fn as_mut(&mut self) -> &mut Q {
self.get_mut()
}
}
impl<Q> core::borrow::Borrow<Q> for State<Q>
where
Q: RawState,
{
fn borrow(&self) -> &Q {
self.get()
}
}
impl<Q> core::borrow::BorrowMut<Q> for State<Q>
where
Q: RawState,
{
fn borrow_mut(&mut self) -> &mut Q {
self.get_mut()
}
}
impl<Q> core::ops::Deref for State<Q>
where
Q: RawState,
{
type Target = Q;
fn deref(&self) -> &Self::Target {
self.get()
}
}
impl<Q> core::ops::DerefMut for State<Q>
where
Q: RawState,
{
fn deref_mut(&mut self) -> &mut Self::Target {
self.get_mut()
}
}
impl<Q> From<Q> for State<Q>
where
Q: RawState,
{
fn from(from: Q) -> Self {
State(from)
}
}
impl<Q> PartialEq<Q> for State<Q>
where
Q: RawState + PartialEq,
{
fn eq(&self, other: &Q) -> bool {
self.get() == other
}
}
impl<'a, Q> PartialEq<&'a Q> for State<Q>
where
Q: RawState + PartialEq,
{
fn eq(&self, other: &&'a Q) -> bool {
self.get() == *other
}
}
impl<'a, Q> PartialEq<&'a mut Q> for State<Q>
where
Q: RawState + PartialEq,
{
fn eq(&self, other: &&'a mut Q) -> bool {
*self.get() == **other
}
}
impl<Q> PartialOrd<Q> for State<Q>
where
Q: RawState + PartialOrd,
{
fn partial_cmp(&self, other: &Q) -> Option<core::cmp::Ordering> {
self.get().partial_cmp(other)
}
}
contained::fmt_wrapper! {
impl State<Q> {
Binary,
Debug,
Display,
LowerExp,
UpperExp,
LowerHex,
UpperHex,
Octal,
Pointer,
}
}