deref_owned 0.5.0

Smart pointer owning its pointee and generalization of std::borrow::Cow
Documentation

deref_owned

This crate provides a smart pointer Owned, which points to a value that can be borrowed from an owned inner value. It's similar to Cow, except that it's always owning a value.

Moreover, a trait GenericCow is provided, which allows conversion from certain pointers into an owned value though an .into_owned() method. The trait GenericCow is implemented for:

  • &'a B where B: ToOwned
  • Cow<'a, B> where B: ToOwned
  • Owned<'a, B, O> where O: Borrow<B>

Here

  • B: ?Sized is the borrowed type (and also the type of the pointer target) and
  • O: Borrow<B> is an owned type.

Changelog

  • 2022-07-01: Version 0.5.0
    • A lifetime and type argument for the borrowed type has been added to Owned, which now contains a PhantomData of a reference to the borrowed type. This makes OwnedRef superfluous, which has been removed.
    • IntoOwned has been renamed to GenericCow.
  • 2022-06-30: Version 0.4.0
    • Removed implementations of IntoOwned for Box<T>, Vec<T>, and String
    • New wrapper type OwnedRef<T>
  • 2022-06-28: Version 0.3.0
    • Added implementations of IntoOwned for Box<T> (where T: ?Sized), Vec<T>, and String, with IntoOwned::Owned being set to Self (replaces previous implementation for Box<T>)
  • 2022-06-27: Version 0.2.0
    • Some more trait implementations (AsRef, AsMut, Borrow, BorrowMut, and Display) have been added for Owned (and Debug::fmt's output is transparent now)
    • Deref is now a supertrait of IntoOwned and IntoOwned::Owned must implement Borrow<<Self as Deref>::Target>
  • 2022-06-26: Version 0.1.0
    • Initial release