Skip to main content

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    V2026_08_01,
27}
28
29impl BehaviorVersion {
30    /// This method will always return the latest major version.
31    ///
32    /// This is the recommend choice for customers who aren't reliant on extremely specific behavior
33    /// characteristics. For example, if you are writing a CLI app, the latest behavior major
34    /// version is probably the best setting for you.
35    ///
36    /// If, however, you're writing a service that is very latency sensitive, or that has written
37    /// code to tune Rust SDK behaviors, consider pinning to a specific major version.
38    ///
39    /// The latest version is currently [`BehaviorVersion::v2026_08_01`]
40    pub fn latest() -> Self {
41        Self::v2026_08_01()
42    }
43
44    /// Behavior version for August 1st, 2026.
45    ///
46    /// This version changes the default identity cache for AWS SDK clients to one that supports
47    /// consistent identity refresh behavior. Generic Smithy clients (non-AWS) continue to use the
48    /// lazy identity cache.
49    ///
50    /// NOTE: the exact release date encoded in `v2026_08_01` is provisional and will be finalized
51    /// at release.
52    pub fn v2026_08_01() -> Self {
53        Self {
54            inner: Inner::V2026_08_01,
55        }
56    }
57
58    /// Behavior version for January 12th, 2026.
59    ///
60    /// This version enables retries by default for AWS SDK clients. Generic Smithy clients
61    /// (non-AWS) do not have retries enabled by default.
62    ///
63    /// Additionally, this version sets a 3.1 second connect timeout for all clients.
64    ///
65    /// For more information about behavior versions and how they affect SDK behavior, see the
66    /// [AWS SDK for Rust Developer Guide](https://docs.aws.amazon.com/sdk-for-rust/latest/dg/behavior-versions.html).
67    pub fn v2026_01_12() -> Self {
68        Self {
69            inner: Inner::V2026_01_12,
70        }
71    }
72
73    /// Behavior version for August 7th, 2025.
74    ///
75    /// This version updates the default HTTPS client to support proxy environment variables
76    /// (e.g. `HTTP_PROXY`, `HTTPS_PROXY`, `NO_PROXY`) by default.
77    #[deprecated(
78        since = "1.10.0",
79        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."
80    )]
81    pub fn v2025_08_07() -> Self {
82        Self {
83            inner: Inner::V2025_08_07,
84        }
85    }
86
87    /// Behavior version for January 17th, 2025
88    ///
89    /// This version updates the default HTTP client and TLS stack. SDKs shipped with
90    /// a pre 1.x version of hyper and rustls originally. This behavior version updates
91    /// the HTTP+TLS stack to maintained versions.
92    ///
93    /// <div class="warning">
94    /// NOTE: In a future release behavior versions prior to this will require enabling
95    /// feature flags manually to keep the legacy Hyper stack as the default. Specifically the
96    /// `aws-smithy-runtime/tls-rustls` feature flag combined with an older behavior version.
97    /// </div>
98    #[deprecated(
99        since = "1.9.0",
100        note = "Superseded by v2025_08_07, which enables automatic HTTP(S) proxy support from environment variables in the default HTTPS client."
101    )]
102    pub fn v2025_01_17() -> Self {
103        Self {
104            inner: Inner::V2025_01_17,
105        }
106    }
107
108    /// Behavior version for March 28th, 2024.
109    ///
110    /// This version enables stalled stream protection for uploads (request bodies) by default.
111    ///
112    /// When a new behavior major version is released, this method will be deprecated.
113    #[deprecated(
114        since = "1.8.0",
115        note = "Superseded by v2025_01_17, which updates the default HTTPS client stack."
116    )]
117    pub fn v2024_03_28() -> Self {
118        Self {
119            inner: Inner::V2024_03_28,
120        }
121    }
122
123    /// Behavior version for November 9th, 2023.
124    #[deprecated(
125        since = "1.4.0",
126        note = "Superseded by v2024_03_28, which enabled stalled stream protection for uploads (request bodies) by default."
127    )]
128    pub fn v2023_11_09() -> Self {
129        Self {
130            inner: Inner::V2023_11_09,
131        }
132    }
133
134    /// True if this version is newer or equal to the given `other` version.
135    pub fn is_at_least(&self, other: BehaviorVersion) -> bool {
136        self.inner >= other.inner
137    }
138}
139
140impl std::fmt::Debug for BehaviorVersion {
141    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
142        f.debug_tuple("BehaviorVersion").field(&self.inner).finish()
143    }
144}
145
146#[cfg(test)]
147mod tests {
148    use super::*;
149
150    #[test]
151    #[allow(deprecated)]
152    fn version_comparison() {
153        assert!(BehaviorVersion::latest() == BehaviorVersion::latest());
154        assert!(BehaviorVersion::v2023_11_09() == BehaviorVersion::v2023_11_09());
155        assert!(BehaviorVersion::v2024_03_28() != BehaviorVersion::v2023_11_09());
156        assert!(BehaviorVersion::v2025_01_17() != BehaviorVersion::v2024_03_28());
157        assert!(BehaviorVersion::latest().is_at_least(BehaviorVersion::latest()));
158        assert!(BehaviorVersion::latest().is_at_least(BehaviorVersion::v2023_11_09()));
159        assert!(BehaviorVersion::latest().is_at_least(BehaviorVersion::v2024_03_28()));
160        assert!(BehaviorVersion::latest().is_at_least(BehaviorVersion::v2025_01_17()));
161        assert!(BehaviorVersion::latest().is_at_least(BehaviorVersion::v2025_08_07()));
162        assert!(BehaviorVersion::latest().is_at_least(BehaviorVersion::v2026_01_12()));
163        assert!(BehaviorVersion::latest().is_at_least(BehaviorVersion::v2026_08_01()));
164        assert!(!BehaviorVersion::v2023_11_09().is_at_least(BehaviorVersion::v2024_03_28()));
165        assert!(!BehaviorVersion::v2026_01_12().is_at_least(BehaviorVersion::v2026_08_01()));
166        assert!(Inner::V2024_03_28 > Inner::V2023_11_09);
167        assert!(Inner::V2023_11_09 < Inner::V2024_03_28);
168        assert!(Inner::V2024_03_28 < Inner::V2025_01_17);
169        assert!(Inner::V2025_01_17 < Inner::V2025_08_07);
170        assert!(Inner::V2025_08_07 < Inner::V2026_01_12);
171        assert!(Inner::V2026_01_12 < Inner::V2026_08_01);
172    }
173}