Closed HDauven closed 1 month ago
Java/C# interfaces and Solidity interfaces or abstract contracts differ from Rust's traits. The inheritance of classes/contracts that implement an interface is not really supported in Rust.
Technically, macros could be used to conditionally expose functions (excluding predefined keyword functions like set_state) and maybe even auto generate the needed setters/getters in a struct, but this complicates the design and moves away from idiomatic Rust. Implementing an interface and inheritance behavior within Rust like Solidity supports it (with abstract contracts or interfaces) will lead to some sort of eDSL.
Higher level insights:
In general, to create contracts based on standards (which may be extensible) we can use a builder pattern to provide the variability and property setting as an alternative to a constructor approach.
For clarity: The previous answers included a wider scope not addressed in the original question
Final summary:
We should now start with atomic issues, the first one being: Macro to hide static mut state & no_mangle
Summary
Foreign traits can have interfaces but also default implementations. These default implementations can theoretically allow for the scaffolding of full contracts that adhere to a standard.
The primary problem we have is that the foreign trait with the default implementation needs to have access to the state and needs to expose the call to the VM.
Possible solution design or implementation
Investigate if it is possible to expose the foreign trait implementation and/or interface to the implementing contract.
The foreign trait implementation should have its call function generated if public AND have access to the contract state.
For the trait functions,
#[no_mangle]
functions can be generated. How it will access the state is a different matter that needs a further look. Maybe introducing the#[contract]
macro with an opinionated state structure.