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

Deref and DerefMut for UniquePtr #95

Merged
merged 3 commits into from
Apr 10, 2020
Merged

Deref and DerefMut for UniquePtr #95

merged 3 commits into from
Apr 10, 2020

Conversation

dtolnay
Copy link
Owner

@dtolnay dtolnay commented Apr 10, 2020

The impls will panic on a null pointer. Panicking in Deref is unconventional but this matches the reality of how unique_ptr is used in practice in C++. In most places that unique_ptr is passed around they can never be null, and in the few cases where null is allowed the programmer is responsible for keeping track and handling those pointers carefully.

Providing these impls is less bad than users writing ptr.as_ref().unwrap() everywhere, because at least this way we can get the panic message to include type info to help debugging.

@dtolnay dtolnay merged commit b455d0a into master Apr 10, 2020
@dtolnay dtolnay deleted the deref branch April 10, 2020 06:58
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.

1 participant