#[non_exhaustive]
pub enum NetworkDirection {
In,
Out,
Unknown(UnknownVariantValue),
}
Expand description
When writing a match expression against NetworkDirection
, it is important to ensure
your code is forward-compatible. That is, if a match arm handles a case for a
feature that is supported by the service but has not been represented as an enum
variant in a current version of SDK, your code should continue to work when you
upgrade SDK to a future version in which the enum does include a variant for that
feature.
Here is an example of how you can make a match expression forward-compatible:
# let networkdirection = unimplemented!();
match networkdirection {
NetworkDirection::In => { /* ... */ },
NetworkDirection::Out => { /* ... */ },
other @ _ if other.as_str() == "NewFeature" => { /* handles a case for `NewFeature` */ },
_ => { /* ... */ },
}
The above code demonstrates that when networkdirection
represents
NewFeature
, the execution path will lead to the second last match arm,
even though the enum does not contain a variant NetworkDirection::NewFeature
in the current version of SDK. The reason is that the variable other
,
created by the @
operator, is bound to
NetworkDirection::Unknown(UnknownVariantValue("NewFeature".to_owned()))
and calling as_str
on it yields "NewFeature"
.
This match expression is forward-compatible when executed with a newer
version of SDK where the variant NetworkDirection::NewFeature
is defined.
Specifically, when networkdirection
represents NewFeature
,
the execution path will hit the second last match arm as before by virtue of
calling as_str
on NetworkDirection::NewFeature
also yielding "NewFeature"
.
Explicitly matching on the Unknown
variant should
be avoided for two reasons:
- The inner data
UnknownVariantValue
is opaque, and no further information can be extracted. - It might inadvertently shadow other intended match arms.
Variants (Non-exhaustive)§
This enum is marked as non-exhaustive
In
Out
Unknown(UnknownVariantValue)
Unknown
contains new variants that have been added since this code was generated.
Implementations§
source§impl NetworkDirection
impl NetworkDirection
sourcepub fn as_str(&self) -> &str
pub fn as_str(&self) -> &str
Returns the &str
value of the enum member.
Examples found in repository?
More examples
2550 2551 2552 2553 2554 2555 2556 2557 2558 2559 2560 2561 2562 2563 2564 2565 2566 2567 2568 2569 2570 2571 2572 2573 2574 2575 2576 2577 2578 2579 2580 2581 2582 2583 2584 2585 2586 2587 2588 2589 2590 2591 2592 2593 2594 2595 2596 2597 2598 2599 2600
pub fn serialize_structure_crate_model_network(
object: &mut aws_smithy_json::serialize::JsonObjectWriter,
input: &crate::model::Network,
) -> Result<(), aws_smithy_http::operation::error::SerializationError> {
if let Some(var_602) = &input.direction {
object.key("Direction").string(var_602.as_str());
}
if let Some(var_603) = &input.protocol {
object.key("Protocol").string(var_603.as_str());
}
if let Some(var_604) = &input.open_port_range {
#[allow(unused_mut)]
let mut object_605 = object.key("OpenPortRange").start_object();
crate::json_ser::serialize_structure_crate_model_port_range(&mut object_605, var_604)?;
object_605.finish();
}
if let Some(var_606) = &input.source_ip_v4 {
object.key("SourceIpV4").string(var_606.as_str());
}
if let Some(var_607) = &input.source_ip_v6 {
object.key("SourceIpV6").string(var_607.as_str());
}
if input.source_port != 0 {
object.key("SourcePort").number(
#[allow(clippy::useless_conversion)]
aws_smithy_types::Number::NegInt((input.source_port).into()),
);
}
if let Some(var_608) = &input.source_domain {
object.key("SourceDomain").string(var_608.as_str());
}
if let Some(var_609) = &input.source_mac {
object.key("SourceMac").string(var_609.as_str());
}
if let Some(var_610) = &input.destination_ip_v4 {
object.key("DestinationIpV4").string(var_610.as_str());
}
if let Some(var_611) = &input.destination_ip_v6 {
object.key("DestinationIpV6").string(var_611.as_str());
}
if input.destination_port != 0 {
object.key("DestinationPort").number(
#[allow(clippy::useless_conversion)]
aws_smithy_types::Number::NegInt((input.destination_port).into()),
);
}
if let Some(var_612) = &input.destination_domain {
object.key("DestinationDomain").string(var_612.as_str());
}
Ok(())
}
Trait Implementations§
source§impl AsRef<str> for NetworkDirection
impl AsRef<str> for NetworkDirection
source§impl Clone for NetworkDirection
impl Clone for NetworkDirection
source§fn clone(&self) -> NetworkDirection
fn clone(&self) -> NetworkDirection
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moresource§impl Debug for NetworkDirection
impl Debug for NetworkDirection
source§impl From<&str> for NetworkDirection
impl From<&str> for NetworkDirection
source§impl FromStr for NetworkDirection
impl FromStr for NetworkDirection
source§impl Hash for NetworkDirection
impl Hash for NetworkDirection
source§impl Ord for NetworkDirection
impl Ord for NetworkDirection
source§fn cmp(&self, other: &NetworkDirection) -> Ordering
fn cmp(&self, other: &NetworkDirection) -> Ordering
1.21.0 · source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
source§impl PartialEq<NetworkDirection> for NetworkDirection
impl PartialEq<NetworkDirection> for NetworkDirection
source§fn eq(&self, other: &NetworkDirection) -> bool
fn eq(&self, other: &NetworkDirection) -> bool
source§impl PartialOrd<NetworkDirection> for NetworkDirection
impl PartialOrd<NetworkDirection> for NetworkDirection
source§fn partial_cmp(&self, other: &NetworkDirection) -> Option<Ordering>
fn partial_cmp(&self, other: &NetworkDirection) -> Option<Ordering>
1.0.0 · source§fn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
self
and other
) and is used by the <=
operator. Read moreimpl Eq for NetworkDirection
impl StructuralEq for NetworkDirection
impl StructuralPartialEq for NetworkDirection
Auto Trait Implementations§
impl RefUnwindSafe for NetworkDirection
impl Send for NetworkDirection
impl Sync for NetworkDirection
impl Unpin for NetworkDirection
impl UnwindSafe for NetworkDirection
Blanket Implementations§
source§impl<Q, K> Equivalent<K> for Qwhere
Q: Eq + ?Sized,
K: Borrow<Q> + ?Sized,
impl<Q, K> Equivalent<K> for Qwhere
Q: Eq + ?Sized,
K: Borrow<Q> + ?Sized,
source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key
and return true
if they are equal.