|
@@ -12,32 +12,37 @@ use std::{
|
|
macro_rules! read_impls {
|
|
macro_rules! read_impls {
|
|
($ty:ident, $bound:path) => {
|
|
($ty:ident, $bound:path) => {
|
|
impl<T: Default + 'static, S: $bound> Default for $ty<T, S> {
|
|
impl<T: Default + 'static, S: $bound> Default for $ty<T, S> {
|
|
|
|
+ #[track_caller]
|
|
fn default() -> Self {
|
|
fn default() -> Self {
|
|
Self::new_maybe_sync(Default::default())
|
|
Self::new_maybe_sync(Default::default())
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
impl<T, S: $bound> std::clone::Clone for $ty<T, S> {
|
|
impl<T, S: $bound> std::clone::Clone for $ty<T, S> {
|
|
|
|
+ #[track_caller]
|
|
fn clone(&self) -> Self {
|
|
fn clone(&self) -> Self {
|
|
*self
|
|
*self
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
- impl<T, S: $bound + Copy> Copy for $ty<T, S> {}
|
|
|
|
|
|
+ impl<T, S: $bound> Copy for $ty<T, S> {}
|
|
|
|
|
|
impl<T: Display + 'static, S: $bound> Display for $ty<T, S> {
|
|
impl<T: Display + 'static, S: $bound> Display for $ty<T, S> {
|
|
|
|
+ #[track_caller]
|
|
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
|
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
|
self.with(|v| Display::fmt(v, f))
|
|
self.with(|v| Display::fmt(v, f))
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
impl<T: Debug + 'static, S: $bound> Debug for $ty<T, S> {
|
|
impl<T: Debug + 'static, S: $bound> Debug for $ty<T, S> {
|
|
|
|
+ #[track_caller]
|
|
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
|
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
|
self.with(|v| Debug::fmt(v, f))
|
|
self.with(|v| Debug::fmt(v, f))
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
impl<T: PartialEq + 'static, S: $bound> PartialEq<T> for $ty<T, S> {
|
|
impl<T: PartialEq + 'static, S: $bound> PartialEq<T> for $ty<T, S> {
|
|
|
|
+ #[track_caller]
|
|
fn eq(&self, other: &T) -> bool {
|
|
fn eq(&self, other: &T) -> bool {
|
|
self.with(|v| *v == *other)
|
|
self.with(|v| *v == *other)
|
|
}
|
|
}
|
|
@@ -50,18 +55,21 @@ macro_rules! write_impls {
|
|
impl<T: Add<Output = T> + Copy + 'static, S: $bound> std::ops::Add<T> for $ty<T, S> {
|
|
impl<T: Add<Output = T> + Copy + 'static, S: $bound> std::ops::Add<T> for $ty<T, S> {
|
|
type Output = T;
|
|
type Output = T;
|
|
|
|
|
|
|
|
+ #[track_caller]
|
|
fn add(self, rhs: T) -> Self::Output {
|
|
fn add(self, rhs: T) -> Self::Output {
|
|
self.with(|v| *v + rhs)
|
|
self.with(|v| *v + rhs)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
impl<T: Add<Output = T> + Copy + 'static, S: $bound> std::ops::AddAssign<T> for $ty<T, S> {
|
|
impl<T: Add<Output = T> + Copy + 'static, S: $bound> std::ops::AddAssign<T> for $ty<T, S> {
|
|
|
|
+ #[track_caller]
|
|
fn add_assign(&mut self, rhs: T) {
|
|
fn add_assign(&mut self, rhs: T) {
|
|
self.with_mut(|v| *v = *v + rhs)
|
|
self.with_mut(|v| *v = *v + rhs)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
impl<T: Sub<Output = T> + Copy + 'static, S: $bound> std::ops::SubAssign<T> for $ty<T, S> {
|
|
impl<T: Sub<Output = T> + Copy + 'static, S: $bound> std::ops::SubAssign<T> for $ty<T, S> {
|
|
|
|
+ #[track_caller]
|
|
fn sub_assign(&mut self, rhs: T) {
|
|
fn sub_assign(&mut self, rhs: T) {
|
|
self.with_mut(|v| *v = *v - rhs)
|
|
self.with_mut(|v| *v = *v - rhs)
|
|
}
|
|
}
|
|
@@ -70,12 +78,14 @@ macro_rules! write_impls {
|
|
impl<T: Sub<Output = T> + Copy + 'static, S: $bound> std::ops::Sub<T> for $ty<T, S> {
|
|
impl<T: Sub<Output = T> + Copy + 'static, S: $bound> std::ops::Sub<T> for $ty<T, S> {
|
|
type Output = T;
|
|
type Output = T;
|
|
|
|
|
|
|
|
+ #[track_caller]
|
|
fn sub(self, rhs: T) -> Self::Output {
|
|
fn sub(self, rhs: T) -> Self::Output {
|
|
self.with(|v| *v - rhs)
|
|
self.with(|v| *v - rhs)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
impl<T: Mul<Output = T> + Copy + 'static, S: $bound> std::ops::MulAssign<T> for $ty<T, S> {
|
|
impl<T: Mul<Output = T> + Copy + 'static, S: $bound> std::ops::MulAssign<T> for $ty<T, S> {
|
|
|
|
+ #[track_caller]
|
|
fn mul_assign(&mut self, rhs: T) {
|
|
fn mul_assign(&mut self, rhs: T) {
|
|
self.with_mut(|v| *v = *v * rhs)
|
|
self.with_mut(|v| *v = *v * rhs)
|
|
}
|
|
}
|
|
@@ -84,12 +94,14 @@ macro_rules! write_impls {
|
|
impl<T: Mul<Output = T> + Copy + 'static, S: $bound> std::ops::Mul<T> for $ty<T, S> {
|
|
impl<T: Mul<Output = T> + Copy + 'static, S: $bound> std::ops::Mul<T> for $ty<T, S> {
|
|
type Output = T;
|
|
type Output = T;
|
|
|
|
|
|
|
|
+ #[track_caller]
|
|
fn mul(self, rhs: T) -> Self::Output {
|
|
fn mul(self, rhs: T) -> Self::Output {
|
|
self.with(|v| *v * rhs)
|
|
self.with(|v| *v * rhs)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
impl<T: Div<Output = T> + Copy + 'static, S: $bound> std::ops::DivAssign<T> for $ty<T, S> {
|
|
impl<T: Div<Output = T> + Copy + 'static, S: $bound> std::ops::DivAssign<T> for $ty<T, S> {
|
|
|
|
+ #[track_caller]
|
|
fn div_assign(&mut self, rhs: T) {
|
|
fn div_assign(&mut self, rhs: T) {
|
|
self.with_mut(|v| *v = *v / rhs)
|
|
self.with_mut(|v| *v = *v / rhs)
|
|
}
|
|
}
|
|
@@ -98,6 +110,7 @@ macro_rules! write_impls {
|
|
impl<T: Div<Output = T> + Copy + 'static, S: $bound> std::ops::Div<T> for $ty<T, S> {
|
|
impl<T: Div<Output = T> + Copy + 'static, S: $bound> std::ops::Div<T> for $ty<T, S> {
|
|
type Output = T;
|
|
type Output = T;
|
|
|
|
|
|
|
|
+ #[track_caller]
|
|
fn div(self, rhs: T) -> Self::Output {
|
|
fn div(self, rhs: T) -> Self::Output {
|
|
self.with(|v| *v / rhs)
|
|
self.with(|v| *v / rhs)
|
|
}
|
|
}
|
|
@@ -105,51 +118,61 @@ macro_rules! write_impls {
|
|
|
|
|
|
impl<T: 'static, S: $vec_bound> $ty<Vec<T>, S> {
|
|
impl<T: 'static, S: $vec_bound> $ty<Vec<T>, S> {
|
|
/// Pushes a new value to the end of the vector.
|
|
/// Pushes a new value to the end of the vector.
|
|
|
|
+ #[track_caller]
|
|
pub fn push(&self, value: T) {
|
|
pub fn push(&self, value: T) {
|
|
self.with_mut(|v| v.push(value))
|
|
self.with_mut(|v| v.push(value))
|
|
}
|
|
}
|
|
|
|
|
|
/// Pops the last value from the vector.
|
|
/// Pops the last value from the vector.
|
|
|
|
+ #[track_caller]
|
|
pub fn pop(&self) -> Option<T> {
|
|
pub fn pop(&self) -> Option<T> {
|
|
self.with_mut(|v| v.pop())
|
|
self.with_mut(|v| v.pop())
|
|
}
|
|
}
|
|
|
|
|
|
/// Inserts a new value at the given index.
|
|
/// Inserts a new value at the given index.
|
|
|
|
+ #[track_caller]
|
|
pub fn insert(&self, index: usize, value: T) {
|
|
pub fn insert(&self, index: usize, value: T) {
|
|
self.with_mut(|v| v.insert(index, value))
|
|
self.with_mut(|v| v.insert(index, value))
|
|
}
|
|
}
|
|
|
|
|
|
/// Removes the value at the given index.
|
|
/// Removes the value at the given index.
|
|
|
|
+ #[track_caller]
|
|
pub fn remove(&self, index: usize) -> T {
|
|
pub fn remove(&self, index: usize) -> T {
|
|
self.with_mut(|v| v.remove(index))
|
|
self.with_mut(|v| v.remove(index))
|
|
}
|
|
}
|
|
|
|
|
|
/// Clears the vector, removing all values.
|
|
/// Clears the vector, removing all values.
|
|
|
|
+ #[track_caller]
|
|
pub fn clear(&self) {
|
|
pub fn clear(&self) {
|
|
self.with_mut(|v| v.clear())
|
|
self.with_mut(|v| v.clear())
|
|
}
|
|
}
|
|
|
|
|
|
/// Extends the vector with the given iterator.
|
|
/// Extends the vector with the given iterator.
|
|
|
|
+ #[track_caller]
|
|
pub fn extend(&self, iter: impl IntoIterator<Item = T>) {
|
|
pub fn extend(&self, iter: impl IntoIterator<Item = T>) {
|
|
self.with_mut(|v| v.extend(iter))
|
|
self.with_mut(|v| v.extend(iter))
|
|
}
|
|
}
|
|
|
|
|
|
/// Truncates the vector to the given length.
|
|
/// Truncates the vector to the given length.
|
|
|
|
+ #[track_caller]
|
|
pub fn truncate(&self, len: usize) {
|
|
pub fn truncate(&self, len: usize) {
|
|
self.with_mut(|v| v.truncate(len))
|
|
self.with_mut(|v| v.truncate(len))
|
|
}
|
|
}
|
|
|
|
|
|
/// Swaps two values in the vector.
|
|
/// Swaps two values in the vector.
|
|
|
|
+ #[track_caller]
|
|
pub fn swap_remove(&self, index: usize) -> T {
|
|
pub fn swap_remove(&self, index: usize) -> T {
|
|
self.with_mut(|v| v.swap_remove(index))
|
|
self.with_mut(|v| v.swap_remove(index))
|
|
}
|
|
}
|
|
|
|
|
|
/// Retains only the values that match the given predicate.
|
|
/// Retains only the values that match the given predicate.
|
|
|
|
+ #[track_caller]
|
|
pub fn retain(&self, f: impl FnMut(&T) -> bool) {
|
|
pub fn retain(&self, f: impl FnMut(&T) -> bool) {
|
|
self.with_mut(|v| v.retain(f))
|
|
self.with_mut(|v| v.retain(f))
|
|
}
|
|
}
|
|
|
|
|
|
/// Splits the vector into two at the given index.
|
|
/// Splits the vector into two at the given index.
|
|
|
|
+ #[track_caller]
|
|
pub fn split_off(&self, at: usize) -> Vec<T> {
|
|
pub fn split_off(&self, at: usize) -> Vec<T> {
|
|
self.with_mut(|v| v.split_off(at))
|
|
self.with_mut(|v| v.split_off(at))
|
|
}
|
|
}
|
|
@@ -161,6 +184,7 @@ read_impls!(CopyValue, Storage<T>);
|
|
|
|
|
|
impl<T: 'static, S: Storage<Vec<T>>> CopyValue<Vec<T>, S> {
|
|
impl<T: 'static, S: Storage<Vec<T>>> CopyValue<Vec<T>, S> {
|
|
/// Read a value from the inner vector.
|
|
/// Read a value from the inner vector.
|
|
|
|
+ #[track_caller]
|
|
pub fn get(&self, index: usize) -> Option<<S::Ref as Mappable<Vec<T>>>::Mapped<T>> {
|
|
pub fn get(&self, index: usize) -> Option<<S::Ref as Mappable<Vec<T>>>::Mapped<T>> {
|
|
S::Ref::try_map(self.read(), move |v| v.get(index))
|
|
S::Ref::try_map(self.read(), move |v| v.get(index))
|
|
}
|
|
}
|
|
@@ -168,6 +192,7 @@ impl<T: 'static, S: Storage<Vec<T>>> CopyValue<Vec<T>, S> {
|
|
|
|
|
|
impl<T: 'static, S: Storage<Option<T>>> CopyValue<Option<T>, S> {
|
|
impl<T: 'static, S: Storage<Option<T>>> CopyValue<Option<T>, S> {
|
|
/// Unwraps the inner value and clones it.
|
|
/// Unwraps the inner value and clones it.
|
|
|
|
+ #[track_caller]
|
|
pub fn unwrap(&self) -> T
|
|
pub fn unwrap(&self) -> T
|
|
where
|
|
where
|
|
T: Clone,
|
|
T: Clone,
|
|
@@ -176,6 +201,7 @@ impl<T: 'static, S: Storage<Option<T>>> CopyValue<Option<T>, S> {
|
|
}
|
|
}
|
|
|
|
|
|
/// Attempts to read the inner value of the Option.
|
|
/// Attempts to read the inner value of the Option.
|
|
|
|
+ #[track_caller]
|
|
pub fn as_ref(&self) -> Option<<S::Ref as Mappable<Option<T>>>::Mapped<T>> {
|
|
pub fn as_ref(&self) -> Option<<S::Ref as Mappable<Option<T>>>::Mapped<T>> {
|
|
S::Ref::try_map(self.read(), |v| v.as_ref())
|
|
S::Ref::try_map(self.read(), |v| v.as_ref())
|
|
}
|
|
}
|
|
@@ -185,21 +211,25 @@ write_impls!(CopyValue, Storage<T>, Storage<Vec<T>>);
|
|
|
|
|
|
impl<T: 'static, S: Storage<Option<T>>> CopyValue<Option<T>, S> {
|
|
impl<T: 'static, S: Storage<Option<T>>> CopyValue<Option<T>, S> {
|
|
/// Takes the value out of the Option.
|
|
/// Takes the value out of the Option.
|
|
|
|
+ #[track_caller]
|
|
pub fn take(&self) -> Option<T> {
|
|
pub fn take(&self) -> Option<T> {
|
|
self.with_mut(|v| v.take())
|
|
self.with_mut(|v| v.take())
|
|
}
|
|
}
|
|
|
|
|
|
/// Replace the value in the Option.
|
|
/// Replace the value in the Option.
|
|
|
|
+ #[track_caller]
|
|
pub fn replace(&self, value: T) -> Option<T> {
|
|
pub fn replace(&self, value: T) -> Option<T> {
|
|
self.with_mut(|v| v.replace(value))
|
|
self.with_mut(|v| v.replace(value))
|
|
}
|
|
}
|
|
|
|
|
|
/// Gets the value out of the Option, or inserts the given value if the Option is empty.
|
|
/// Gets the value out of the Option, or inserts the given value if the Option is empty.
|
|
|
|
+ #[track_caller]
|
|
pub fn get_or_insert(&self, default: T) -> <S::Ref as Mappable<Option<T>>>::Mapped<T> {
|
|
pub fn get_or_insert(&self, default: T) -> <S::Ref as Mappable<Option<T>>>::Mapped<T> {
|
|
self.get_or_insert_with(|| default)
|
|
self.get_or_insert_with(|| default)
|
|
}
|
|
}
|
|
|
|
|
|
/// Gets the value out of the Option, or inserts the value returned by the given function if the Option is empty.
|
|
/// Gets the value out of the Option, or inserts the value returned by the given function if the Option is empty.
|
|
|
|
+ #[track_caller]
|
|
pub fn get_or_insert_with(
|
|
pub fn get_or_insert_with(
|
|
&self,
|
|
&self,
|
|
default: impl FnOnce() -> T,
|
|
default: impl FnOnce() -> T,
|