Skip to content
GitLab
Projects Groups Topics Snippets
  • /
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
  • Register
  • Sign in
  • L linux
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributor statistics
    • Graph
    • Compare revisions
  • Issues 0
    • Issues 0
    • List
    • Boards
    • Service Desk
    • Milestones
  • Merge requests 0
    • Merge requests 0
  • Deployments
    • Deployments
    • Releases
  • Monitor
    • Monitor
    • Incidents
  • Analytics
    • Analytics
    • Value stream
    • Repository
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Commits
  • Issue Boards
Collapse sidebar
  • Kirill Smelkov
  • linux
  • Repository
  • linux
  • rust
  • kernel
  • types.rs
Find file BlameHistoryPermalink
  • Obei Sideg's avatar
    rust: types: add `try_from_foreign()` method · 5bc81841
    Obei Sideg authored Jan 29, 2024
    Currently `ForeignOwnable::from_foreign()` only works for non-null
    pointers for the existing `impl`s (e.g. `Box`, `Arc`). In turn, this
    means callers may write code like:
    
    ```rust
    // `p` is a pointer that may be null.
    if p.is_null() {
        None
    } else {
        unsafe { Some(Self::from_foreign(ptr)) }
    }
    ```
    
    Add a `try_from_foreign()` method to the trait with a default
    implementation that returns `None` if `ptr` is null, otherwise
    `Some(from_foreign(ptr))`, so that it can be used by callers instead.
    
    Link: https://github.com/Rust-for-Linux/linux/issues/1057
    
    
    Signed-off-by: default avatarObei Sideg <linux@obei.io>
    Reviewed-by: default avatarAlice Ryhl <aliceryhl@google.com>
    Reviewed-by: default avatarTrevor Gross <tmgross@umich.edu>
    Link: https://lore.kernel.org/r/0100018d53f737f8-80c1fe97-0019-40d7-ab69-b1b192785cd7-000000@email.amazonses.com
    
    
    [ Fixed intra-doc links, improved `SAFETY` comment and reworded commit. ]
    Signed-off-by: default avatarMiguel Ojeda <ojeda@kernel.org>
    5bc81841
GitLab Nexedi Edition | About GitLab | About Nexedi | 沪ICP备2021021310号-2 | 沪ICP备2021021310号-7