use crate::octave::Octave;
impl<T> Octave<T> {
pub const fn new(octave: T) -> Self {
Octave(octave)
}
pub fn create<F>(f: F) -> Self
where
F: FnOnce() -> T,
{
Octave(f())
}
pub fn one() -> Self
where
T: num_traits::One,
{
Octave::create(T::one)
}
pub fn zero() -> Self
where
T: num_traits::Zero,
{
Octave::create(T::zero)
}
pub const fn as_ptr(&self) -> *const T {
core::ptr::from_ref(&self.0)
}
pub const fn as_mut_ptr(&mut self) -> *mut T {
core::ptr::from_mut(&mut self.0)
}
#[inline]
pub fn value(self) -> T {
self.0
}
pub const fn get(&self) -> &T {
&self.0
}
pub const fn get_mut(&mut self) -> &mut T {
&mut self.0
}
pub fn map<U, F>(self, f: F) -> Octave<U>
where
F: FnOnce(T) -> U,
{
Octave(f(self.0))
}
pub const fn replace(&mut self, index: T) -> T {
core::mem::replace(self.get_mut(), index)
}
pub fn set(&mut self, index: T) -> &mut Self {
*self.get_mut() = index;
self
}
pub const fn swap(&mut self, other: &mut Self) {
core::mem::swap(self.get_mut(), other.get_mut());
}
pub fn with<U>(self, other: U) -> Octave<U> {
Octave(other)
}
pub fn take(&mut self) -> T
where
T: Default,
{
core::mem::take(self.get_mut())
}
pub const fn view(&self) -> Octave<&T> {
Octave(self.get())
}
pub fn view_mut(&mut self) -> Octave<&mut T> {
Octave(self.get_mut())
}
}