1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102
use crate::structure::GValue; use crate::structure::{Either2, TextP, T}; use crate::structure::{IntoPredicate, P}; pub enum HasStepKey { Str(String), T(T), } impl Into<HasStepKey> for T { fn into(self) -> HasStepKey { HasStepKey::T(self) } } impl Into<HasStepKey> for String { fn into(self) -> HasStepKey { HasStepKey::Str(self) } } impl Into<HasStepKey> for &str { fn into(self) -> HasStepKey { HasStepKey::Str(String::from(self)) } } pub struct HasStep { label: Option<String>, key: HasStepKey, predicate: Option<Either2<P, TextP>>, } impl From<HasStep> for Vec<GValue> { fn from(step: HasStep) -> Self { let mut params: Vec<GValue> = vec![]; if let Some(s) = step.label { params.push(Into::into(s)); } match step.key { HasStepKey::Str(key) => params.push(Into::into(key)), HasStepKey::T(key) => params.push(Into::into(key)), }; if let Some(p) = step.predicate { params.push(Into::into(p)); } params } } impl<A, B> From<(A, B)> for HasStep where A: Into<HasStepKey>, B: IntoPredicate, { fn from(param: (A, B)) -> Self { HasStep { label: None, key: param.0.into(), predicate: Some(param.1.into_predicate()), } } } impl<A, B, C> From<(A, B, C)> for HasStep where A: Into<String>, B: Into<HasStepKey>, C: IntoPredicate, { fn from(param: (A, B, C)) -> Self { HasStep { label: Some(param.0.into()), key: param.1.into(), predicate: Some(param.2.into_predicate()), } } } impl From<String> for HasStep { fn from(param: String) -> Self { HasStep { label: None, key: HasStepKey::Str(param), predicate: None, } } } impl From<&str> for HasStep { fn from(param: &str) -> Self { HasStep { label: None, key: HasStepKey::Str(String::from(param)), predicate: None, } } }