Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions crates/compilers/src/compilers/restrictions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ use semver::VersionReq;
/// Abstraction over set of restrictions for given [`crate::Compiler::Settings`].
pub trait CompilerSettingsRestrictions: Copy + Debug + Sync + Send + Clone + Default {
/// Combines this restriction with another one. Returns `None` if restrictions are incompatible.
#[must_use]
fn merge(self, other: Self) -> Option<Self>;
}

Expand All @@ -20,15 +21,18 @@ pub struct RestrictionsWithVersion<T> {
}

impl<T: CompilerSettingsRestrictions> RestrictionsWithVersion<T> {
pub fn merge(&mut self, other: Self) {
/// Tries to merge the given restrictions with the other [`RestrictionsWithVersion`]. Returns
/// `None` if restrictions are incompatible.
pub fn merge(mut self, other: Self) -> Option<Self> {
if let Some(version) = other.version {
if let Some(self_version) = self.version.as_mut() {
self_version.comparators.extend(version.comparators);
} else {
self.version = Some(version.clone());
}
}
self.restrictions.merge(other.restrictions);
self.restrictions = self.restrictions.merge(other.restrictions)?;
Some(self)
}
}

Expand Down
Loading