•  TehPers   ( @TehPers@beehaw.org ) 
    link
    fedilink
    English
    arrow-up
    3
    ·
    21 天前
    #[unsafe(export_name = "my_super_duper_function")]
    pub fn foo() {}
    

    I would recommend reading up some materials on FFI in Rust if you’re interested. Calling functions in Rust from C and in C from Rust (or even languages other than C) is both extremely common and a primary usecase of the language.

      •  TehPers   ( @TehPers@beehaw.org ) 
        link
        fedilink
        English
        arrow-up
        3
        ·
        21 天前

        No, the attribute is unsafe. An unsafe function is marked unsafe fn.

        Also, unsafe by itself just means there are invariants that must me manually upheld to avoid unsound behavior. If those invariants are upheld, then it doesn’t matter if it’s unsafe.