[−][src]Struct borrow_as::LifeRef
Container for value which remains valid over specified lifetime.
Implementations
impl<'a, T: ?Sized> LifeRef<'a, (Ref<T>,)>
[src]
pub fn wrap_ref(r: &'a T) -> Self
[src]
Wraps immutable reference with inner value represented as 1-tuple for chaining with other methods.
Example
let s = String::from("Referenced"); let r = borrow_as::LifeRef::wrap_ref(&s[..3]); assert_eq!(r.0, "Ref");
impl<'a, T: ?Sized> LifeRef<'a, (Mut<T>,)>
[src]
pub fn wrap_mut(r: &'a mut T) -> Self
[src]
Wraps mutable reference with inner value represented as 1-tuple for chaining with other methods.
Example
let mut v = vec![1, 2, 3]; let r_mut = borrow_as::LifeRef::wrap_mut(v.as_mut_slice()); let v_mut = r_mut.0.as_slice_of_cells(); v_mut[2].set(4); assert_eq!(v, [1, 2, 4]);
impl<'a, T> LifeRef<'a, T>
[src]
pub fn wrap_life(self) -> LifeRef<'a, (T,)>
[src]
Wraps inner value into 1-tuple for chaining with other methods.
Example
let u = borrow_as::LifeRef::from(true); assert!(*u); let uu = u.wrap_life(); assert!(uu.0);
pub fn add_ref<U: ?Sized>(self, r: &'a U) -> LifeRef<'a, T::Output> where
T: Append<Ref<U>>,
U: 'a,
[src]
T: Append<Ref<U>>,
U: 'a,
Extends inner tuple by one element which represents passed immutable reference. Supports extending up to 16 elements.
Example
let t = (0, 1); let s = String::from("Referenced"); let r = borrow_as::LifeRef::wrap_ref(&t).add_ref(&s[..3]).add_ref(&42); assert_eq!(r.0, &t); assert_eq!(r.1, "Ref"); assert_eq!(r.2, &42);
pub fn add_mut<U: ?Sized>(self, r: &'a mut U) -> LifeRef<'a, T::Output> where
T: Append<Mut<U>>,
U: 'a,
[src]
T: Append<Mut<U>>,
U: 'a,
Extends inner tuple by one element which represents passed mutable reference. Supports extending up to 16 elements.
Example
let mut t = (0, 1); let mut s = String::from("Unaltered"); let r = borrow_as::LifeRef::wrap_mut(&mut t).add_mut(&mut s); let (y, x) = r.0.get(); r.0.set((x, y)); let mut r1 = r.1.take(); r1.replace_range(..3, "A"); r.1.set(r1); assert_eq!(t, (1, 0)); assert_eq!(s, "Altered");
pub fn add_life<'b, U>(self, other: LifeRef<'b, U>) -> LifeRef<'a, T::Output> where
T: Append<U>,
'b: 'a,
[src]
T: Append<U>,
'b: 'a,
Extends inner tuple with extracted value from another LifeRef
.
Note: other
can't outlive self
and its lifetime will be shortened accordingly.
Example
use borrow_as::LifeRef as Life; struct A; struct B; struct C; let a = Life::from(A).wrap_life(); let b = Life::from(B); let c = Life::from(C); let ab = a.add_life(b).wrap_life(); let abc: Life<'_, ((A, B), C)> = ab.add_life(c);
pub fn map_life<U>(self, f: impl Fn(T) -> U) -> LifeRef<'a, U>
[src]
Converts wrapped value from one type to another.
Example
use borrow_as::*; struct Test { x: Mut<String>, y: Ref<i32>, z: Mut<bool>, } let int = 42; let mut string = String::from("Unaltered"); let mut flag = false; let test = LifeRef:: wrap_mut(&mut string) .add_ref(&int) .add_mut(&mut flag) .map_life(|(x, y, z)| Test { x, y, z }); let mut x = test.x.take(); x.replace_range(..3, "A"); test.x.set(x); assert_eq!(test.y, &42); test.z.set(!test.z.get()); assert_eq!(string, "Altered"); assert!(flag);
Trait Implementations
impl<T, '_> Borrow<T> for LifeRef<'_, T>
[src]
impl<'a, T: Clone> Clone for LifeRef<'a, T>
[src]
impl<'a, T: Copy> Copy for LifeRef<'a, T>
[src]
impl<'a, T: Debug> Debug for LifeRef<'a, T>
[src]
impl<'a, T: Default> Default for LifeRef<'a, T>
[src]
impl<'a, T> Deref for LifeRef<'a, T>
[src]
impl<'a, T: Eq> Eq for LifeRef<'a, T>
[src]
impl<T, '_> From<T> for LifeRef<'_, T>
[src]
impl<'a, T: Hash> Hash for LifeRef<'a, T>
[src]
pub fn hash<__H: Hasher>(&self, state: &mut __H)
[src]
pub fn hash_slice<H>(data: &[Self], state: &mut H) where
H: Hasher,
1.3.0[src]
H: Hasher,
impl<'a, T: Ord> Ord for LifeRef<'a, T>
[src]
pub fn cmp(&self, other: &LifeRef<'a, T>) -> Ordering
[src]
#[must_use]pub fn max(self, other: Self) -> Self
1.21.0[src]
#[must_use]pub fn min(self, other: Self) -> Self
1.21.0[src]
#[must_use]pub fn clamp(self, min: Self, max: Self) -> Self
1.50.0[src]
impl<'a, T: PartialEq> PartialEq<LifeRef<'a, T>> for LifeRef<'a, T>
[src]
pub fn eq(&self, other: &LifeRef<'a, T>) -> bool
[src]
pub fn ne(&self, other: &LifeRef<'a, T>) -> bool
[src]
impl<'a, T: PartialOrd> PartialOrd<LifeRef<'a, T>> for LifeRef<'a, T>
[src]
pub fn partial_cmp(&self, other: &LifeRef<'a, T>) -> Option<Ordering>
[src]
pub fn lt(&self, other: &LifeRef<'a, T>) -> bool
[src]
pub fn le(&self, other: &LifeRef<'a, T>) -> bool
[src]
pub fn gt(&self, other: &LifeRef<'a, T>) -> bool
[src]
pub fn ge(&self, other: &LifeRef<'a, T>) -> bool
[src]
impl<'a, T> StructuralEq for LifeRef<'a, T>
[src]
impl<'a, T> StructuralPartialEq for LifeRef<'a, T>
[src]
Auto Trait Implementations
impl<'a, T> RefUnwindSafe for LifeRef<'a, T> where
T: RefUnwindSafe,
T: RefUnwindSafe,
impl<'a, T> Send for LifeRef<'a, T> where
T: Send + Sync,
T: Send + Sync,
impl<'a, T> Sync for LifeRef<'a, T> where
T: Sync,
T: Sync,
impl<'a, T> Unpin for LifeRef<'a, T> where
T: Unpin,
T: Unpin,
impl<'a, T> UnwindSafe for LifeRef<'a, T> where
T: RefUnwindSafe + UnwindSafe,
T: RefUnwindSafe + UnwindSafe,
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
pub fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<!> for T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
pub fn to_owned(&self) -> T
[src]
pub fn clone_into(&self, target: &mut T)
[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,