@@ -11,22 +11,28 @@ pub mod trimexports;
1111pub mod verifyexports;
1212pub mod verifyimports;
1313
14+ #[ derive( Eq , PartialEq , Debug ) ]
15+ pub enum ModuleError {
16+ NotSupported ,
17+ Custom ( String ) ,
18+ }
19+
1420pub trait ModuleCreator {
1521 /// Returns new module.
16- fn create ( & self ) -> Result < Module , String > ;
22+ fn create ( & self ) -> Result < Module , ModuleError > ;
1723}
1824
1925pub trait ModuleTranslator {
20- /// Translates module. Returns new module.
21- fn translate ( & self , module : & Module ) -> Result < Module , String > ;
26+ /// Translates module. Returns new module. Can fail with ModuleError::NotSupported.
27+ fn translate ( & self , module : & Module ) -> Result < Module , ModuleError > ;
2228
23- /// Translates module in-place. Returns true if the module was modified.
24- fn translate_inplace ( & self , module : & mut Module ) -> Result < bool , String > ;
29+ /// Translates module in-place. Returns true if the module was modified. Can fail with ModuleError::NotSupported.
30+ fn translate_inplace ( & self , module : & mut Module ) -> Result < bool , ModuleError > ;
2531}
2632
2733pub trait ModuleValidator {
2834 /// Validates module. Returns true if it is valid or false if invalid.
29- fn validate ( & self , module : & Module ) -> Result < bool , String > ;
35+ fn validate ( & self , module : & Module ) -> Result < bool , ModuleError > ;
3036}
3137
3238#[ cfg( test) ]
@@ -36,22 +42,22 @@ mod tests {
3642 struct SampleModule { }
3743
3844 impl ModuleCreator for SampleModule {
39- fn create ( & self ) -> Result < Module , String > {
45+ fn create ( & self ) -> Result < Module , ModuleError > {
4046 Ok ( Module :: default ( ) )
4147 }
4248 }
4349
4450 impl ModuleTranslator for SampleModule {
45- fn translate ( & self , module : & Module ) -> Result < Module , String > {
51+ fn translate ( & self , module : & Module ) -> Result < Module , ModuleError > {
4652 Ok ( Module :: default ( ) )
4753 }
48- fn translate_inplace ( & self , module : & mut Module ) -> Result < bool , String > {
54+ fn translate_inplace ( & self , module : & mut Module ) -> Result < bool , ModuleError > {
4955 Ok ( ( true ) )
5056 }
5157 }
5258
5359 impl ModuleValidator for SampleModule {
54- fn validate ( & self , module : & Module ) -> Result < bool , String > {
60+ fn validate ( & self , module : & Module ) -> Result < bool , ModuleError > {
5561 Ok ( true )
5662 }
5763 }
0 commit comments