Add convenient functions and operators for Module and module resolvers.

This commit is contained in:
Stephen Chung
2020-10-07 15:40:36 +08:00
parent a56859c2ac
commit d7bfe13b3e
4 changed files with 86 additions and 10 deletions

View File

@@ -33,7 +33,7 @@ use crate::stdlib::{
fmt, format,
iter::empty,
num::NonZeroUsize,
ops::{Deref, DerefMut},
ops::{Add, AddAssign, Deref, DerefMut},
string::{String, ToString},
vec::Vec,
};
@@ -1546,6 +1546,38 @@ impl From<StaticVec<(String, Position)>> for ModuleRef {
}
}
impl Add<Module> for Module {
type Output = Self;
fn add(self, rhs: Module) -> Self::Output {
let mut module = self.clone();
module.merge(&rhs);
module
}
}
impl Add<&Module> for Module {
type Output = Self;
fn add(self, rhs: &Module) -> Self::Output {
let mut module = self.clone();
module.merge(rhs);
module
}
}
impl AddAssign<Module> for Module {
fn add_assign(&mut self, rhs: Module) {
self.combine(rhs);
}
}
impl AddAssign<&Module> for Module {
fn add_assign(&mut self, rhs: &Module) {
self.merge(rhs);
}
}
impl ModuleRef {
pub(crate) fn index(&self) -> Option<NonZeroUsize> {
self.1