#[non_exhaustive]
pub enum CrAllocationStrategy {
    BestFit,
    BestFitProgressive,
    SpotCapacityOptimized,
    Unknown(UnknownVariantValue),
}
Expand description

When writing a match expression against CrAllocationStrategy, 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 crallocationstrategy = unimplemented!();
match crallocationstrategy {
    CrAllocationStrategy::BestFit => { /* ... */ },
    CrAllocationStrategy::BestFitProgressive => { /* ... */ },
    CrAllocationStrategy::SpotCapacityOptimized => { /* ... */ },
    other @ _ if other.as_str() == "NewFeature" => { /* handles a case for `NewFeature` */ },
    _ => { /* ... */ },
}

The above code demonstrates that when crallocationstrategy represents NewFeature, the execution path will lead to the second last match arm, even though the enum does not contain a variant CrAllocationStrategy::NewFeature in the current version of SDK. The reason is that the variable other, created by the @ operator, is bound to CrAllocationStrategy::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 CrAllocationStrategy::NewFeature is defined. Specifically, when crallocationstrategy represents NewFeature, the execution path will hit the second last match arm as before by virtue of calling as_str on CrAllocationStrategy::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.
§

BestFit

§

BestFitProgressive

§

SpotCapacityOptimized

§

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 10765)
10764
10765
10766
    fn as_ref(&self) -> &str {
        self.as_str()
    }
More examples
Hide additional examples
src/json_ser.rs (line 646)
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
pub fn serialize_structure_crate_model_compute_resource(
    object: &mut aws_smithy_json::serialize::JsonObjectWriter,
    input: &crate::model::ComputeResource,
) -> Result<(), aws_smithy_http::operation::error::SerializationError> {
    if let Some(var_148) = &input.r#type {
        object.key("type").string(var_148.as_str());
    }
    if let Some(var_149) = &input.allocation_strategy {
        object.key("allocationStrategy").string(var_149.as_str());
    }
    if let Some(var_150) = &input.minv_cpus {
        object.key("minvCpus").number(
            #[allow(clippy::useless_conversion)]
            aws_smithy_types::Number::NegInt((*var_150).into()),
        );
    }
    if let Some(var_151) = &input.maxv_cpus {
        object.key("maxvCpus").number(
            #[allow(clippy::useless_conversion)]
            aws_smithy_types::Number::NegInt((*var_151).into()),
        );
    }
    if let Some(var_152) = &input.desiredv_cpus {
        object.key("desiredvCpus").number(
            #[allow(clippy::useless_conversion)]
            aws_smithy_types::Number::NegInt((*var_152).into()),
        );
    }
    if let Some(var_153) = &input.instance_types {
        let mut array_154 = object.key("instanceTypes").start_array();
        for item_155 in var_153 {
            {
                array_154.value().string(item_155.as_str());
            }
        }
        array_154.finish();
    }
    if let Some(var_156) = &input.image_id {
        object.key("imageId").string(var_156.as_str());
    }
    if let Some(var_157) = &input.subnets {
        let mut array_158 = object.key("subnets").start_array();
        for item_159 in var_157 {
            {
                array_158.value().string(item_159.as_str());
            }
        }
        array_158.finish();
    }
    if let Some(var_160) = &input.security_group_ids {
        let mut array_161 = object.key("securityGroupIds").start_array();
        for item_162 in var_160 {
            {
                array_161.value().string(item_162.as_str());
            }
        }
        array_161.finish();
    }
    if let Some(var_163) = &input.ec2_key_pair {
        object.key("ec2KeyPair").string(var_163.as_str());
    }
    if let Some(var_164) = &input.instance_role {
        object.key("instanceRole").string(var_164.as_str());
    }
    if let Some(var_165) = &input.tags {
        #[allow(unused_mut)]
        let mut object_166 = object.key("tags").start_object();
        for (key_167, value_168) in var_165 {
            {
                object_166.key(key_167.as_str()).string(value_168.as_str());
            }
        }
        object_166.finish();
    }
    if let Some(var_169) = &input.placement_group {
        object.key("placementGroup").string(var_169.as_str());
    }
    if let Some(var_170) = &input.bid_percentage {
        object.key("bidPercentage").number(
            #[allow(clippy::useless_conversion)]
            aws_smithy_types::Number::NegInt((*var_170).into()),
        );
    }
    if let Some(var_171) = &input.spot_iam_fleet_role {
        object.key("spotIamFleetRole").string(var_171.as_str());
    }
    if let Some(var_172) = &input.launch_template {
        #[allow(unused_mut)]
        let mut object_173 = object.key("launchTemplate").start_object();
        crate::json_ser::serialize_structure_crate_model_launch_template_specification(
            &mut object_173,
            var_172,
        )?;
        object_173.finish();
    }
    if let Some(var_174) = &input.ec2_configuration {
        let mut array_175 = object.key("ec2Configuration").start_array();
        for item_176 in var_174 {
            {
                #[allow(unused_mut)]
                let mut object_177 = array_175.value().start_object();
                crate::json_ser::serialize_structure_crate_model_ec2_configuration(
                    &mut object_177,
                    item_176,
                )?;
                object_177.finish();
            }
        }
        array_175.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