Obtaining ownership.
You can add ownership as a dependency with the following command:
$ cargo add ownershipOr by directly specifying it in the configuration like so:
[dependencies]
ownership = "0.4.0"Alternatively, you can add it directly from the source:
[dependencies.ownership]
git = "https://github.com/nekitdev/ownership.git"One of the main ideas of this crate is to allow going from 'a to 'static via switching
to owned types (which is usually done through the ToOwned trait).
This is especially useful when working with Cow<'_, T>, as the implementation of IntoOwned
for Cow<'_, T> will result in Cow<'static, T>.
The derive feature allows one to derive the IntoOwned trait for custom types.
Firstly, enable the derive feature either through the console:
$ cargo add ownership --features deriveOr by specifying it in the configuration like so:
[dependencies.ownership]
version = "0.4.0"
features = ["derive"]And then the IntoOwned trait can be derived, for instance:
use std::borrow::Cow;
use ownership::IntoOwned;
#[derive(IntoOwned)]
pub struct Item<'i, T> {
pub name: Cow<'i, str>,
pub value: T,
}This code will generate the following implementation:
impl<'i, T: IntoOwned> IntoOwned for Item<'i, T> {
type Owned = Item<'static, <T as IntoOwned>::Owned>;
fn into_owned(self) -> Self::Owned {
Self::Owned {
name: IntoOwned::into_owned(self.name),
value: IntoOwned::into_owned(self.value),
}
}
}Then one can "lift" Item<'_, T> to Item<'static, <T as IntoOwned>::Owned> by calling
the into_owned method.
You can find the documentation here.
If you need support with the library, you can send an email.
You can find the changelog here.
You can find the Security Policy of ownership here.
If you are interested in contributing to ownership, make sure to take a look at the
Contributing Guide, as well as the Code of Conduct.
ownership is licensed under the MIT License terms. See License for details.