Building Rust FFI bindings by example

To map an enum from Rust to GT, create a subclass of GtExternalEnumeration FFIExternalEnumeration << #GtExternalEnumeration slots: {}; tag: 'New'; package: 'GToolkit-Boxer' and implement the following methods by overriding them in a subclass on the class side: GtExternalEnumeration>>#externalDeclaration externalDeclaration " self rebuildEnumAccessors " ^ self subclassResponsibility and GtExternalEnumeration>>#externalType externalType ^ self subclassResponsibility .

A simple enum with an explicit u8 memory representation:

        
#[repr(u8)]
pub enum Enumeration {
    A,
    B,
    C,
}
        
      

maps in GT to GtBoxerExampleU8Enumeration>>#externalDeclaration externalDeclaration ^ #( A, B, C, ) with the following GtBoxerExampleU8Enumeration>>#externalType externalType ^ FFIUInt8 new

If an enum has #[repr(u32)] memory representation, return the corresponding externalType GtBoxerExampleU32Enumeration>>#externalType externalType ^ FFIUInt32 new