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