Changed module set_name to return a boolean

This commit is contained in:
Syrus
2020-05-27 14:29:44 -07:00
parent 28c2a05853
commit 30dd994cd6

View File

@@ -297,10 +297,9 @@ impl Module {
/// Sets the name of the current module. /// Sets the name of the current module.
/// This is normally useful for stacktraces and debugging. /// This is normally useful for stacktraces and debugging.
/// ///
/// ## Important /// It will return `true` if the module name was changed successfully,
/// /// and return `false` otherwise (in case the module is already
/// If the module is already insantiated, setting a name will have /// instantiated).
/// no effects (it will silently fail).
/// ///
/// # Example /// # Example
/// ///
@@ -316,12 +315,14 @@ impl Module {
/// # Ok(()) /// # Ok(())
/// # } /// # }
/// ``` /// ```
pub fn set_name(&mut self, name: &str) { pub fn set_name(&mut self, name: &str) -> bool {
Arc::get_mut(&mut self.artifact) Arc::get_mut(&mut self.artifact)
.and_then(|artifact| artifact.module_mut()) .and_then(|artifact| artifact.module_mut())
.map(|mut module_info| { .map(|mut module_info| {
module_info.name = Some(name.to_string()); module_info.name = Some(name.to_string());
}); true
})
.unwrap_or(false)
} }
/// Returns an iterator over the imported types in the Module. /// Returns an iterator over the imported types in the Module.