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

Ignore FFI-unsafe warning to support stable? #34

Open
heaths opened this issue Aug 21, 2024 · 0 comments
Open

Ignore FFI-unsafe warning to support stable? #34

heaths opened this issue Aug 21, 2024 · 0 comments

Comments

@heaths
Copy link
Owner

heaths commented Aug 21, 2024

As the try_trait_v2 lingers on, perhaps we can just ignore the lint with something like:

use std::fmt;

const ERROR_INSTALL_FAILURE: Error =
    Error(unsafe { std::num::NonZero::<u32>::new_unchecked(1603) });

#[derive(Debug)]
#[repr(transparent)]
pub struct Error(std::num::NonZero<u32>);
impl std::error::Error for Error {}
impl fmt::Display for Error {
    fn fmt(&self, f: &'_ mut fmt::Formatter) -> fmt::Result {
        f.write_str(&self.0.to_string())
    }
}

pub type Result<T> = std::result::Result<T, Error>;

#[allow(improper_ctypes_definitions)]
#[no_mangle]
pub extern "C" fn print_size() -> Result<()> {
    println!("{}", std::mem::size_of::<Result<()>>());
    Err(ERROR_INSTALL_FAILURE)
}

fn main() -> std::result::Result<(), Box<dyn std::error::Error>> {
    Ok(print_size()?)
}
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

No branches or pull requests

1 participant