Skip to content

Commit

Permalink
chore: Fix clippy lint issues
Browse files Browse the repository at this point in the history
  • Loading branch information
guerinoni committed Dec 9, 2024
1 parent 31b5b24 commit 9727c3a
Show file tree
Hide file tree
Showing 29 changed files with 214 additions and 64 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/continuos-integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ jobs:
rustup component add clippy
- name: Run clippy
run: cargo clippy -- -D warnings
run: cargo clippy

test:
strategy:
Expand Down
10 changes: 10 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ version = "0.5.0"
authors = ["Paolo Barbolini <[email protected]>", "Federico Guerinoni <[email protected]>"]
description = "Simple pure Rust AWS S3 Client following a Sans-IO approach"
keywords = ["aws", "s3", "minio"]
categories = ["aws", "s3", "minio"]
repository = "https://github.com/paolobarbolini/rusty-s3"
license = "BSD-2-Clause"
documentation = "https://docs.rs/rusty-s3"
Expand Down Expand Up @@ -42,3 +43,12 @@ criterion = "0.5"
[[bench]]
name = "actions"
harness = false

[lints.clippy]
complexity = "warn"
correctness = "warn"
nursery = "warn"
pedantic = "warn"
perf = "warn"
style = "warn"
suspicious = "warn"
2 changes: 1 addition & 1 deletion benches/actions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ fn criterion_benchmark(c: &mut Criterion) {
.insert("response-content-type", "text/plain");
let url = action.sign(black_box(expires_in));
let _ = url;
})
});
});
}

Expand Down
3 changes: 2 additions & 1 deletion src/actions/create_bucket.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ pub struct CreateBucket<'a> {
}

impl<'a> CreateBucket<'a> {
pub fn new(bucket: &'a Bucket, credentials: &'a Credentials) -> Self {
#[must_use]
pub const fn new(bucket: &'a Bucket, credentials: &'a Credentials) -> Self {
Self {
bucket,
credentials,
Expand Down
3 changes: 2 additions & 1 deletion src/actions/delete_bucket.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ pub struct DeleteBucket<'a> {
}

impl<'a> DeleteBucket<'a> {
pub fn new(bucket: &'a Bucket, credentials: &'a Credentials) -> Self {
#[must_use]
pub const fn new(bucket: &'a Bucket, credentials: &'a Credentials) -> Self {
Self {
bucket,
credentials,
Expand Down
7 changes: 6 additions & 1 deletion src/actions/delete_object.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,12 @@ pub struct DeleteObject<'a> {

impl<'a> DeleteObject<'a> {
#[inline]
pub fn new(bucket: &'a Bucket, credentials: Option<&'a Credentials>, object: &'a str) -> Self {
#[must_use]
pub const fn new(
bucket: &'a Bucket,
credentials: Option<&'a Credentials>,
object: &'a str,
) -> Self {
Self {
bucket,
credentials,
Expand Down
9 changes: 7 additions & 2 deletions src/actions/delete_objects.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ pub struct DeleteObjects<'a, I> {

impl<'a, I> DeleteObjects<'a, I> {
#[inline]
pub fn new(bucket: &'a Bucket, credentials: Option<&'a Credentials>, objects: I) -> Self {
pub const fn new(bucket: &'a Bucket, credentials: Option<&'a Credentials>, objects: I) -> Self {
Self {
bucket,
credentials,
Expand All @@ -41,7 +41,7 @@ impl<'a, I> DeleteObjects<'a, I> {
}
}

pub fn quiet(&self) -> bool {
pub const fn quiet(&self) -> bool {
self.quiet
}

Expand All @@ -57,6 +57,7 @@ pub struct ObjectIdentifier {
}

impl ObjectIdentifier {
#[must_use]
pub fn new(key: String) -> Self {
Self {
key,
Expand All @@ -69,6 +70,10 @@ impl<'a, I> DeleteObjects<'a, I>
where
I: Iterator<Item = &'a ObjectIdentifier>,
{
/// Generate the XML body for the request.
///
/// # Panics
/// Panics if an index is not representable as a `u16`.
pub fn body_with_md5(self) -> (String, String) {
#[derive(Serialize)]
#[serde(rename = "Delete")]
Expand Down
7 changes: 6 additions & 1 deletion src/actions/get_bucket_policy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ pub struct GetBucketPolicy<'a> {
headers: Map<'a>,
}

#[allow(clippy::module_name_repetitions)]
#[derive(Debug, Clone, Deserialize, PartialEq, Eq)]
pub struct GetBucketPolicyResponse {
#[serde(rename = "Version")]
Expand All @@ -37,7 +38,8 @@ pub struct GetBucketPolicyResponse {

impl<'a> GetBucketPolicy<'a> {
#[inline]
pub fn new(bucket: &'a Bucket, credentials: Option<&'a Credentials>) -> Self {
#[must_use]
pub const fn new(bucket: &'a Bucket, credentials: Option<&'a Credentials>) -> Self {
Self {
bucket,
credentials,
Expand All @@ -47,6 +49,9 @@ impl<'a> GetBucketPolicy<'a> {
}
}

/// Parse the response from S3.
/// # Errors
/// If the response cannot be parsed.
pub fn parse_response(s: &str) -> Result<GetBucketPolicyResponse, serde_json::Error> {
serde_json::from_str(s)
}
Expand Down
7 changes: 6 additions & 1 deletion src/actions/get_object.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,12 @@ pub struct GetObject<'a> {

impl<'a> GetObject<'a> {
#[inline]
pub fn new(bucket: &'a Bucket, credentials: Option<&'a Credentials>, object: &'a str) -> Self {
#[must_use]
pub const fn new(
bucket: &'a Bucket,
credentials: Option<&'a Credentials>,
object: &'a str,
) -> Self {
Self {
bucket,
credentials,
Expand Down
3 changes: 2 additions & 1 deletion src/actions/head_bucket.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ pub struct HeadBucket<'a> {

impl<'a> HeadBucket<'a> {
#[inline]
pub fn new(bucket: &'a Bucket, credentials: Option<&'a Credentials>) -> Self {
#[must_use]
pub const fn new(bucket: &'a Bucket, credentials: Option<&'a Credentials>) -> Self {
Self {
bucket,
credentials,
Expand Down
7 changes: 6 additions & 1 deletion src/actions/head_object.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,12 @@ pub struct HeadObject<'a> {

impl<'a> HeadObject<'a> {
#[inline]
pub fn new(bucket: &'a Bucket, credentials: Option<&'a Credentials>, object: &'a str) -> Self {
#[must_use]
pub const fn new(
bucket: &'a Bucket,
credentials: Option<&'a Credentials>,
object: &'a str,
) -> Self {
Self {
bucket,
credentials,
Expand Down
26 changes: 16 additions & 10 deletions src/actions/list_objects_v2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ use crate::{Bucket, Credentials, Map};
/// Find out more about `ListObjectsV2` from the [AWS API Reference][api]
///
/// [api]: https://docs.aws.amazon.com/AmazonS3/latest/API/API_ListObjectsV2.html
#[allow(clippy::module_name_repetitions)]
#[derive(Debug, Clone)]
pub struct ListObjectsV2<'a> {
bucket: &'a Bucket,
Expand All @@ -29,6 +30,7 @@ pub struct ListObjectsV2<'a> {
headers: Map<'a>,
}

#[allow(clippy::module_name_repetitions)]
#[derive(Debug, Clone, Deserialize)]
pub struct ListObjectsV2Response {
// #[serde(rename = "IsTruncated")]
Expand Down Expand Up @@ -90,6 +92,7 @@ pub struct CommonPrefixes {
}

impl<'a> ListObjectsV2<'a> {
#[must_use]
pub fn new(bucket: &'a Bucket, credentials: Option<&'a Credentials>) -> Self {
let mut query = Map::new();
query.insert("list-type", "2");
Expand All @@ -106,7 +109,7 @@ impl<'a> ListObjectsV2<'a> {

/// Limits the response to keys that begin with the specified prefix.
///
/// See https://docs.aws.amazon.com/AmazonS3/latest/API/API_ListObjectsV2.html#API_ListObjectsV2_RequestSyntax for more infos.
/// See <https://docs.aws.amazon.com/AmazonS3/latest/API/API_ListObjectsV2.html#API_ListObjectsV2_RequestSyntax> for more infos.
/// # Example
/// ```
/// # let bucket = rusty_s3::Bucket::new(url::Url::parse("http://rusty_s3/").unwrap(), rusty_s3::UrlStyle::Path, "doggo", "doggoland").unwrap();
Expand All @@ -119,7 +122,7 @@ impl<'a> ListObjectsV2<'a> {

/// A delimiter is a character that you use to group keys.
///
/// See https://docs.aws.amazon.com/AmazonS3/latest/API/API_ListObjectsV2.html#API_ListObjectsV2_RequestSyntax for more infos.
/// See <https://docs.aws.amazon.com/AmazonS3/latest/API/API_ListObjectsV2.html#API_ListObjectsV2_RequestSyntax> for more infos.
/// # Example
/// ```
/// # let bucket = rusty_s3::Bucket::new(url::Url::parse("http://rusty_s3/").unwrap(), rusty_s3::UrlStyle::Path, "doggo", "doggoland").unwrap();
Expand All @@ -130,11 +133,11 @@ impl<'a> ListObjectsV2<'a> {
self.query_mut().insert("delimiter", delimiter);
}

/// StartAfter is where you want Amazon S3 to start listing from.
/// `StartAfter` is where you want Amazon S3 to start listing from.
/// Amazon S3 starts listing after this specified key.
/// StartAfter can be any key in the bucket.
/// `StartAfter` can be any key in the bucket.
///
/// See https://docs.aws.amazon.com/AmazonS3/latest/API/API_ListObjectsV2.html#API_ListObjectsV2_RequestSyntax for more infos.
/// See <https://docs.aws.amazon.com/AmazonS3/latest/API/API_ListObjectsV2.html#API_ListObjectsV2_RequestSyntax> for more infos.
/// # Example
/// ```
/// # let bucket = rusty_s3::Bucket::new(url::Url::parse("http://rusty_s3/").unwrap(), rusty_s3::UrlStyle::Path, "doggo", "doggoland").unwrap();
Expand All @@ -145,10 +148,10 @@ impl<'a> ListObjectsV2<'a> {
self.query_mut().insert("start-after", start_after);
}

/// ContinuationToken indicates to Amazon S3 that the list is being continued on this bucket with a token.
/// ContinuationToken is obfuscated and is not a real key.
/// `ContinuationToken` indicates to Amazon S3 that the list is being continued on this bucket with a token.
/// `ContinuationToken` is obfuscated and is not a real key.
///
/// See https://docs.aws.amazon.com/AmazonS3/latest/API/API_ListObjectsV2.html#API_ListObjectsV2_RequestSyntax for more infos.
/// See <https://docs.aws.amazon.com/AmazonS3/latest/API/API_ListObjectsV2.html#API_ListObjectsV2_RequestSyntax> for more infos.
/// # Example
/// ```
/// # let bucket = rusty_s3::Bucket::new(url::Url::parse("http://rusty_s3/").unwrap(), rusty_s3::UrlStyle::Path, "doggo", "doggoland").unwrap();
Expand All @@ -164,7 +167,7 @@ impl<'a> ListObjectsV2<'a> {
/// By default, the action returns up to 1,000 key names.
/// The response might contain fewer keys but will never contain more.
///
/// See https://docs.aws.amazon.com/AmazonS3/latest/API/API_ListObjectsV2.html#API_ListObjectsV2_RequestSyntax for more infos.
/// See <https://docs.aws.amazon.com/AmazonS3/latest/API/API_ListObjectsV2.html#API_ListObjectsV2_RequestSyntax> for more infos.
/// # Example
/// ```
/// # let bucket = rusty_s3::Bucket::new(url::Url::parse("http://rusty_s3/").unwrap(), rusty_s3::UrlStyle::Path, "doggo", "doggoland").unwrap();
Expand All @@ -175,11 +178,14 @@ impl<'a> ListObjectsV2<'a> {
self.query_mut().insert("max-keys", max_keys.to_string());
}

/// Parse the response from S3.
/// # Errors
/// If the response cannot be parsed.
pub fn parse_response(s: &str) -> Result<ListObjectsV2Response, quick_xml::DeError> {
let mut parsed: ListObjectsV2Response = quick_xml::de::from_str(s)?;

// S3 returns an Owner with an empty DisplayName and ID when fetch-owner is disabled
for content in parsed.contents.iter_mut() {
for content in &mut parsed.contents {
if let Some(owner) = &content.owner {
if owner.id.is_empty() && owner.display_name.is_empty() {
content.owner = None;
Expand Down
4 changes: 3 additions & 1 deletion src/actions/multipart_upload/abort.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ use crate::{Bucket, Credentials, Map};
/// Find out more about `AbortMultipartUpload` from the [AWS API Reference][api]
///
/// [api]: https://docs.aws.amazon.com/AmazonS3/latest/API/API_AbortMultipartUpload.html
#[allow(clippy::module_name_repetitions)]
#[derive(Debug, Clone)]
pub struct AbortMultipartUpload<'a> {
bucket: &'a Bucket,
Expand All @@ -31,7 +32,8 @@ pub struct AbortMultipartUpload<'a> {

impl<'a> AbortMultipartUpload<'a> {
#[inline]
pub fn new(
#[must_use]
pub const fn new(
bucket: &'a Bucket,
credentials: Option<&'a Credentials>,
object: &'a str,
Expand Down
12 changes: 10 additions & 2 deletions src/actions/multipart_upload/complete.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ use crate::{Bucket, Credentials, Map};
/// Find out more about `CompleteMultipartUpload` from the [AWS API Reference][api]
///
/// [api]: https://docs.aws.amazon.com/AmazonS3/latest/API/API_CreateMultipartUpload.html
#[allow(clippy::module_name_repetitions)]
#[derive(Debug, Clone)]
pub struct CompleteMultipartUpload<'a, I> {
bucket: &'a Bucket,
Expand All @@ -31,7 +32,7 @@ pub struct CompleteMultipartUpload<'a, I> {

impl<'a, I> CompleteMultipartUpload<'a, I> {
#[inline]
pub fn new(
pub const fn new(
bucket: &'a Bucket,
credentials: Option<&'a Credentials>,
object: &'a str,
Expand All @@ -56,6 +57,10 @@ impl<'a, I> CompleteMultipartUpload<'a, I>
where
I: Iterator<Item = &'a str>,
{
/// Generate the XML body for the request.
///
/// # Panics
/// Panics if an index is not representable as a `u16`.
pub fn body(self) -> String {
#[derive(Serialize)]
#[serde(rename = "CompleteMultipartUpload")]
Expand All @@ -80,7 +85,10 @@ where
.etags
.enumerate()
.map(|(i, etag)| Part {
nodes: vec![Node::ETag(etag), Node::PartNumber(i as u16 + 1)],
nodes: vec![
Node::ETag(etag),
Node::PartNumber(u16::try_from(i).expect("convert to u16") + 1),
],
})
.collect::<Vec<_>>();

Expand Down
14 changes: 13 additions & 1 deletion src/actions/multipart_upload/create.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ use crate::{Bucket, Credentials, Map};
/// Find out more about `CreateMultipartUpload` from the [AWS API Reference][api]
///
/// [api]: https://docs.aws.amazon.com/AmazonS3/latest/API/API_CreateMultipartUpload.html
#[allow(clippy::module_name_repetitions)]
#[derive(Debug, Clone)]
pub struct CreateMultipartUpload<'a> {
bucket: &'a Bucket,
Expand All @@ -31,9 +32,11 @@ pub struct CreateMultipartUpload<'a> {
headers: Map<'a>,
}

#[allow(clippy::module_name_repetitions)]
#[derive(Debug, Clone)]
pub struct CreateMultipartUploadResponse(InnerCreateMultipartUploadResponse);

#[allow(clippy::module_name_repetitions)]
#[derive(Debug, Clone, Deserialize)]
struct InnerCreateMultipartUploadResponse {
#[serde(rename = "UploadId")]
Expand All @@ -42,7 +45,12 @@ struct InnerCreateMultipartUploadResponse {

impl<'a> CreateMultipartUpload<'a> {
#[inline]
pub fn new(bucket: &'a Bucket, credentials: Option<&'a Credentials>, object: &'a str) -> Self {
#[must_use]
pub const fn new(
bucket: &'a Bucket,
credentials: Option<&'a Credentials>,
object: &'a str,
) -> Self {
Self {
bucket,
credentials,
Expand All @@ -53,13 +61,17 @@ impl<'a> CreateMultipartUpload<'a> {
}
}

/// Parse the XML response from S3
/// # Errors
/// Will return an error if the body is not valid XML
pub fn parse_response(s: &str) -> Result<CreateMultipartUploadResponse, quick_xml::DeError> {
let parsed = quick_xml::de::from_str(s)?;
Ok(CreateMultipartUploadResponse(parsed))
}
}

impl CreateMultipartUploadResponse {
#[must_use]
pub fn upload_id(&self) -> &str {
&self.0.upload_id
}
Expand Down
Loading

0 comments on commit 9727c3a

Please sign in to comment.