Skip to main content

s3/
lib.rs

1//! Simple access to Amazon Web Service's (AWS) Simple Storage Service (S3)
2#![forbid(unsafe_code)]
3
4#[macro_use]
5extern crate serde_derive;
6
7use std::sync::atomic::AtomicU8;
8
9pub use awscreds as creds;
10pub use awsregion as region;
11
12pub use bucket::Bucket;
13pub use bucket::Tag;
14pub use bucket_ops::BucketConfiguration;
15pub use post_policy::{PostPolicy, PostPolicyChecksum, PostPolicyField, PostPolicyValue};
16pub use put_object_request::PutObjectRequest;
17#[cfg(any(feature = "with-tokio", feature = "with-async-std"))]
18pub use put_object_request::PutObjectStreamRequest;
19pub use region::Region;
20
21pub mod bucket;
22pub mod bucket_ops;
23pub mod command;
24pub mod deserializer;
25pub mod post_policy;
26pub mod put_object_request;
27pub mod serde_types;
28pub mod signing;
29
30pub mod error;
31pub mod request;
32pub mod utils;
33
34const LONG_DATETIME: &[time::format_description::FormatItem<'static>] =
35    time::macros::format_description!("[year][month][day]T[hour][minute][second]Z");
36const EMPTY_PAYLOAD_SHA: &str = "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855";
37
38static RETRIES: AtomicU8 = AtomicU8::new(1);
39
40/// Sets the maximum number of retries for eligible request attempts.
41///
42/// This function stores the specified number of retries in an atomic variable,
43/// which can be safely shared across threads. Request retries are limited to
44/// reads and multipart part uploads whose upload ID, part number, and bytes are
45/// unchanged. Ambiguous mutations such as ordinary uploads, deletes, and
46/// multipart initiation or completion are not automatically replayed.
47///
48/// With `fail-on-err`, HTTP statuses 408, 429, 500, 502, 503, and 504 can be
49/// retried for eligible operations. Without `fail-on-err`, HTTP responses keep
50/// the raw-status behavior and HTTP statuses are not retried. Transport
51/// libraries expose different error detail, so some connection or TLS failures
52/// may also be retried for eligible operations. The exported [`retry!`] macro
53/// retains its independent behavior.
54///
55/// # Arguments
56///
57/// * `retries` - The number of retries to set.
58///
59/// # Example
60///
61/// ```rust
62/// s3::set_retries(3);
63/// ```
64pub fn set_retries(retries: u8) {
65    RETRIES.store(retries, std::sync::atomic::Ordering::SeqCst);
66}
67
68/// Retrieves the maximum number of retries configured for eligible request attempts.
69///
70/// This function loads the value of the atomic variable storing the number of retries,
71/// which can be safely accessed across threads.
72///
73/// # Returns
74///
75/// The number of retries currently set. This is an additional-attempt count,
76/// so zero means one total attempt.
77///
78/// # Example
79///
80/// ```rust
81/// let retries = s3::get_retries();
82/// ```
83pub fn get_retries() -> u8 {
84    RETRIES.load(std::sync::atomic::Ordering::Relaxed)
85}