Skip to content

Commit

Permalink
refactor(core): Remove Runtime::get_mut_*
Browse files Browse the repository at this point in the history
  • Loading branch information
watcol committed Jul 30, 2022
1 parent 2ed3bff commit 15c8448
Showing 1 changed file with 4 additions and 31 deletions.
35 changes: 4 additions & 31 deletions drake-core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use core::ops::Range;
pub use module::Module;

/// A struct contains all runtime informations
#[derive(Debug, Clone, Default)]
#[derive(Debug, Clone)]
#[allow(dead_code)]
pub struct Runtime {
modules: Vec<Module>,
Expand Down Expand Up @@ -52,19 +52,10 @@ impl<'a> Files<'a> for Runtime {
impl Runtime {
/// Creates a new instance.
#[inline]
pub fn new() -> Self {
Self::default()
}

/// Registers a new module by the name and the source code.
pub fn add(&mut self, name: String, source: String) -> usize {
if let Some((id, _)) = self.get_module_by_name(&name) {
return id;
pub fn new(name: String, source: String) -> Self {
Self {
modules: alloc::vec![Module::new(name, source)],
}

let mod_id = self.modules.len();
self.modules.push(Module::new(name, source));
mod_id
}

/// Gets a slice of modules indexed by identifiers.
Expand All @@ -87,22 +78,4 @@ impl Runtime {
.enumerate()
.find(|(_, m)| m.get_name() == name.as_ref())
}

/// Gets a mutable reference of a module corresponding to given module identifier.
#[inline]
pub fn get_mut_module(&mut self, id: usize) -> Option<&mut Module> {
self.modules.get_mut(id)
}

/// Gets a mutable reference of a module corresponding to given name.
#[inline]
pub fn get_mut_module_by_name<S: AsRef<str>>(
&mut self,
name: S,
) -> Option<(usize, &mut Module)> {
self.modules
.iter_mut()
.enumerate()
.find(|(_, m)| m.get_name() == name.as_ref())
}
}

0 comments on commit 15c8448

Please sign in to comment.