Implement From store Circuit for protos Circuit
Adds various From implementations for the store Circuit-associated enums
to be converted to the admin::protos::Circuit-associated enum types.
This enables for easier conversion for the store-defined Circuit to the
admin::protos::Circuit definition.
@@ -172,6 +172,14 @@ impl TryFrom<&admin::Circuit_AuthorizationType> for AuthorizationType {
}
}
+impl From<&AuthorizationType> for admin::Circuit_AuthorizationType {
+ fn from(auth: &AuthorizationType) -> Self {
+ match *auth {
+ AuthorizationType::Trust => admin::Circuit_AuthorizationType::TRUST_AUTHORIZATION,
+ }
+ }
+}
+
/// A circuits message persistence strategy
#[derive(Clone, Debug, PartialEq, Eq)]
pub enum PersistenceType {
@@ -205,6 +213,14 @@ impl TryFrom<&admin::Circuit_PersistenceType> for PersistenceType {
}
}
+impl From<&PersistenceType> for admin::Circuit_PersistenceType {
+ fn from(persistence: &PersistenceType) -> Self {
+ match *persistence {
+ PersistenceType::Any => admin::Circuit_PersistenceType::ANY_PERSISTENCE,
+ }
+ }
+}
+
/// A circuits durability requirement
#[derive(Clone, Debug, PartialEq, Eq)]
pub enum DurabilityType {
@@ -232,6 +248,14 @@ impl TryFrom<&admin::Circuit_DurabilityType> for DurabilityType {
}
}
+impl From<&DurabilityType> for admin::Circuit_DurabilityType {
+ fn from(durability: &DurabilityType) -> Self {
+ match *durability {
+ DurabilityType::NoDurability => admin::Circuit_DurabilityType::NO_DURABILITY,
+ }
+ }
+}
+
/// How messages are expected to be routed across a circuit
#[derive(Clone, Debug, PartialEq, Eq)]
pub enum RouteType {
@@ -265,6 +289,14 @@ impl TryFrom<&admin::Circuit_RouteType> for RouteType {
}
}
+impl From<&RouteType> for admin::Circuit_RouteType {
+ fn from(route: &RouteType) -> Self {
+ match *route {
+ RouteType::Any => admin::Circuit_RouteType::ANY_ROUTE,
+ }
+ }
+}
+
/// Status of the circuit
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
pub enum CircuitStatus {
@@ -305,6 +337,16 @@ impl TryFrom<&admin::Circuit_CircuitStatus> for CircuitStatus {
}
}
+impl From<&CircuitStatus> for admin::Circuit_CircuitStatus {
+ fn from(status: &CircuitStatus) -> Self {
+ match *status {
+ CircuitStatus::Active => admin::Circuit_CircuitStatus::ACTIVE,
+ CircuitStatus::Disbanded => admin::Circuit_CircuitStatus::DISBANDED,
+ CircuitStatus::Abandoned => admin::Circuit_CircuitStatus::ABANDONED,
+ }
+ }
+}
+
/// Builder to be used to build a `Circuit`
#[derive(Default, Clone)]
pub struct CircuitBuilder {
