aws_smithy_async/lib.rs
1/*
2 * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3 * SPDX-License-Identifier: Apache-2.0
4 */
5
6/* Automatically managed default lints */
7#![cfg_attr(docsrs, feature(doc_auto_cfg))]
8/* End of automatically managed default lints */
9#![allow(clippy::derive_partial_eq_without_eq)]
10#![warn(
11 missing_docs,
12 rustdoc::missing_crate_level_docs,
13 unreachable_pub,
14 rust_2018_idioms
15)]
16
17//! Future utilities and runtime-agnostic abstractions for smithy-rs.
18//!
19//! Async runtime specific code is abstracted behind async traits, and implementations are
20//! provided via feature flag. For now, only Tokio runtime implementations are provided.
21
22pub mod future;
23pub mod rt;
24#[cfg(feature = "test-util")]
25pub mod test_util;
26pub mod time;
27
28/// Given an `Instant` and a `Duration`, assert time elapsed since `Instant` is equal to `Duration`.
29/// This macro allows for a 5ms margin of error.
30///
31/// # Example
32///
33/// ```rust,ignore
34/// let now = std::time::Instant::now();
35/// let _ = some_function_that_always_takes_five_seconds_to_run().await;
36/// assert_elapsed!(now, std::time::Duration::from_secs(5));
37/// ```
38#[macro_export]
39macro_rules! assert_elapsed {
40 ($start:expr, $dur:expr) => {
41 assert_elapsed!($start, $dur, std::time::Duration::from_millis(5));
42 };
43 ($start:expr, $dur:expr, $margin_of_error:expr) => {{
44 let elapsed = $start.elapsed();
45 // type ascription improves compiler error when wrong type is passed
46 let margin_of_error: std::time::Duration = $margin_of_error;
47 let lower: std::time::Duration = $dur - margin_of_error;
48 let upper: std::time::Duration = $dur + margin_of_error;
49
50 // Handles ms rounding
51 assert!(
52 elapsed >= lower && elapsed <= upper,
53 "actual = {:?}, expected = {:?}",
54 elapsed,
55 lower
56 );
57 }};
58}