Skip to content

Repository files navigation

ownership

License Version Downloads Documentation Test

Obtaining ownership.

Installation

cargo

You can add ownership as a dependency with the following command:

$ cargo add ownership

Or 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"

Usage

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>.

Derive

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 derive

Or 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.

Documentation

You can find the documentation here.

Support

If you need support with the library, you can send an email.

Changelog

You can find the changelog here.

Security Policy

You can find the Security Policy of ownership here.

Contributing

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.

License

ownership is licensed under the MIT License terms. See License for details.

About

Obtaining ownership.

Resources

Code of conduct

Contributing

Security policy

Stars

2 stars

Watchers

0 watching

Forks

Releases

Sponsor this project

Packages

Used by

Contributors

Languages