Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Disabling APIs

(Supported by all backends)

Any type or method can be “disabled” by applying the disable attribute:

#![allow(unused)]
fn main() {
#[diplomat::bridge]
mod ffi {
    #[diplomat::opaque]
    #[diplomat::attr(cpp, disable)]
    struct Foo;


    impl Foo {
        #[diplomat::attr(js, disable)]
        pub fn bar() {}
        pub fn baz() {}
    }
}
}

Here, the class Foo will not show up in the C++ backend. It will in the JS backend, however it will not have the function bar().

Currently enum variants cannot be disabled, however this is technically feasible for input-only enums and could be added if people request. It is also not possible to disable struct fields.

#[diplomat::cfg(*)]

You can also use cfg to disable based on an implicit not(*) condition:

#[diplomat::bridge]
mod ffi {
    #[diplomat::opaque]
    #[diplomat::cfg(supports = namespaces)]
    struct Foo;
}

Is equivalent to

#[diplomat::bridge]
mod ffi {
    #[diplomat::opaque]
    #[diplomat::attr(not(supports = namespaces), disable)]
    struct Foo;
}