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