Added Result type and minor consistency changes

This commit is contained in:
foreverpyrite
2025-10-16 00:52:01 +00:00
parent 5b8ad30198
commit d73cc39585
7 changed files with 23 additions and 3 deletions

View File

@@ -2,6 +2,7 @@
name = "aws_sigv4" name = "aws_sigv4"
version = "0.1.0" version = "0.1.0"
edition = "2024" edition = "2024"
authors = ["foreverpyrite <r2client@foreverpyrite.com"]
description = "Minimal-dependancy library to sign requests via AWS's SigV4." description = "Minimal-dependancy library to sign requests via AWS's SigV4."
[lib] [lib]

View File

@@ -2,7 +2,7 @@
name = "r2client" name = "r2client"
version = "0.2.0" version = "0.2.0"
edition = "2024" edition = "2024"
authors = ["ForeverPyrite <r2@foreverpyrite.com"] authors = ["foreverpyrite <r2client@foreverpyrite.com"]
[lib] [lib]

View File

@@ -7,6 +7,19 @@ use reqwest::header::HeaderMap;
use std::collections::HashMap; use std::collections::HashMap;
use std::str::FromStr; use std::str::FromStr;
// I wonder if something like this would be better for error handling instead of a hardcoded
// string?
// Of course it'll only be for this codebase, but it would make the code more maintainable, right?
// #[derive(Debug)]
// enum R2Operation {
// Delete,
// Download,
// Upload,
// ListFiles,
// ListAll
// }
#[derive(Debug)] #[derive(Debug)]
pub struct R2Client { pub struct R2Client {
sigv4: SigV4Credentials, sigv4: SigV4Credentials,
@@ -66,7 +79,7 @@ impl R2Client {
local_file_path: &str, local_file_path: &str,
r2_file_key: &str, r2_file_key: &str,
content_type: Option<&str>, content_type: Option<&str>,
) -> Result<(), R2Error> { ) -> crate::Result {
// Payload (file data) // Payload (file data)
let payload = std::fs::read(local_file_path)?; let payload = std::fs::read(local_file_path)?;
trace!( trace!(

View File

@@ -13,3 +13,5 @@ pub enum R2Error {
#[error("Request failed during operation {0}: {1}\n{2}")] #[error("Request failed during operation {0}: {1}\n{2}")]
FailedRequest(String, http::StatusCode, String), FailedRequest(String, http::StatusCode, String),
} }
pub type Result = std::result::Result<(), R2Error>;

View File

@@ -1,6 +1,8 @@
mod error; mod error;
mod mimetypes; mod mimetypes;
pub use error::R2Error; // Should r2client::Result be r2client::R2Result just in case someone does a glob import or
// something? Or should that be left to the user of the library to use the "as" keyword?
pub use error::{R2Error, Result};
mod _async; mod _async;
#[cfg(feature = "async")] #[cfg(feature = "async")]

View File

@@ -4,6 +4,7 @@
- [ ] A way to view the file contents (UTF-8 valid) would be cool - [ ] A way to view the file contents (UTF-8 valid) would be cool
- [ ] Add functions that will list files with their metadata (perhaps a simple R2File type?) - [ ] Add functions that will list files with their metadata (perhaps a simple R2File type?)
- [ ] Clear out all all print statements and consider logging (this is a library, after all) - [ ] Clear out all all print statements and consider logging (this is a library, after all)
- [ ] How should buckets act in a multi-threaded environment if they are stored in an Arc or something?
## Dev (since we're so back): ## Dev (since we're so back):
- [X] Update the sync library - [X] Update the sync library

View File

@@ -2,6 +2,7 @@
name = "r2python" name = "r2python"
version = "0.1.0" version = "0.1.0"
edition = "2024" edition = "2024"
authors = ["foreverpyrite <r2client@foreverpyrite.com"]
[dependencies] [dependencies]
pyo3 = "0.26.0" pyo3 = "0.26.0"