#[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
Non-exhaustive enums could have additional variants added in future. Therefore, when matching against variants of non-exhaustive enums, an extra wildcard arm must be added to account for any future variants.
§

Tcp

§

Udp

§

Unknown(UnknownVariantValue)

Unknown contains new variants that have been added since this code was generated.

Implementations§

Returns the &str value of the enum member.

Examples found in repository?
src/model.rs (line 58346)
58345
58346
58347
    fn as_ref(&self) -> &str {
        self.as_str()
    }
More examples
Hide additional examples
src/operation_ser.rs (line 3674)
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))
}
src/query_ser.rs (line 5989)
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(())
}

Returns all the &str values of the enum members.

Trait Implementations§

Converts this type into a shared reference of the (usually inferred) input type.
Returns a copy of the value. Read more
Performs copy-assignment from source. Read more
Formats the value using the given formatter. Read more
Converts to this type from the input type.
The associated error which can be returned from parsing.
Parses a string s to return a value of this type. Read more
Feeds this value into the given Hasher. Read more
Feeds a slice of this type into the given Hasher. Read more
This method returns an Ordering between self and other. Read more
Compares and returns the maximum of two values. Read more
Compares and returns the minimum of two values. Read more
Restrict a value to a certain interval. Read more
This method tests for self and other values to be equal, and is used by ==. Read more
This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason. Read more
This method returns an ordering between self and other values if one exists. Read more
This method tests less than (for self and other) and is used by the < operator. Read more
This method tests less than or equal to (for self and other) and is used by the <= operator. Read more
This method tests greater than (for self and other) and is used by the > operator. Read more
This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more

Auto Trait Implementations§

Blanket Implementations§

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more
Compare self to key and return true if they are equal.

Returns the argument unchanged.

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Instruments this type with the current Span, returning an Instrumented wrapper. Read more

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Should always be Self
The resulting type after obtaining ownership.
Creates owned data from borrowed data, usually by cloning. Read more
Uses borrowed data to replace owned data, usually by cloning. Read more
The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.
Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more