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

Indexing

(Supported by dart and cpp, queried with supports = indexing)

[] can be overloaded in languages that support it by applying an indexer attribute to a method that takes an integer argument and returns an Option<u8>.

#![allow(unused)]
fn main() {
#[diplomat::bridge]
mod ffi {
    #[diplomat::opaque]
    struct Foo(Vec<u8>);

    impl Foo {
        #[diplomat::attr(auto, indexer)]
        pub fn get(&self, idx: usize) -> Option<u8> {
            self.0.get(idx).copied()
        }
    }
}
}