Struct supercow::Supercow [] [src]

pub struct Supercow<'a, OWNED, BORROWED: ?Sized = OWNED, SHARED = Box<DefaultFeatures<'static> + 'static>, STORAGE = BoxedStorage, PTR = *const BORROWED> where BORROWED: 'a, *const BORROWED: PointerFirstRef, STORAGE: OwnedStorage<OWNED, SHARED>, PTR: PtrWrite<BORROWED> { /* fields omitted */ }

The actual generic reference type.

See the module documentation for most of the details.

Most of the generics requirements you don't need to pay too much attention to if you aren't making custom SHARED or STORAGE types, etc. In general:

Methods

impl<'a, OWNED, BORROWED: ?Sized, SHARED, STORAGE, PTR> Supercow<'a, OWNED, BORROWED, SHARED, STORAGE, PTR> where BORROWED: 'a, *const BORROWED: PointerFirstRef, STORAGE: OwnedStorage<OWNED, SHARED>, PTR: PtrWrite<BORROWED>
[src]

Creates a new Supercow which owns the given value.

This can create a Supercow with a 'static lifetime.

Creates a new Supercow which borrows the given value.

Creates a new Supercow using the given shared reference.

The reference must be convertible to SHARED via SharedFrom.

If this is non-owned, clone this and return it.

Otherwise, return None.

Example

use supercow::Supercow;

struct SomeNonCloneThing;

let owned: Supercow<SomeNonCloneThing> = SomeNonCloneThing.into();
assert!(Supercow::clone_non_owned(&owned).is_none());

let the_thing = SomeNonCloneThing;
let borrowed: Supercow<SomeNonCloneThing> = (&the_thing).into();
let also_borrowed = Supercow::clone_non_owned(&borrowed).unwrap();Run

Logically clone this without needing to clone OWNED.

If this Supercow is in owned mode, the owned value is first moved into a new shared reference so that OWNED does not need to be cloned.

Example

use supercow::Supercow;

struct NonCloneType(u32);

let mut first: Supercow<NonCloneType> =
  Supercow::owned(NonCloneType(42));
let second = Supercow::share(&mut first);

assert_eq!(42, (*first).0);
assert_eq!(42, (*second).0);Run

If this is borrowed, return the underlying reference with the original lifetime. Otherwise, return None.

The returned reference has a lifetime independent of this.

This can be used to bridge between Supercow APIs and mundane reference APIs without needing to restrict the lifetime to the Supercow, but as a result is only available if the contained reference is actually independent.

Example

use std::sync::Arc;

use supercow::Supercow;

let forty_two: u32 = 42;

let borrowed: Supercow<u32> = (&forty_two).into();
assert_eq!(Some(&forty_two), Supercow::extract_ref(&borrowed));

let owned: Supercow<u32> = forty_two.into();
assert_eq!(None, Supercow::extract_ref(&owned));

let shared: Supercow<u32> = Arc::new(forty_two).into();
assert_eq!(None, Supercow::extract_ref(&shared));Run

Takes ownership of the underling value if needed, then returns it, consuming self.

Returns a (indirect) mutable reference to an underlying owned value.

If this Supercow does not currently own the value, it takes ownership. A Ref is then returned which allows accessing the mutable owned value directly.

Leak Safety

If the returned Ref is released without its destructor being run, the behaviour of the Supercow is unspecified (but does not result in memory unsafety).

If this is borrowed, clone the inner value so that the new Supercow has a 'static lifetime.

If the inner value is owned or shared, this simply returns the input unchanged.

Example

use supercow::Supercow;

let s = {
  let forty_two = 42u32;
  let by_ref: Supercow<u32> = Supercow::borrowed(&forty_two);
  // We can't return `by_ref` because it holds a reference to
  // `forty_two`. However, we can change that lifetime parameter
  // to `'static` and then move that out of the block.
  let by_val: Supercow<'static, u32> = Supercow::unborrow(by_ref);
  by_val
};
assert_eq!(42, *s);Run

Takes ownership of the underlying value, so that this Supercow has a 'static lifetime.

This may also change the SHARED type parameter arbitrarily.

Example

use supercow::Supercow;

let s = {
  let forty_two = 42u32;
  let by_ref: Supercow<u32> = Supercow::borrowed(&forty_two);
  // We can't return `by_ref` because it holds a reference to
  // `forty_two`. However, we can change that lifetime parameter
  // to `'static` and then move that out of the block.
  let by_val: Supercow<'static, u32> =
    Supercow::take_ownership(by_ref);
  by_val
};
assert_eq!(42, *s);Run

Converts this Supercow into a Phantomcow.

Trait Implementations

impl<'a, OWNED, BORROWED: ?Sized, SHARED, STORAGE, PTR> Drop for Supercow<'a, OWNED, BORROWED, SHARED, STORAGE, PTR> where BORROWED: 'a, *const BORROWED: PointerFirstRef, STORAGE: OwnedStorage<OWNED, SHARED>, PTR: PtrWrite<BORROWED>
[src]

A method called when the value goes out of scope. Read more

impl<'a, OWNED, BORROWED: ?Sized, SHARED, STORAGE, PTR> Send for Supercow<'a, OWNED, BORROWED, SHARED, STORAGE, PTR> where BORROWED: 'a, *const BORROWED: PointerFirstRef, STORAGE: OwnedStorage<OWNED, SHARED>, PTR: PtrWrite<BORROWED>, OWNED: Send, &'a BORROWED: Send, SHARED: Send, STORAGE: Send
[src]

impl<'a, OWNED, BORROWED: ?Sized, SHARED, STORAGE, PTR> Sync for Supercow<'a, OWNED, BORROWED, SHARED, STORAGE, PTR> where BORROWED: 'a, *const BORROWED: PointerFirstRef, STORAGE: OwnedStorage<OWNED, SHARED>, PTR: PtrWrite<BORROWED>, OWNED: Sync, &'a BORROWED: Sync, SHARED: Sync, STORAGE: Sync
[src]

impl<'a, OWNED, BORROWED: ?Sized, SHARED, STORAGE, PTR> Deref for Supercow<'a, OWNED, BORROWED, SHARED, STORAGE, PTR> where BORROWED: 'a, *const BORROWED: PointerFirstRef, STORAGE: OwnedStorage<OWNED, SHARED>, PTR: PtrWrite<BORROWED>, PTR: PtrRead<BORROWED>
[src]

The resulting type after dereferencing

The method called to dereference a value

impl<'a, OWNED, BORROWED: ?Sized, SHARED, STORAGE, PTR> Borrow<BORROWED> for Supercow<'a, OWNED, BORROWED, SHARED, STORAGE, PTR> where BORROWED: 'a, *const BORROWED: PointerFirstRef, STORAGE: OwnedStorage<OWNED, SHARED>, PTR: PtrWrite<BORROWED>, PTR: PtrRead<BORROWED>
[src]

Immutably borrows from an owned value. Read more

impl<'a, OWNED, BORROWED: ?Sized, SHARED, STORAGE, PTR> AsRef<BORROWED> for Supercow<'a, OWNED, BORROWED, SHARED, STORAGE, PTR> where BORROWED: 'a, *const BORROWED: PointerFirstRef, STORAGE: OwnedStorage<OWNED, SHARED>, PTR: PtrWrite<BORROWED>, PTR: PtrRead<BORROWED>
[src]

Performs the conversion.

impl<'a, OWNED, BORROWED: ?Sized, SHARED, STORAGE, PTR> Clone for Supercow<'a, OWNED, BORROWED, SHARED, STORAGE, PTR> where BORROWED: 'a, *const BORROWED: PointerFirstRef, STORAGE: OwnedStorage<OWNED, SHARED>, PTR: PtrWrite<BORROWED>, OWNED: Clone + SafeBorrow<BORROWED>, SHARED: Clone
[src]

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

impl<'a, OWNED, BORROWED: ?Sized, SHARED, STORAGE, PTR> From<OWNED> for Supercow<'a, OWNED, BORROWED, SHARED, STORAGE, PTR> where BORROWED: 'a, *const BORROWED: PointerFirstRef, STORAGE: OwnedStorage<OWNED, SHARED>, PTR: PtrWrite<BORROWED>, OWNED: SafeBorrow<BORROWED>
[src]

Performs the conversion.

impl<'a, OWNED, BORROWED: ?Sized, SHARED, STORAGE, PTR> From<&'a OWNED> for Supercow<'a, OWNED, BORROWED, SHARED, STORAGE, PTR> where BORROWED: 'a, *const BORROWED: PointerFirstRef, STORAGE: OwnedStorage<OWNED, SHARED>, PTR: PtrWrite<BORROWED>, OWNED: Borrow<BORROWED>
[src]

Performs the conversion.

impl<'a, OWNED, SHARED, STORAGE> From<Rc<OWNED>> for Supercow<'a, OWNED, OWNED, SHARED, STORAGE> where SHARED: SharedFrom<Rc<OWNED>>, STORAGE: OwnedStorage<OWNED, SHARED>, OWNED: 'a, *const OWNED: PointerFirstRef
[src]

Performs the conversion.

impl<'a, OWNED, SHARED, STORAGE> From<Arc<OWNED>> for Supercow<'a, OWNED, OWNED, SHARED, STORAGE> where SHARED: SharedFrom<Arc<OWNED>>, STORAGE: OwnedStorage<OWNED, SHARED>, OWNED: 'a, *const OWNED: PointerFirstRef
[src]

Performs the conversion.

impl<'a, OWNED, BORROWED: ?Sized, SHARED, STORAGE, PTR> Binary for Supercow<'a, OWNED, BORROWED, SHARED, STORAGE, PTR> where BORROWED: 'a, *const BORROWED: PointerFirstRef, STORAGE: OwnedStorage<OWNED, SHARED>, PTR: PtrWrite<BORROWED>, BORROWED: Binary, PTR: PtrRead<BORROWED>
[src]

Formats the value using the given formatter.

impl<'a, OWNED, BORROWED: ?Sized, SHARED, STORAGE, PTR> Display for Supercow<'a, OWNED, BORROWED, SHARED, STORAGE, PTR> where BORROWED: 'a, *const BORROWED: PointerFirstRef, STORAGE: OwnedStorage<OWNED, SHARED>, PTR: PtrWrite<BORROWED>, BORROWED: Display, PTR: PtrRead<BORROWED>
[src]

Formats the value using the given formatter.

impl<'a, OWNED, BORROWED: ?Sized, SHARED, STORAGE, PTR> LowerExp for Supercow<'a, OWNED, BORROWED, SHARED, STORAGE, PTR> where BORROWED: 'a, *const BORROWED: PointerFirstRef, STORAGE: OwnedStorage<OWNED, SHARED>, PTR: PtrWrite<BORROWED>, BORROWED: LowerExp, PTR: PtrRead<BORROWED>
[src]

Formats the value using the given formatter.

impl<'a, OWNED, BORROWED: ?Sized, SHARED, STORAGE, PTR> LowerHex for Supercow<'a, OWNED, BORROWED, SHARED, STORAGE, PTR> where BORROWED: 'a, *const BORROWED: PointerFirstRef, STORAGE: OwnedStorage<OWNED, SHARED>, PTR: PtrWrite<BORROWED>, BORROWED: LowerHex, PTR: PtrRead<BORROWED>
[src]

Formats the value using the given formatter.

impl<'a, OWNED, BORROWED: ?Sized, SHARED, STORAGE, PTR> Octal for Supercow<'a, OWNED, BORROWED, SHARED, STORAGE, PTR> where BORROWED: 'a, *const BORROWED: PointerFirstRef, STORAGE: OwnedStorage<OWNED, SHARED>, PTR: PtrWrite<BORROWED>, BORROWED: Octal, PTR: PtrRead<BORROWED>
[src]

Formats the value using the given formatter.

impl<'a, OWNED, BORROWED: ?Sized, SHARED, STORAGE, PTR> Pointer for Supercow<'a, OWNED, BORROWED, SHARED, STORAGE, PTR> where BORROWED: 'a, *const BORROWED: PointerFirstRef, STORAGE: OwnedStorage<OWNED, SHARED>, PTR: PtrWrite<BORROWED>, BORROWED: Pointer, PTR: PtrRead<BORROWED>
[src]

Formats the value using the given formatter.

impl<'a, OWNED, BORROWED: ?Sized, SHARED, STORAGE, PTR> UpperExp for Supercow<'a, OWNED, BORROWED, SHARED, STORAGE, PTR> where BORROWED: 'a, *const BORROWED: PointerFirstRef, STORAGE: OwnedStorage<OWNED, SHARED>, PTR: PtrWrite<BORROWED>, BORROWED: UpperExp, PTR: PtrRead<BORROWED>
[src]

Formats the value using the given formatter.

impl<'a, OWNED, BORROWED: ?Sized, SHARED, STORAGE, PTR> UpperHex for Supercow<'a, OWNED, BORROWED, SHARED, STORAGE, PTR> where BORROWED: 'a, *const BORROWED: PointerFirstRef, STORAGE: OwnedStorage<OWNED, SHARED>, PTR: PtrWrite<BORROWED>, BORROWED: UpperHex, PTR: PtrRead<BORROWED>
[src]

Formats the value using the given formatter.

impl<'a, OWNED, BORROWED: ?Sized, SHARED, STORAGE> Debug for Supercow<'a, OWNED, BORROWED, SHARED, STORAGE, ()> where BORROWED: 'a, *const BORROWED: PointerFirstRef, STORAGE: OwnedStorage<OWNED, SHARED>
[src]

Formats the value using the given formatter.

impl<'a, OWNED, BORROWED: ?Sized, SHARED, STORAGE> Debug for Supercow<'a, OWNED, BORROWED, SHARED, STORAGE, *const BORROWED> where BORROWED: Debug + 'a, *const BORROWED: PointerFirstRef, STORAGE: OwnedStorage<OWNED, SHARED>
[src]

Formats the value using the given formatter.

impl<'a, T, OWNED, BORROWED: ?Sized, SHARED, STORAGE, PTR> PartialEq<T> for Supercow<'a, OWNED, BORROWED, SHARED, STORAGE, PTR> where BORROWED: 'a, *const BORROWED: PointerFirstRef, STORAGE: OwnedStorage<OWNED, SHARED>, PTR: PtrWrite<BORROWED>, T: Borrow<BORROWED>, BORROWED: PartialEq<BORROWED>, PTR: PtrRead<BORROWED>
[src]

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

impl<'a, OWNED, BORROWED: ?Sized, SHARED, STORAGE, PTR> Eq for Supercow<'a, OWNED, BORROWED, SHARED, STORAGE, PTR> where BORROWED: 'a, *const BORROWED: PointerFirstRef, STORAGE: OwnedStorage<OWNED, SHARED>, PTR: PtrWrite<BORROWED>, BORROWED: Eq, PTR: PtrRead<BORROWED>
[src]

impl<'a, T, OWNED, BORROWED: ?Sized, SHARED, STORAGE, PTR> PartialOrd<T> for Supercow<'a, OWNED, BORROWED, SHARED, STORAGE, PTR> where BORROWED: 'a, *const BORROWED: PointerFirstRef, STORAGE: OwnedStorage<OWNED, SHARED>, PTR: PtrWrite<BORROWED>, T: Borrow<BORROWED>, BORROWED: PartialOrd<BORROWED>, PTR: PtrRead<BORROWED>
[src]

This method returns an ordering between self and other values if one exists. Read more

This method tests less than (for self and other) and is used by the < operator. Read more

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more

This method tests greater than (for self and other) and is used by the > operator. Read more

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more

impl<'a, OWNED, BORROWED: ?Sized, SHARED, STORAGE, PTR> Ord for Supercow<'a, OWNED, BORROWED, SHARED, STORAGE, PTR> where BORROWED: 'a, *const BORROWED: PointerFirstRef, STORAGE: OwnedStorage<OWNED, SHARED>, PTR: PtrWrite<BORROWED>, BORROWED: Ord, PTR: PtrRead<BORROWED>
[src]

This method returns an Ordering between self and other. Read more

impl<'a, OWNED, BORROWED: ?Sized, SHARED, STORAGE, PTR> Hash for Supercow<'a, OWNED, BORROWED, SHARED, STORAGE, PTR> where BORROWED: 'a, *const BORROWED: PointerFirstRef, STORAGE: OwnedStorage<OWNED, SHARED>, PTR: PtrWrite<BORROWED>, BORROWED: Hash, PTR: PtrRead<BORROWED>
[src]

Feeds this value into the state given, updating the hasher as necessary.

Feeds a slice of this type into the state provided.