Skip to content

Commit f8ddd2f

Browse files
durchjplatte
andauthored
More ergonomic local paths (#121)
* Allow types other than string slices for local paths (#119) * 0.26.0 Co-authored-by: Jonas Platte <jplatte@users.noreply.github.com>
1 parent 2e94658 commit f8ddd2f

File tree

2 files changed

+17
-8
lines changed

2 files changed

+17
-8
lines changed

s3/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "rust-s3"
3-
version = "0.25.0"
3+
version = "0.26.0"
44
authors = ["Drazen Urch"]
55
description = "Tiny Rust library for working with Amazon S3 and compatible object storage APIs"
66
repository = "https://github.com/durch/rust-s3"

s3/src/bucket.rs

+16-7
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ use tokio::io::AsyncWrite as TokioAsyncWrite;
2222
use reqwest::header::HeaderMap;
2323

2424
use async_std::fs::File;
25+
use async_std::path::Path;
2526

2627
/// # Example
2728
/// ```
@@ -335,19 +336,23 @@ impl Bucket {
335336
Ok(request.tokio_response_data_to_writer_future(writer).await?)
336337
}
337338

338-
pub async fn put_object_stream<S: AsRef<str>>(&self, path: &str, s3_path: S) -> Result<u16> {
339+
pub async fn put_object_stream(
340+
&self,
341+
path: impl AsRef<Path>,
342+
s3_path: impl AsRef<str>,
343+
) -> Result<u16> {
339344
let mut file = File::open(path).await?;
340-
self._put_object_stream(&mut file, s3_path).await
345+
self._put_object_stream(&mut file, s3_path.as_ref()).await
341346
}
342347

343-
async fn _put_object_stream<R: AsyncRead + Unpin, S: AsRef<str>>(
348+
async fn _put_object_stream<R: AsyncRead + Unpin>(
344349
&self,
345350
reader: &mut R,
346-
s3_path: S,
351+
s3_path: &str,
347352
) -> Result<u16> {
348353
let chunk_size: usize = 5_300_000; // min is 5_242_880;
349354
let command = Command::InitiateMultipartUpload;
350-
let path = format!("{}?uploads", s3_path.as_ref());
355+
let path = format!("{}?uploads", s3_path);
351356
let request = Request::new(self, &path, command);
352357
let (data, code) = request.response_data_future(false).await?;
353358
let msg: InitiateMultipartUploadResponse =
@@ -391,7 +396,7 @@ impl Bucket {
391396
let abort_path = format!("{}?uploadId={}", msg.key, &msg.upload_id);
392397
let abort_request = Request::new(self, &abort_path, abort);
393398
let (_, _code) = abort_request.response_data_future(false).await?;
394-
self.put_object(s3_path.as_ref(), chunk.as_slice()).await?;
399+
self.put_object(s3_path, chunk.as_slice()).await?;
395400
break;
396401
} else {
397402
part_number += 1;
@@ -512,7 +517,11 @@ impl Bucket {
512517
/// Ok(())
513518
/// }
514519
/// ```
515-
pub fn put_object_stream_blocking<S: AsRef<str>>(&self, path: &str, s3_path: S) -> Result<u16> {
520+
pub fn put_object_stream_blocking(
521+
&self,
522+
path: impl AsRef<Path>,
523+
s3_path: impl AsRef<str>,
524+
) -> Result<u16> {
516525
let mut rt = Runtime::new()?;
517526
Ok(rt.block_on(self.put_object_stream(path, s3_path))?)
518527
}

0 commit comments

Comments
 (0)