After using the abigen! macro, CounterConfig will be accessible in your Rust file! Here's an example:
abigen!(Contract(name="MyContract", abi="packages/fuels/tests/types/contracts/complex_types_contract/out/debug/complex_types_contract-abi.json"));// Here we can use `CounterConfig`, a struct originally// defined in the contract.let counter_config =CounterConfig { dummy:true, initial_value:42,};
You can freely use your custom types (structs or enums) within this scope. That also means passing custom types to functions and receiving custom types from function calls.
The Fuel Rust SDK supports both generic enums and generic structs. If you're already familiar with Rust, it's your typical struct MyStruct<T> type of generics support.
For instance, your Sway contract could look like this:
// simple struct with a single generic paramlet arg1 =SimpleGeneric { single_generic_param:123u64,};let result = contract_methods.struct_w_generic(arg1.clone()).call().await?.value;assert_eq!(result, arg1);
If you tried the same in Rust you'd get complaints that T and K must be used or removed. When generating Rust bindings for such types we make use of the PhantomDataIcon Link type. The generated bindings for the above example would look something like this:
If your struct doesn't have any fields we'll also derive Default. As for enums all PhantomDatas are placed inside a new variant called IgnoreMe which you'll need to ignore in your matches:
match my_enum {MyEnum::One(_value) => {}MyEnum::IgnoreMe(..) =>panic!("Will never receive this variant"),}