diff --git a/.vscode/tasks.json b/.vscode/tasks.json new file mode 100644 index 0000000..1b38da9 --- /dev/null +++ b/.vscode/tasks.json @@ -0,0 +1,80 @@ +{ + "version": "2.0.0", + "tasks": [ + { + "label": "Build Project", + "type": "cargo", + "command": "build", + "presentation": { + "reveal": "silent" + }, + "problemMatcher": "$rustc", + "group": "build" + }, + { + "label": "Run Project", + "type": "cargo", + "command": "run", + "dependsOn": [ + "Build Project" + ], + "args": [ + "--bin=shrupl", + "--package=shrupl" + ], + "env": { + "RUST_LOG": "shrupl=info", + }, + "problemMatcher": "$rustc", + "group": "none" + }, + { + "label": "Clippy Fix Project", + "type": "cargo", + "command": "clippy", + "args": [ + "--fix", + "--bin=shrupl", + "--package=shrupl", + "--allow-dirty", + "--allow-staged", + "--", + "-Wclippy::pedantic" + ], + "problemMatcher": "$rustc", + "group": "build" + }, + // { + // "label": "Run Unit Tests", + // "type": "cargo", + // "command": "test", + // "args": [ + // "--lib" + // ], + // "problemMatcher": "$rustc", + // "group": "test" + // }, + // { + // "label": "Run Integration Tests", + // "type": "cargo", + // "command": "test", + // "args": [ + // "--test", + // "integration" + // ], + // "problemMatcher": "$rustc", + // "group": "test" + // }, + // { + // "label": "Run All Tests", + // "type": "shell", + // "command": "echo All Tests successful!", + // "dependsOn": [ + // "Run Unit Tests", + // "Run Integration Tests" + // ], + // "dependsOrder": "sequence", + // "group": "test" + // } + ], +} \ No newline at end of file diff --git a/src/main.rs b/src/main.rs index 87ed3bc..0488d9a 100644 --- a/src/main.rs +++ b/src/main.rs @@ -20,15 +20,15 @@ fn main() { let share = NewShareRequest::new(Some("foo"), "", 10); let share = Share::create(&agent, &alias, share).unwrap(); - info!("share: {:?}", share); + info!("share: {share:?}"); let file = File::create(&agent, &share, "/lib/x86_64-linux-gnu/liblldb-14.so.1").unwrap(); - info!("file: {:?}", file); + info!("file: {file:?}"); for chunk in file.chunked(10 * 1024 * 1024) { println!("chunk len: {}", chunk.bytes.len()); - file.upload_chunk(&agent, chunk) - .inspect_err(|e| error!("error: {}", e)) + file.upload_chunk(&agent, &chunk) + .inspect_err(|e| error!("error: {e}")) .unwrap(); } diff --git a/src/sharry/alias.rs b/src/sharry/alias.rs index 8ebdcb2..5f71225 100644 --- a/src/sharry/alias.rs +++ b/src/sharry/alias.rs @@ -3,7 +3,7 @@ use std::fmt::{Debug, Display}; use log::debug; use ureq::RequestBuilder; -use super::api::URI; +use super::api::Uri; #[derive(Debug)] pub struct Alias { @@ -22,7 +22,7 @@ impl SharryAlias for RequestBuilder { } impl Alias { - pub fn new(api_uri: URI, id: impl Into) -> Self { + pub fn new(api_uri: Uri, id: impl Into) -> Self { Self { api_uri: api_uri.into(), id: id.into(), @@ -31,7 +31,7 @@ impl Alias { pub(super) fn get_endpoint(&self, endpoint: impl Display + Debug) -> String { let uri = format!("{}/{}", self.api_uri, endpoint); - debug!("endpoint uri: {:?}", uri); + debug!("endpoint uri: {uri:?}"); uri } diff --git a/src/sharry/api.rs b/src/sharry/api.rs index 21bf636..bd2a6dc 100644 --- a/src/sharry/api.rs +++ b/src/sharry/api.rs @@ -1,11 +1,11 @@ use serde::{Deserialize, Serialize}; -pub struct URI { +pub struct Uri { protocol: String, base_url: String, } -impl URI { +impl Uri { pub fn with_protocol(protocol: impl Into, base_url: impl Into) -> Self { Self { protocol: protocol.into(), @@ -14,15 +14,15 @@ impl URI { } } -impl From<&str> for URI { +impl From<&str> for Uri { fn from(value: &str) -> Self { Self::with_protocol("https", value) } } -impl Into for URI { - fn into(self) -> String { - format!("{}://{}/api/v2", self.protocol, self.base_url) +impl From for String { + fn from(val: Uri) -> Self { + format!("{}://{}/api/v2", val.protocol, val.base_url) } } diff --git a/src/sharry/chunkedfile.rs b/src/sharry/chunkedfile.rs index 0c5b1ea..b135e6f 100644 --- a/src/sharry/chunkedfile.rs +++ b/src/sharry/chunkedfile.rs @@ -22,7 +22,7 @@ impl<'t> ChunkedFile<'t> { } } -impl<'t> Iterator for ChunkedFile<'t> { +impl Iterator for ChunkedFile<'_> { type Item = Chunk; fn next(&mut self) -> Option { @@ -31,21 +31,21 @@ impl<'t> Iterator for ChunkedFile<'t> { self.cnum * csize }; - let mut f = File::open(&self.path) - .inspect_err(|e| error!("Error opening file: {}", e)) + let mut f = File::open(self.path) + .inspect_err(|e| error!("Error opening file: {e}")) .ok()?; f.seek(SeekFrom::Start(offset)).ok()?; let mut bytes = vec![0; self.csize]; let read_len = f .read(&mut bytes) - .inspect_err(|e| error!("Error reading file: {}", e)) + .inspect_err(|e| error!("Error reading file: {e}")) .ok()?; bytes.truncate(read_len); self.cnum += 1; - Some(Self::Item { offset, bytes }).filter(|c| c.bytes.len() > 0) + Some(Self::Item { offset, bytes }).filter(|c| !c.bytes.is_empty()) } } diff --git a/src/sharry/file.rs b/src/sharry/file.rs index 9a185e3..b52b915 100644 --- a/src/sharry/file.rs +++ b/src/sharry/file.rs @@ -17,7 +17,7 @@ use super::{ #[derive(Debug)] pub struct File<'t> { alias: &'t Alias, - file_path: PathBuf, + path: PathBuf, patch_uri: String, } @@ -25,10 +25,10 @@ impl<'t> File<'t> { pub fn create( http: &ureq::Agent, share: &'t Share, - file_path: impl Into, + path: impl Into, ) -> Result { - let file_path: PathBuf = file_path.into(); - let filename = file_path + let path: PathBuf = path.into(); + let filename = path .file_name() .and_then(OsStr::to_str) .unwrap_or("file.bin"); @@ -41,7 +41,7 @@ impl<'t> File<'t> { .post(endpoint) .sharry_header(share.alias) .header("Sharry-File-Name", filename) - .header("Upload-Length", metadata(&file_path)?.len()) + .header("Upload-Length", metadata(&path)?.len()) .send_empty()?; if res.status() != StatusCode::CREATED { @@ -55,20 +55,20 @@ impl<'t> File<'t> { .to_str() .map_err(|_| Other("Location header invalid".into()))?; - debug!("location: {}", location); + debug!("location: {location}"); Ok(Self { alias: share.alias, - file_path, + path, patch_uri: location.into(), }) } pub fn chunked(&self, chunk_size: usize) -> ChunkedFile { - ChunkedFile::new(&self.file_path, chunk_size) + ChunkedFile::new(&self.path, chunk_size) } - pub fn upload_chunk(&self, http: &ureq::Agent, chunk: Chunk) -> Result<(), ureq::Error> { + pub fn upload_chunk(&self, http: &ureq::Agent, chunk: &Chunk) -> Result<(), ureq::Error> { debug!("upload uri: {:?}", self.patch_uri); let res = http diff --git a/src/sharry/mod.rs b/src/sharry/mod.rs index ceb2c08..cdc9014 100644 --- a/src/sharry/mod.rs +++ b/src/sharry/mod.rs @@ -7,6 +7,6 @@ mod file; mod share; pub use alias::Alias; -pub use api::{NewShareRequest, URI}; +pub use api::{NewShareRequest, Uri}; pub use file::File; pub use share::Share; diff --git a/src/sharry/share.rs b/src/sharry/share.rs index 3102315..f5b385b 100644 --- a/src/sharry/share.rs +++ b/src/sharry/share.rs @@ -24,7 +24,7 @@ impl<'t> Share<'t> { .body_mut() .read_json::()?; - debug!("response: {:?}", res); + debug!("response: {res:?}"); if !(res.success && (res.message == "Share created.")) { return Err(ureq::Error::Other("unexpected json response".into())); @@ -45,7 +45,7 @@ impl<'t> Share<'t> { .body_mut() .read_json::()?; - debug!("response: {:?}", res); + debug!("response: {res:?}"); Ok(()) }