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}
26
27impl BehaviorVersion {
28 /// This method will always return the latest major version.
29 ///
30 /// This is the recommend choice for customers who aren't reliant on extremely specific behavior
31 /// characteristics. For example, if you are writing a CLI app, the latest behavior major
32 /// version is probably the best setting for you.
33 ///
34 /// If, however, you're writing a service that is very latency sensitive, or that has written
35 /// code to tune Rust SDK behaviors, consider pinning to a specific major version.
36 ///
37 /// The latest version is currently [`BehaviorVersion::v2025_08_07`]
38 pub fn latest() -> Self {
39 Self::v2025_08_07()
40 }
41
42 /// Behavior version for August 7th, 2025.
43 ///
44 /// This version updates the default HTTPS client to support proxy environment variables
45 /// (e.g. `HTTP_PROXY`, `HTTPS_PROXY`, `NO_PROXY`) by default.
46 pub fn v2025_08_07() -> Self {
47 Self {
48 inner: Inner::V2025_08_07,
49 }
50 }
51
52 /// Behavior version for January 17th, 2025
53 ///
54 /// This version updates the default HTTP client and TLS stack. SDKs shipped with
55 /// a pre 1.x version of hyper and rustls originally. This behavior version updates
56 /// the HTTP+TLS stack to maintained versions.
57 ///
58 /// <div class="warning">
59 /// NOTE: In a future release behavior versions prior to this will require enabling
60 /// feature flags manually to keep the legacy Hyper stack as the default. Specifically the
61 /// `aws-smithy-runtime/tls-rustls` feature flag combined with an older behavior version.
62 /// </div>
63 #[deprecated(
64 since = "1.9.0",
65 note = "Superseded by v2025_08_07, which enables automatic HTTP(S) proxy support from environment variables in the default HTTPS client."
66 )]
67 pub fn v2025_01_17() -> Self {
68 Self {
69 inner: Inner::V2025_01_17,
70 }
71 }
72
73 /// Behavior version for March 28th, 2024.
74 ///
75 /// This version enables stalled stream protection for uploads (request bodies) by default.
76 ///
77 /// When a new behavior major version is released, this method will be deprecated.
78 #[deprecated(
79 since = "1.8.0",
80 note = "Superseded by v2025_01_17, which updates the default HTTPS client stack."
81 )]
82 pub fn v2024_03_28() -> Self {
83 Self {
84 inner: Inner::V2024_03_28,
85 }
86 }
87
88 /// Behavior version for November 9th, 2023.
89 #[deprecated(
90 since = "1.4.0",
91 note = "Superseded by v2024_03_28, which enabled stalled stream protection for uploads (request bodies) by default."
92 )]
93 pub fn v2023_11_09() -> Self {
94 Self {
95 inner: Inner::V2023_11_09,
96 }
97 }
98
99 /// True if this version is newer or equal to the given `other` version.
100 pub fn is_at_least(&self, other: BehaviorVersion) -> bool {
101 self.inner >= other.inner
102 }
103}
104
105impl std::fmt::Debug for BehaviorVersion {
106 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
107 f.debug_tuple("BehaviorVersion").field(&self.inner).finish()
108 }
109}
110
111#[cfg(test)]
112mod tests {
113 use super::*;
114
115 #[test]
116 #[allow(deprecated)]
117 fn version_comparison() {
118 assert!(BehaviorVersion::latest() == BehaviorVersion::latest());
119 assert!(BehaviorVersion::v2023_11_09() == BehaviorVersion::v2023_11_09());
120 assert!(BehaviorVersion::v2024_03_28() != BehaviorVersion::v2023_11_09());
121 assert!(BehaviorVersion::v2025_01_17() != BehaviorVersion::v2024_03_28());
122 assert!(BehaviorVersion::latest().is_at_least(BehaviorVersion::latest()));
123 assert!(BehaviorVersion::latest().is_at_least(BehaviorVersion::v2023_11_09()));
124 assert!(BehaviorVersion::latest().is_at_least(BehaviorVersion::v2024_03_28()));
125 assert!(BehaviorVersion::latest().is_at_least(BehaviorVersion::v2025_01_17()));
126 assert!(!BehaviorVersion::v2023_11_09().is_at_least(BehaviorVersion::v2024_03_28()));
127 assert!(Inner::V2024_03_28 > Inner::V2023_11_09);
128 assert!(Inner::V2023_11_09 < Inner::V2024_03_28);
129 assert!(Inner::V2024_03_28 < Inner::V2025_01_17);
130 assert!(Inner::V2025_01_17 < Inner::V2025_08_07);
131 }
132}