Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make memory and vector trait bounds publicly nameable #762

Merged
merged 8 commits into from
Mar 25, 2021
Merged

Conversation

dtolnay
Copy link
Owner

@dtolnay dtolnay commented Mar 25, 2021

These trait bounds enable manipulating UniquePtr, SharedPtr, and CxxVector inside of generic code.

Example:

use cxx::memory::{UniquePtr, UniquePtrTarget};
use std::fmt::Display;

pub fn take_generic_ptr<T>(ptr: UniquePtr<T>)
where
    T: UniquePtrTarget + Display,
{
    println!("the unique_ptr points to: {}", *ptr);
}

Writing the same generic function without a UniquePtrTarget trait bound would not compile.

Closes #685.

@dtolnay dtolnay merged commit b90097b into master Mar 25, 2021
@dtolnay dtolnay deleted the traits branch March 25, 2021 06:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant