use core::{
borrow::{Borrow, BorrowMut},
iter::once,
str::FromStr,
};
pub mod ops;
pub use ops::{deref, deref_mut, index, index_mut, index_owned};
use crate::{ThisMut, ThisRef, Unpack};
pub fn default<T: Default>() -> T {
Default::default()
}
pub fn unpack<T: Unpack>(this: T) -> T::Output {
this.unpack()
}
pub fn this_ref<'a, T: ThisRef<'a>>(this: T) -> &'a T::Out {
this.this_ref()
}
pub fn this_mut<'a, T: ThisMut<'a>>(this: T) -> &'a mut T::Out {
this.this_mut()
}
pub fn into<T: Into<U>, U>(this: T) -> U {
this.into()
}
pub fn into_iter<T: IntoIterator>(this: T) -> T::IntoIter {
this.into_iter()
}
pub fn try_into<T: TryInto<U>, U>(this: T) -> Result<U, T::Error> {
this.try_into()
}
#[cfg(feature = "std")]
pub fn to_owned<T: ?Sized + ToOwned>(this: &T) -> T::Owned {
this.to_owned()
}
pub fn parse<T: FromStr>(this: &str) -> Result<T, T::Err> {
this.parse()
}
#[cfg(feature = "std")]
pub fn to_string<T: ?Sized + ToString>(this: &T) -> String {
this.to_string()
}
pub fn as_ref<T: ?Sized + AsRef<U>, U>(this: &T) -> &U {
this.as_ref()
}
pub fn as_mut<T: ?Sized + AsMut<U>, U>(this: &mut T) -> &mut U {
this.as_mut()
}
pub fn borrow<T: ?Sized + Borrow<U>, U>(this: &T) -> &U {
this.borrow()
}
pub fn borrow_mut<T: ?Sized + BorrowMut<U>, U>(this: &mut T) -> &mut U {
this.borrow_mut()
}
#[inline]
pub fn copy<T: Copy>(this: &T) -> T {
*this
}
pub fn clone<T: Clone>(this: &T) -> T {
this.clone()
}
pub fn run_ref<T, F>(mut f: F) -> impl FnMut(T) -> T
where F: FnMut(&T),
{
move |this| {
f(&this);
this
}
}
pub fn run_mut<T, F>(mut f: F) -> impl FnMut(T) -> T
where F: FnMut(&mut T),
{
move |mut this| {
f(&mut this);
this
}
}
pub fn extend_to<T, C>(collect: &mut C) -> impl FnMut(T) + '_
where C: Extend<T>,
{
|elem| collect.extend(once(elem))
}
pub fn extend<T, C>(mut collect: C, elem: T) -> C
where C: Extend<T>,
{
collect.extend(once(elem));
collect
}