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

Use the #[doc(alias = "...")] attribute on wrapper methods #15

Closed
Cldfire opened this issue Dec 6, 2020 · 0 comments · Fixed by #31
Closed

Use the #[doc(alias = "...")] attribute on wrapper methods #15

Cldfire opened this issue Dec 6, 2020 · 0 comments · Fixed by #31

Comments

@Cldfire
Copy link
Collaborator

Cldfire commented Dec 6, 2020

The #[doc(alias = "...")] attribute became stable in Rust 1.48, and an interesting usecase for the feature was presented in this blog post. Libraries that wrap over an FFI interface (like nvml-wrapper does) can use the attribute to make it easier for developers used to working with the C library to transition to the Rust wrapper by enabling them to search for the C function names directly.

As an example, the following wrapper function in nvml-wrapper:

pub fn are_devices_on_same_board(
    &self,
    device1: &Device,
    device2: &Device,
) -> Result<bool, NvmlError> {
    let sym = nvml_sym(self.lib.nvmlDeviceOnSameBoard.as_ref())?;

    unsafe {
        let mut bool_int: c_int = mem::zeroed();

        nvml_try(sym(device1.handle(), device2.handle(), &mut bool_int))?;

        match bool_int {
            0 => Ok(false),
            _ => Ok(true),
        }
    }
}

should be annotated with the following attribute:

#[doc(alias = "nvmlDeviceOnSameBoard")]

So that it's possible to search for the C function name and find the equivalent method in the Rust wrapper.

I'd be happy to accept a PR adding usages of this attribute around the wrapper!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant