Skip to content

Commit

Permalink
impl From trait instead
Browse files Browse the repository at this point in the history
  • Loading branch information
t-lohse committed Feb 19, 2024
1 parent 16491df commit 2db1a1d
Showing 1 changed file with 13 additions and 11 deletions.
24 changes: 13 additions & 11 deletions src/system/query_failures.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ use crate::transition_systems::{CompositionType, TransitionSystem, TransitionSys

use super::specifics::{SpecificPath, SpecificState};

// TODO: Check file for From/Into impls
/// Represents how a system is composed at the highest level
#[derive(Clone, Debug, PartialEq, Eq, Hash)]
pub enum SystemType {
Expand Down Expand Up @@ -62,13 +61,6 @@ impl System {
sys_type: SystemType::Refinement,
}
}
/// Creates a new system from a single [TransitionSystem]
pub fn from(sys: &dyn TransitionSystem) -> Self {
Self {
name: sys.to_string(),
sys_type: sys.get_composition_type().into(),
}
}
/// Creates a new system from two [TransitionSystem]s, `sys1` and `sys2`, and the type of the composition `sys_type`
pub fn from_composite_system(
sys1: &dyn TransitionSystem,
Expand Down Expand Up @@ -364,12 +356,12 @@ impl ActionFailure {
}

/// Converts this [ActionFailure] into a [SystemRecipeFailure] given the [TransitionSystem] that failed.
pub fn to_recipe_failure(self, sys: &dyn TransitionSystem) -> SystemRecipeFailure {
pub fn to_recipe_failure_<T: TransitionSystem>(self, sys: &T) -> SystemRecipeFailure {
SystemRecipeFailure::Action(self, System::from(sys))
}

/// Converts this [ActionFailure] into a [SystemRecipeFailure] given the name of the system `sys` that failed.
pub fn to_simple_failure(self, sys: impl Into<String>) -> SystemRecipeFailure {
pub fn to_simple_failure<S: Into<String>>(self, sys: S) -> SystemRecipeFailure {
SystemRecipeFailure::Action(
self,
System {
Expand Down Expand Up @@ -485,7 +477,7 @@ impl ConsistencyFailure {
}

/// Converts this [ConsistencyFailure] into a [SystemRecipeFailure] given the [TransitionSystem] that failed.
pub fn to_recipe_failure(self, sys: &dyn TransitionSystem) -> SystemRecipeFailure {
pub fn to_recipe_failure<T: TransitionSystem>(self, sys: &T) -> SystemRecipeFailure {
SystemRecipeFailure::Inconsistent(self, System::from(sys))
}

Expand Down Expand Up @@ -687,6 +679,16 @@ mod conversions {
impl Error for DeterminismFailure {}
impl Error for SyntaxFailure {}

impl<T: TransitionSystem> From<&T> for System {
/// Creates a new system from a single [TransitionSystem]
fn from(value: &T) -> Self {
Self {
name: value.to_string(),
sys_type: value.get_composition_type().into(),
}
}
}

impl From<RefinementPrecondition> for RefinementFailure {
fn from(failure: RefinementPrecondition) -> Self {
RefinementFailure::Precondition(failure)
Expand Down

0 comments on commit 2db1a1d

Please sign in to comment.