-
Notifications
You must be signed in to change notification settings - Fork 463
rust: types: Add try_from_foreign()
method
#1059
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
Conversation
5ff8680
to
534b8e8
Compare
Thanks! The commit should be signed (in the The commit message could perhaps also show how a user would look like (like one of the ones linked in the issue). Apart from that, it seems OK to submit it to the mailing list -- please see https://rust-for-linux.com/contributing. |
Currently `ForeignOwnable::from_foreign()` only works for non-null pointers for the existing impls (e.g. Box, Arc). It may create a few duplicate code like: ```rust // `p` is a maybe null pointer if p.is_null() { None } else { Some(unsafe { T::from_foreign(p) }) } `` Link: Rust-for-Linux#1059 Cc: Alice Ryhl <[email protected]> Cc: Matt Gilbride <[email protected]> Cc: Miguel Ojeda <[email protected]> Signed-off-by: Obei Sideg <[email protected]>
Currently `ForeignOwnable::from_foreign()` only works for non-null pointers for the existing impls (e.g. Box, Arc). It may create a few duplicate code like: ```rust // `p` is a maybe null pointer if p.is_null() { None } else { Some(unsafe { T::from_foreign(p) }) } `` Link: Rust-for-Linux#1059 Cc: Alice Ryhl <[email protected]> Cc: Matt Gilbride <[email protected]> Cc: Miguel Ojeda <[email protected]> Signed-off-by: Obei Sideg <[email protected]>
8db06e6
to
c9eee6f
Compare
Looks good. Is there code in the tree that can use this right away or we'd have to wait for patches to get merged? |
ef4a066
to
63eb0b3
Compare
Currently `ForeignOwnable::from_foreign()` only works for non-null pointers for the existing impls (e.g. Box, Arc). It may create a few duplicate code like: ```rust // `p` is a maybe null pointer if p.is_null() { None } else { unsafe { Some(Self::from_foreign(ptr)) } } ``` Add a `try_from_foreign()` method that will return `None` if `ptr` is null, otherwise return `Some(from_foreign(ptr))`. Link: Rust-for-Linux#1057 Signed-off-by: Obei Sideg <[email protected]> Reviewed-by: Alice Ryhl <[email protected]> Reviewed-by: Trevor Gross <[email protected]>
63eb0b3
to
47b451f
Compare
|
Close #1057