aws_smithy_runtime_api/client/behavior_version.rs
1/*
2 * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3 * SPDX-License-Identifier: Apache-2.0
4 */
5
6//! Behavior version of the client
7
8/// Behavior version of the client
9///
10/// Over time, new best-practice behaviors are introduced. However, these behaviors might not be
11/// backwards compatible. For example, a change which introduces new default timeouts or a new
12/// retry-mode for all operations might be the ideal behavior but could break existing applications.
13#[derive(Copy, Clone, PartialEq)]
14pub struct BehaviorVersion {
15 inner: Inner,
16}
17
18#[derive(Copy, Clone, Debug, Ord, PartialOrd, Eq, PartialEq)]
19enum Inner {
20 // IMPORTANT: Order matters here for the `Ord` derive. Newer versions go to the bottom.
21 V2023_11_09,
22 V2024_03_28,
23 V2025_01_17,
24 V2025_08_07,
25 V2026_01_12,
26}
27
28impl BehaviorVersion {
29 /// This method will always return the latest major version.
30 ///
31 /// This is the recommend choice for customers who aren't reliant on extremely specific behavior
32 /// characteristics. For example, if you are writing a CLI app, the latest behavior major
33 /// version is probably the best setting for you.
34 ///
35 /// If, however, you're writing a service that is very latency sensitive, or that has written
36 /// code to tune Rust SDK behaviors, consider pinning to a specific major version.
37 ///
38 /// The latest version is currently [`BehaviorVersion::v2026_01_12`]
39 pub fn latest() -> Self {
40 Self::v2026_01_12()
41 }
42
43 /// Behavior version for January 12th, 2026.
44 ///
45 /// This version enables retries by default for AWS SDK clients. Generic Smithy clients
46 /// (non-AWS) do not have retries enabled by default.
47 ///
48 /// Additionally, this version sets a 3.1 second connect timeout for all clients.
49 ///
50 /// For more information about behavior versions and how they affect SDK behavior, see the
51 /// [AWS SDK for Rust Developer Guide](https://docs.aws.amazon.com/sdk-for-rust/latest/dg/behavior-versions.html).
52 pub fn v2026_01_12() -> Self {
53 Self {
54 inner: Inner::V2026_01_12,
55 }
56 }
57
58 /// Behavior version for August 7th, 2025.
59 ///
60 /// This version updates the default HTTPS client to support proxy environment variables
61 /// (e.g. `HTTP_PROXY`, `HTTPS_PROXY`, `NO_PROXY`) by default.
62 #[deprecated(
63 since = "1.10.0",
64 note = "Superseded by v2026_01_12, which enables retries by default for AWS SDK clients and sets a 3.1s connect timeout for all clients."
65 )]
66 pub fn v2025_08_07() -> Self {
67 Self {
68 inner: Inner::V2025_08_07,
69 }
70 }
71
72 /// Behavior version for January 17th, 2025
73 ///
74 /// This version updates the default HTTP client and TLS stack. SDKs shipped with
75 /// a pre 1.x version of hyper and rustls originally. This behavior version updates
76 /// the HTTP+TLS stack to maintained versions.
77 ///
78 /// <div class="warning">
79 /// NOTE: In a future release behavior versions prior to this will require enabling
80 /// feature flags manually to keep the legacy Hyper stack as the default. Specifically the
81 /// `aws-smithy-runtime/tls-rustls` feature flag combined with an older behavior version.
82 /// </div>
83 #[deprecated(
84 since = "1.9.0",
85 note = "Superseded by v2025_08_07, which enables automatic HTTP(S) proxy support from environment variables in the default HTTPS client."
86 )]
87 pub fn v2025_01_17() -> Self {
88 Self {
89 inner: Inner::V2025_01_17,
90 }
91 }
92
93 /// Behavior version for March 28th, 2024.
94 ///
95 /// This version enables stalled stream protection for uploads (request bodies) by default.
96 ///
97 /// When a new behavior major version is released, this method will be deprecated.
98 #[deprecated(
99 since = "1.8.0",
100 note = "Superseded by v2025_01_17, which updates the default HTTPS client stack."
101 )]
102 pub fn v2024_03_28() -> Self {
103 Self {
104 inner: Inner::V2024_03_28,
105 }
106 }
107
108 /// Behavior version for November 9th, 2023.
109 #[deprecated(
110 since = "1.4.0",
111 note = "Superseded by v2024_03_28, which enabled stalled stream protection for uploads (request bodies) by default."
112 )]
113 pub fn v2023_11_09() -> Self {
114 Self {
115 inner: Inner::V2023_11_09,
116 }
117 }
118
119 /// True if this version is newer or equal to the given `other` version.
120 pub fn is_at_least(&self, other: BehaviorVersion) -> bool {
121 self.inner >= other.inner
122 }
123}
124
125impl std::fmt::Debug for BehaviorVersion {
126 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
127 f.debug_tuple("BehaviorVersion").field(&self.inner).finish()
128 }
129}
130
131#[cfg(test)]
132mod tests {
133 use super::*;
134
135 #[test]
136 #[allow(deprecated)]
137 fn version_comparison() {
138 assert!(BehaviorVersion::latest() == BehaviorVersion::latest());
139 assert!(BehaviorVersion::v2023_11_09() == BehaviorVersion::v2023_11_09());
140 assert!(BehaviorVersion::v2024_03_28() != BehaviorVersion::v2023_11_09());
141 assert!(BehaviorVersion::v2025_01_17() != BehaviorVersion::v2024_03_28());
142 assert!(BehaviorVersion::latest().is_at_least(BehaviorVersion::latest()));
143 assert!(BehaviorVersion::latest().is_at_least(BehaviorVersion::v2023_11_09()));
144 assert!(BehaviorVersion::latest().is_at_least(BehaviorVersion::v2024_03_28()));
145 assert!(BehaviorVersion::latest().is_at_least(BehaviorVersion::v2025_01_17()));
146 assert!(BehaviorVersion::latest().is_at_least(BehaviorVersion::v2025_08_07()));
147 assert!(!BehaviorVersion::v2023_11_09().is_at_least(BehaviorVersion::v2024_03_28()));
148 assert!(Inner::V2024_03_28 > Inner::V2023_11_09);
149 assert!(Inner::V2023_11_09 < Inner::V2024_03_28);
150 assert!(Inner::V2024_03_28 < Inner::V2025_01_17);
151 assert!(Inner::V2025_01_17 < Inner::V2025_08_07);
152 assert!(Inner::V2025_08_07 < Inner::V2026_01_12);
153 }
154}