#[non_exhaustive]
pub enum SupportedHardwareType {
Rack,
Server,
Unknown(UnknownVariantValue),
}
Expand description
When writing a match expression against SupportedHardwareType
, 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 supportedhardwaretype = unimplemented!();
match supportedhardwaretype {
SupportedHardwareType::Rack => { /* ... */ },
SupportedHardwareType::Server => { /* ... */ },
other @ _ if other.as_str() == "NewFeature" => { /* handles a case for `NewFeature` */ },
_ => { /* ... */ },
}
The above code demonstrates that when supportedhardwaretype
represents
NewFeature
, the execution path will lead to the second last match arm,
even though the enum does not contain a variant SupportedHardwareType::NewFeature
in the current version of SDK. The reason is that the variable other
,
created by the @
operator, is bound to
SupportedHardwareType::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 SupportedHardwareType::NewFeature
is defined.
Specifically, when supportedhardwaretype
represents NewFeature
,
the execution path will hit the second last match arm as before by virtue of
calling as_str
on SupportedHardwareType::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
Rack
Server
Unknown(UnknownVariantValue)
Unknown
contains new variants that have been added since this code was generated.
Implementations§
source§impl SupportedHardwareType
impl SupportedHardwareType
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
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 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168
pub fn serialize_structure_crate_input_create_outpost_input(
object: &mut aws_smithy_json::serialize::JsonObjectWriter,
input: &crate::input::CreateOutpostInput,
) -> Result<(), aws_smithy_http::operation::error::SerializationError> {
if let Some(var_8) = &input.availability_zone {
object.key("AvailabilityZone").string(var_8.as_str());
}
if let Some(var_9) = &input.availability_zone_id {
object.key("AvailabilityZoneId").string(var_9.as_str());
}
if let Some(var_10) = &input.description {
object.key("Description").string(var_10.as_str());
}
if let Some(var_11) = &input.name {
object.key("Name").string(var_11.as_str());
}
if let Some(var_12) = &input.site_id {
object.key("SiteId").string(var_12.as_str());
}
if let Some(var_13) = &input.supported_hardware_type {
object.key("SupportedHardwareType").string(var_13.as_str());
}
if let Some(var_14) = &input.tags {
#[allow(unused_mut)]
let mut object_15 = object.key("Tags").start_object();
for (key_16, value_17) in var_14 {
{
object_15.key(key_16.as_str()).string(value_17.as_str());
}
}
object_15.finish();
}
Ok(())
}
pub fn serialize_structure_crate_input_create_site_input(
object: &mut aws_smithy_json::serialize::JsonObjectWriter,
input: &crate::input::CreateSiteInput,
) -> Result<(), aws_smithy_http::operation::error::SerializationError> {
if let Some(var_18) = &input.description {
object.key("Description").string(var_18.as_str());
}
if let Some(var_19) = &input.name {
object.key("Name").string(var_19.as_str());
}
if let Some(var_20) = &input.notes {
object.key("Notes").string(var_20.as_str());
}
if let Some(var_21) = &input.operating_address {
#[allow(unused_mut)]
let mut object_22 = object.key("OperatingAddress").start_object();
crate::json_ser::serialize_structure_crate_model_address(&mut object_22, var_21)?;
object_22.finish();
}
if let Some(var_23) = &input.rack_physical_properties {
#[allow(unused_mut)]
let mut object_24 = object.key("RackPhysicalProperties").start_object();
crate::json_ser::serialize_structure_crate_model_rack_physical_properties(
&mut object_24,
var_23,
)?;
object_24.finish();
}
if let Some(var_25) = &input.shipping_address {
#[allow(unused_mut)]
let mut object_26 = object.key("ShippingAddress").start_object();
crate::json_ser::serialize_structure_crate_model_address(&mut object_26, var_25)?;
object_26.finish();
}
if let Some(var_27) = &input.tags {
#[allow(unused_mut)]
let mut object_28 = object.key("Tags").start_object();
for (key_29, value_30) in var_27 {
{
object_28.key(key_29.as_str()).string(value_30.as_str());
}
}
object_28.finish();
}
Ok(())
}
pub fn serialize_structure_crate_input_start_connection_input(
object: &mut aws_smithy_json::serialize::JsonObjectWriter,
input: &crate::input::StartConnectionInput,
) -> Result<(), aws_smithy_http::operation::error::SerializationError> {
if let Some(var_31) = &input.asset_id {
object.key("AssetId").string(var_31.as_str());
}
if let Some(var_32) = &input.client_public_key {
object.key("ClientPublicKey").string(var_32.as_str());
}
if let Some(var_33) = &input.device_serial_number {
object.key("DeviceSerialNumber").string(var_33.as_str());
}
{
object.key("NetworkInterfaceDeviceIndex").number(
#[allow(clippy::useless_conversion)]
aws_smithy_types::Number::NegInt((input.network_interface_device_index).into()),
);
}
Ok(())
}
pub fn serialize_structure_crate_input_tag_resource_input(
object: &mut aws_smithy_json::serialize::JsonObjectWriter,
input: &crate::input::TagResourceInput,
) -> Result<(), aws_smithy_http::operation::error::SerializationError> {
if let Some(var_34) = &input.tags {
#[allow(unused_mut)]
let mut object_35 = object.key("Tags").start_object();
for (key_36, value_37) in var_34 {
{
object_35.key(key_36.as_str()).string(value_37.as_str());
}
}
object_35.finish();
}
Ok(())
}
pub fn serialize_structure_crate_input_update_outpost_input(
object: &mut aws_smithy_json::serialize::JsonObjectWriter,
input: &crate::input::UpdateOutpostInput,
) -> Result<(), aws_smithy_http::operation::error::SerializationError> {
if let Some(var_38) = &input.description {
object.key("Description").string(var_38.as_str());
}
if let Some(var_39) = &input.name {
object.key("Name").string(var_39.as_str());
}
if let Some(var_40) = &input.supported_hardware_type {
object.key("SupportedHardwareType").string(var_40.as_str());
}
Ok(())
}
Trait Implementations§
source§impl AsRef<str> for SupportedHardwareType
impl AsRef<str> for SupportedHardwareType
source§impl Clone for SupportedHardwareType
impl Clone for SupportedHardwareType
source§fn clone(&self) -> SupportedHardwareType
fn clone(&self) -> SupportedHardwareType
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moresource§impl Debug for SupportedHardwareType
impl Debug for SupportedHardwareType
source§impl From<&str> for SupportedHardwareType
impl From<&str> for SupportedHardwareType
source§impl FromStr for SupportedHardwareType
impl FromStr for SupportedHardwareType
source§impl Hash for SupportedHardwareType
impl Hash for SupportedHardwareType
source§impl Ord for SupportedHardwareType
impl Ord for SupportedHardwareType
source§fn cmp(&self, other: &SupportedHardwareType) -> Ordering
fn cmp(&self, other: &SupportedHardwareType) -> Ordering
1.21.0 · source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
source§impl PartialEq<SupportedHardwareType> for SupportedHardwareType
impl PartialEq<SupportedHardwareType> for SupportedHardwareType
source§fn eq(&self, other: &SupportedHardwareType) -> bool
fn eq(&self, other: &SupportedHardwareType) -> bool
source§impl PartialOrd<SupportedHardwareType> for SupportedHardwareType
impl PartialOrd<SupportedHardwareType> for SupportedHardwareType
source§fn partial_cmp(&self, other: &SupportedHardwareType) -> Option<Ordering>
fn partial_cmp(&self, other: &SupportedHardwareType) -> 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 SupportedHardwareType
impl StructuralEq for SupportedHardwareType
impl StructuralPartialEq for SupportedHardwareType
Auto Trait Implementations§
impl RefUnwindSafe for SupportedHardwareType
impl Send for SupportedHardwareType
impl Sync for SupportedHardwareType
impl Unpin for SupportedHardwareType
impl UnwindSafe for SupportedHardwareType
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.