Skip to content

Commit 008b42c

Browse files
committed
added into any trait
1 parent 9b4dc35 commit 008b42c

File tree

3 files changed

+17
-6
lines changed

3 files changed

+17
-6
lines changed

dynamic_plan_tree/src/behaviour.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -530,7 +530,7 @@ mod tests {
530530
#[derive(Serialize, Deserialize)]
531531
struct TestConfig;
532532
impl Config for TestConfig {
533-
type Predicate = predicate::True;
533+
type Predicate = predicate::Predicates;
534534
type Behaviour = TestBehaviours<Self>;
535535
}
536536
type TC = TestConfig;

dynamic_plan_tree/src/plan.rs

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,17 @@ pub trait FromAny: Sized {
2424
fn from_any(x: impl Any) -> Option<Self>;
2525
}
2626

27+
pub trait IntoAny {
28+
fn into_any<T: FromAny>(self) -> Option<T>
29+
where
30+
Self: 'static + Sized,
31+
{
32+
T::from_any(self)
33+
}
34+
}
35+
36+
impl<T> IntoAny for T {}
37+
2738
pub trait Cast {
2839
fn cast<T: 'static>(&self) -> Option<&T>;
2940
fn cast_mut<T: 'static>(&mut self) -> Option<&mut T>;
@@ -369,7 +380,7 @@ mod tests {
369380
#[derive(Serialize, Deserialize)]
370381
struct TestConfig;
371382
impl Config for TestConfig {
372-
type Predicate = predicate::True;
383+
type Predicate = predicate::Predicates;
373384
type Behaviour = RunCountBehaviour;
374385
}
375386

@@ -383,17 +394,17 @@ mod tests {
383394
Transition {
384395
src: vec!["A".into()],
385396
dst: vec!["B".into()],
386-
predicate: predicate::True,
397+
predicate: predicate::True.into_any().unwrap(),
387398
},
388399
Transition {
389400
src: vec!["B".into()],
390401
dst: vec!["C".into()],
391-
predicate: predicate::True,
402+
predicate: predicate::True.into_any().unwrap(),
392403
},
393404
Transition {
394405
src: vec!["C".into()],
395406
dst: vec!["A".into()],
396-
predicate: predicate::True,
407+
predicate: predicate::True.into_any().unwrap(),
397408
},
398409
];
399410
// init plan to A

dynamic_plan_tree/src/predicate.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ pub enum Predicates {
4040
AnyFailure,
4141
}
4242

43-
#[derive(Serialize, Deserialize, FromAny)]
43+
#[derive(Serialize, Deserialize)]
4444
pub struct True;
4545
impl Predicate for True {
4646
fn evaluate(&self, _: &Plan<impl Config>, _: &[String]) -> bool {

0 commit comments

Comments
 (0)