Enum aws_sdk_ec2::model::Protocol
source · #[non_exhaustive]
pub enum Protocol {
Tcp,
Udp,
Unknown(UnknownVariantValue),
}
Expand description
When writing a match expression against Protocol
, 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 protocol = unimplemented!();
match protocol {
Protocol::Tcp => { /* ... */ },
Protocol::Udp => { /* ... */ },
other @ _ if other.as_str() == "NewFeature" => { /* handles a case for `NewFeature` */ },
_ => { /* ... */ },
}
The above code demonstrates that when protocol
represents
NewFeature
, the execution path will lead to the second last match arm,
even though the enum does not contain a variant Protocol::NewFeature
in the current version of SDK. The reason is that the variable other
,
created by the @
operator, is bound to
Protocol::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 Protocol::NewFeature
is defined.
Specifically, when protocol
represents NewFeature
,
the execution path will hit the second last match arm as before by virtue of
calling as_str
on Protocol::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
Tcp
Udp
Unknown(UnknownVariantValue)
Unknown
contains new variants that have been added since this code was generated.
Implementations§
source§impl Protocol
impl Protocol
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
3644 3645 3646 3647 3648 3649 3650 3651 3652 3653 3654 3655 3656 3657 3658 3659 3660 3661 3662 3663 3664 3665 3666 3667 3668 3669 3670 3671 3672 3673 3674 3675 3676 3677 3678 3679 3680 3681 3682 3683 3684 3685 3686 3687 3688 3689 3690 3691 3692 3693 3694 3695 3696 3697 3698 3699 3700 3701 3702 3703 3704 3705 3706 3707 3708 3709
pub fn serialize_operation_crate_operation_create_network_insights_path(
input: &crate::input::CreateNetworkInsightsPathInput,
) -> Result<aws_smithy_http::body::SdkBody, aws_smithy_http::operation::error::SerializationError> {
let mut out = String::new();
#[allow(unused_mut)]
let mut writer =
aws_smithy_query::QueryWriter::new(&mut out, "CreateNetworkInsightsPath", "2016-11-15");
#[allow(unused_mut)]
let mut scope_1052 = writer.prefix("SourceIp");
if let Some(var_1053) = &input.source_ip {
scope_1052.string(var_1053);
}
#[allow(unused_mut)]
let mut scope_1054 = writer.prefix("DestinationIp");
if let Some(var_1055) = &input.destination_ip {
scope_1054.string(var_1055);
}
#[allow(unused_mut)]
let mut scope_1056 = writer.prefix("Source");
if let Some(var_1057) = &input.source {
scope_1056.string(var_1057);
}
#[allow(unused_mut)]
let mut scope_1058 = writer.prefix("Destination");
if let Some(var_1059) = &input.destination {
scope_1058.string(var_1059);
}
#[allow(unused_mut)]
let mut scope_1060 = writer.prefix("Protocol");
if let Some(var_1061) = &input.protocol {
scope_1060.string(var_1061.as_str());
}
#[allow(unused_mut)]
let mut scope_1062 = writer.prefix("DestinationPort");
if let Some(var_1063) = &input.destination_port {
scope_1062.number(
#[allow(clippy::useless_conversion)]
aws_smithy_types::Number::NegInt((*var_1063).into()),
);
}
#[allow(unused_mut)]
let mut scope_1064 = writer.prefix("TagSpecification");
if let Some(var_1065) = &input.tag_specifications {
let mut list_1067 = scope_1064.start_list(true, Some("item"));
for item_1066 in var_1065 {
#[allow(unused_mut)]
let mut entry_1068 = list_1067.entry();
crate::query_ser::serialize_structure_crate_model_tag_specification(
entry_1068, item_1066,
)?;
}
list_1067.finish();
}
#[allow(unused_mut)]
let mut scope_1069 = writer.prefix("DryRun");
if let Some(var_1070) = &input.dry_run {
scope_1069.boolean(*var_1070);
}
#[allow(unused_mut)]
let mut scope_1071 = writer.prefix("ClientToken");
if let Some(var_1072) = &input.client_token {
scope_1071.string(var_1072);
}
writer.finish();
Ok(aws_smithy_http::body::SdkBody::from(out))
}
5912 5913 5914 5915 5916 5917 5918 5919 5920 5921 5922 5923 5924 5925 5926 5927 5928 5929 5930 5931 5932 5933 5934 5935 5936 5937 5938 5939 5940 5941 5942 5943 5944 5945 5946 5947 5948 5949 5950 5951 5952 5953 5954 5955 5956 5957 5958 5959 5960 5961 5962 5963 5964 5965 5966 5967 5968 5969 5970 5971 5972 5973 5974 5975 5976 5977 5978 5979 5980 5981 5982 5983 5984 5985 5986 5987 5988 5989 5990 5991 5992 5993 5994
pub fn serialize_structure_crate_model_packet_header_statement_request(
mut writer: aws_smithy_query::QueryValueWriter,
input: &crate::model::PacketHeaderStatementRequest,
) -> Result<(), aws_smithy_http::operation::error::SerializationError> {
#[allow(unused_mut)]
let mut scope_1640 = writer.prefix("SourceAddress");
if let Some(var_1641) = &input.source_addresses {
let mut list_1643 = scope_1640.start_list(true, Some("item"));
for item_1642 in var_1641 {
#[allow(unused_mut)]
let mut entry_1644 = list_1643.entry();
entry_1644.string(item_1642);
}
list_1643.finish();
}
#[allow(unused_mut)]
let mut scope_1645 = writer.prefix("DestinationAddress");
if let Some(var_1646) = &input.destination_addresses {
let mut list_1648 = scope_1645.start_list(true, Some("item"));
for item_1647 in var_1646 {
#[allow(unused_mut)]
let mut entry_1649 = list_1648.entry();
entry_1649.string(item_1647);
}
list_1648.finish();
}
#[allow(unused_mut)]
let mut scope_1650 = writer.prefix("SourcePort");
if let Some(var_1651) = &input.source_ports {
let mut list_1653 = scope_1650.start_list(true, Some("item"));
for item_1652 in var_1651 {
#[allow(unused_mut)]
let mut entry_1654 = list_1653.entry();
entry_1654.string(item_1652);
}
list_1653.finish();
}
#[allow(unused_mut)]
let mut scope_1655 = writer.prefix("DestinationPort");
if let Some(var_1656) = &input.destination_ports {
let mut list_1658 = scope_1655.start_list(true, Some("item"));
for item_1657 in var_1656 {
#[allow(unused_mut)]
let mut entry_1659 = list_1658.entry();
entry_1659.string(item_1657);
}
list_1658.finish();
}
#[allow(unused_mut)]
let mut scope_1660 = writer.prefix("SourcePrefixList");
if let Some(var_1661) = &input.source_prefix_lists {
let mut list_1663 = scope_1660.start_list(true, Some("item"));
for item_1662 in var_1661 {
#[allow(unused_mut)]
let mut entry_1664 = list_1663.entry();
entry_1664.string(item_1662);
}
list_1663.finish();
}
#[allow(unused_mut)]
let mut scope_1665 = writer.prefix("DestinationPrefixList");
if let Some(var_1666) = &input.destination_prefix_lists {
let mut list_1668 = scope_1665.start_list(true, Some("item"));
for item_1667 in var_1666 {
#[allow(unused_mut)]
let mut entry_1669 = list_1668.entry();
entry_1669.string(item_1667);
}
list_1668.finish();
}
#[allow(unused_mut)]
let mut scope_1670 = writer.prefix("Protocol");
if let Some(var_1671) = &input.protocols {
let mut list_1673 = scope_1670.start_list(true, Some("item"));
for item_1672 in var_1671 {
#[allow(unused_mut)]
let mut entry_1674 = list_1673.entry();
entry_1674.string(item_1672.as_str());
}
list_1673.finish();
}
Ok(())
}
Trait Implementations§
source§impl Ord for Protocol
impl Ord for Protocol
source§impl PartialOrd<Protocol> for Protocol
impl PartialOrd<Protocol> for Protocol
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 Protocol
impl StructuralEq for Protocol
impl StructuralPartialEq for Protocol
Auto Trait Implementations§
impl RefUnwindSafe for Protocol
impl Send for Protocol
impl Sync for Protocol
impl Unpin for Protocol
impl UnwindSafe for Protocol
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.