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}
24
25impl BehaviorVersion {
26    /// This method will always return the latest major version.
27    ///
28    /// This is the recommend choice for customers who aren't reliant on extremely specific behavior
29    /// characteristics. For example, if you are writing a CLI app, the latest behavior major
30    /// version is probably the best setting for you.
31    ///
32    /// If, however, you're writing a service that is very latency sensitive, or that has written
33    /// code to tune Rust SDK behaviors, consider pinning to a specific major version.
34    ///
35    /// The latest version is currently [`BehaviorVersion::v2024_03_28`]
36    pub fn latest() -> Self {
37        Self::v2024_03_28()
38    }
39
40    /// Behavior version for March 28th, 2024.
41    ///
42    /// This version enables stalled stream protection for uploads (request bodies) by default.
43    ///
44    /// When a new behavior major version is released, this method will be deprecated.
45    pub fn v2024_03_28() -> Self {
46        Self {
47            inner: Inner::V2024_03_28,
48        }
49    }
50
51    /// Behavior version for November 9th, 2023.
52    #[deprecated(
53        since = "1.4.0",
54        note = "Superceded by v2024_03_28, which enabled stalled stream protection for uploads (request bodies) by default."
55    )]
56    pub fn v2023_11_09() -> Self {
57        Self {
58            inner: Inner::V2023_11_09,
59        }
60    }
61
62    /// True if this version is newer or equal to the given `other` version.
63    pub fn is_at_least(&self, other: BehaviorVersion) -> bool {
64        self.inner >= other.inner
65    }
66}
67
68impl std::fmt::Debug for BehaviorVersion {
69    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
70        f.debug_tuple("BehaviorVersion").field(&self.inner).finish()
71    }
72}
73
74#[cfg(test)]
75mod tests {
76    use super::*;
77
78    #[test]
79    #[allow(deprecated)]
80    fn version_comparison() {
81        assert!(BehaviorVersion::latest() == BehaviorVersion::latest());
82        assert!(BehaviorVersion::v2023_11_09() == BehaviorVersion::v2023_11_09());
83        assert!(BehaviorVersion::v2024_03_28() != BehaviorVersion::v2023_11_09());
84        assert!(BehaviorVersion::latest().is_at_least(BehaviorVersion::latest()));
85        assert!(BehaviorVersion::latest().is_at_least(BehaviorVersion::v2023_11_09()));
86        assert!(BehaviorVersion::latest().is_at_least(BehaviorVersion::v2024_03_28()));
87        assert!(!BehaviorVersion::v2023_11_09().is_at_least(BehaviorVersion::v2024_03_28()));
88        assert!(Inner::V2024_03_28 > Inner::V2023_11_09);
89        assert!(Inner::V2023_11_09 < Inner::V2024_03_28);
90    }
91}