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

Implement lifetime-free ref and mut casts for unsized type #23

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

zheland
Copy link
Contributor

@zheland zheland commented Jul 3, 2024

The TryCastMutLifetimeFree and TryCastRefLifetimeFree trait implementations have default Sized bound on the T and U generics, which prevents unsized types not defined as static from casiting.

This PR adds ?Sized bound to T and U generics in TryCastMutLifetimeFree and TryCastRefLifetimeFree trait implementation.

For example this makes it possible to specialize slices without restricting the source slice item type to be static:

fn func<T>(slice: &[T]) {
    if let Ok(byte_slice) = cast!(slice, &[u8]) {
        // specialized impl...
    } else {
        // default impl...
    }
}

@sagebind
Copy link
Owner

sagebind commented Jul 4, 2024

Thanks for the idea and working on this! If that's alright, I am going to release #25 as a more urgent patch release, and then review this PR a bit later to include in a subsequent minor version feature release.

@zheland
Copy link
Contributor Author

zheland commented Jul 5, 2024

Rebased to upstream/master.

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.

2 participants