From 4aa0e573f3bdbcf2a39e83a82c075ce963ef0853 Mon Sep 17 00:00:00 2001 From: Trim21 Date: Thu, 26 Dec 2024 08:24:38 +0800 Subject: [PATCH] fix rust warning in python binding (#5459) --- bindings/python/src/file.rs | 31 ++++++++++++++++++++----------- bindings/python/src/operator.rs | 30 +++++++++++++++--------------- 2 files changed, 35 insertions(+), 26 deletions(-) diff --git a/bindings/python/src/file.rs b/bindings/python/src/file.rs index 2c2172324bb7..2b27e3f0a991 100644 --- a/bindings/python/src/file.rs +++ b/bindings/python/src/file.rs @@ -63,7 +63,11 @@ impl File { impl File { /// Read and return at most size bytes, or if size is not given, until EOF. #[pyo3(signature = (size=None,))] - pub fn read<'p>(&'p mut self, py: Python<'p>, size: Option) -> PyResult> { + pub fn read<'p>( + &'p mut self, + py: Python<'p>, + size: Option, + ) -> PyResult> { let reader = match &mut self.0 { FileState::Reader(r) => r, FileState::Writer(_) => { @@ -107,7 +111,7 @@ impl File { &'p mut self, py: Python<'p>, size: Option, - ) -> PyResult> { + ) -> PyResult> { let reader = match &mut self.0 { FileState::Reader(r) => r, FileState::Writer(_) => { @@ -352,7 +356,7 @@ impl AsyncFile { impl AsyncFile { /// Read and return at most size bytes, or if size is not given, until EOF. #[pyo3(signature = (size=None))] - pub fn read<'p>(&'p self, py: Python<'p>, size: Option) -> PyResult> { + pub fn read<'p>(&'p self, py: Python<'p>, size: Option) -> PyResult> { let state = self.0.clone(); future_into_py(py, async move { @@ -397,7 +401,7 @@ impl AsyncFile { } /// Write bytes into the file. - pub fn write<'p>(&'p mut self, py: Python<'p>, bs: &'p [u8]) -> PyResult> { + pub fn write<'p>(&'p mut self, py: Python<'p>, bs: &'p [u8]) -> PyResult> { let state = self.0.clone(); // FIXME: can we avoid this clone? @@ -438,7 +442,12 @@ impl AsyncFile { /// /// Return the new absolute position. #[pyo3(signature = (pos, whence = 0))] - pub fn seek<'p>(&'p mut self, py: Python<'p>, pos: i64, whence: u8) -> PyResult> { + pub fn seek<'p>( + &'p mut self, + py: Python<'p>, + pos: i64, + whence: u8, + ) -> PyResult> { let state = self.0.clone(); let whence = match whence { @@ -474,7 +483,7 @@ impl AsyncFile { } /// Return the current stream position. - pub fn tell<'p>(&'p mut self, py: Python<'p>) -> PyResult> { + pub fn tell<'p>(&'p mut self, py: Python<'p>) -> PyResult> { let state = self.0.clone(); future_into_py(py, async move { @@ -502,7 +511,7 @@ impl AsyncFile { .and_then(|pos| pos.into_bound_py_any(py)) } - fn close<'p>(&'p mut self, py: Python<'p>) -> PyResult> { + fn close<'p>(&'p mut self, py: Python<'p>) -> PyResult> { let state = self.0.clone(); future_into_py(py, async move { let mut state = state.lock().await; @@ -532,7 +541,7 @@ impl AsyncFile { } /// Check if the stream may be read from. - pub fn readable<'p>(&'p self, py: Python<'p>) -> PyResult> { + pub fn readable<'p>(&'p self, py: Python<'p>) -> PyResult> { let state = self.0.clone(); future_into_py(py, async move { let state = state.lock().await; @@ -541,7 +550,7 @@ impl AsyncFile { } /// Check if the stream may be written to. - pub fn writable<'p>(&'p self, py: Python<'p>) -> PyResult> { + pub fn writable<'p>(&'p self, py: Python<'p>) -> PyResult> { let state = self.0.clone(); future_into_py(py, async move { let state = state.lock().await; @@ -550,7 +559,7 @@ impl AsyncFile { } /// Check if the stream reader may be re-located. - pub fn seekable<'p>(&'p self, py: Python<'p>) -> PyResult> { + pub fn seekable<'p>(&'p self, py: Python<'p>) -> PyResult> { if true { self.readable(py) } else { @@ -560,7 +569,7 @@ impl AsyncFile { /// Check if the stream is closed. #[getter] - pub fn closed<'p>(&'p self, py: Python<'p>) -> PyResult> { + pub fn closed<'p>(&'p self, py: Python<'p>) -> PyResult> { let state = self.0.clone(); future_into_py(py, async move { let state = state.lock().await; diff --git a/bindings/python/src/operator.rs b/bindings/python/src/operator.rs index cfa58fe5a619..4cd53924407d 100644 --- a/bindings/python/src/operator.rs +++ b/bindings/python/src/operator.rs @@ -109,7 +109,7 @@ impl Operator { } /// Read the whole path into bytes. - pub fn read<'p>(&'p self, py: Python<'p>, path: &str) -> PyResult> { + pub fn read<'p>(&'p self, py: Python<'p>, path: &str) -> PyResult> { let buffer = self.core.read(path).map_err(format_pyerr)?.to_vec(); Buffer::new(buffer).into_bytes_ref(py) } @@ -287,7 +287,7 @@ impl AsyncOperator { py: Python<'p>, path: String, mode: String, - ) -> PyResult> { + ) -> PyResult> { let this = self.core.clone(); future_into_py(py, async move { @@ -312,7 +312,7 @@ impl AsyncOperator { } /// Read the whole path into bytes. - pub fn read<'p>(&'p self, py: Python<'p>, path: String) -> PyResult> { + pub fn read<'p>(&'p self, py: Python<'p>, path: String) -> PyResult> { let this = self.core.clone(); future_into_py(py, async move { let res: Vec = this.read(&path).await.map_err(format_pyerr)?.to_vec(); @@ -328,7 +328,7 @@ impl AsyncOperator { path: String, bs: &Bound, kwargs: Option, - ) -> PyResult> { + ) -> PyResult> { let kwargs = kwargs.unwrap_or_default(); let this = self.core.clone(); let bs = bs.as_bytes().to_vec(); @@ -351,7 +351,7 @@ impl AsyncOperator { } /// Get current path's metadata **without cache** directly. - pub fn stat<'p>(&'p self, py: Python<'p>, path: String) -> PyResult> { + pub fn stat<'p>(&'p self, py: Python<'p>, path: String) -> PyResult> { let this = self.core.clone(); future_into_py(py, async move { let res: Metadata = this @@ -370,7 +370,7 @@ impl AsyncOperator { py: Python<'p>, source: String, target: String, - ) -> PyResult> { + ) -> PyResult> { let this = self.core.clone(); future_into_py(py, async move { this.copy(&source, &target).await.map_err(format_pyerr) @@ -383,7 +383,7 @@ impl AsyncOperator { py: Python<'p>, source: String, target: String, - ) -> PyResult> { + ) -> PyResult> { let this = self.core.clone(); future_into_py(py, async move { this.rename(&source, &target).await.map_err(format_pyerr) @@ -391,7 +391,7 @@ impl AsyncOperator { } /// Remove all file - pub fn remove_all<'p>(&'p self, py: Python<'p>, path: String) -> PyResult> { + pub fn remove_all<'p>(&'p self, py: Python<'p>, path: String) -> PyResult> { let this = self.core.clone(); future_into_py(py, async move { this.remove_all(&path).await.map_err(format_pyerr) @@ -410,7 +410,7 @@ impl AsyncOperator { /// /// - Create on existing dir will succeed. /// - Create dir is always recursive, works like `mkdir -p` - pub fn create_dir<'p>(&'p self, py: Python<'p>, path: String) -> PyResult> { + pub fn create_dir<'p>(&'p self, py: Python<'p>, path: String) -> PyResult> { let this = self.core.clone(); future_into_py(py, async move { this.create_dir(&path).await.map_err(format_pyerr) @@ -422,7 +422,7 @@ impl AsyncOperator { /// # Notes /// /// - Delete not existing error won't return errors. - pub fn delete<'p>(&'p self, py: Python<'p>, path: String) -> PyResult> { + pub fn delete<'p>(&'p self, py: Python<'p>, path: String) -> PyResult> { let this = self.core.clone(); future_into_py( py, @@ -431,7 +431,7 @@ impl AsyncOperator { } /// List current dir path. - pub fn list<'p>(&'p self, py: Python<'p>, path: String) -> PyResult> { + pub fn list<'p>(&'p self, py: Python<'p>, path: String) -> PyResult> { let this = self.core.clone(); future_into_py(py, async move { let lister = this.lister(&path).await.map_err(format_pyerr)?; @@ -442,7 +442,7 @@ impl AsyncOperator { } /// List dir in flat way. - pub fn scan<'p>(&'p self, py: Python<'p>, path: String) -> PyResult> { + pub fn scan<'p>(&'p self, py: Python<'p>, path: String) -> PyResult> { let this = self.core.clone(); future_into_py(py, async move { let lister = this @@ -462,7 +462,7 @@ impl AsyncOperator { py: Python<'p>, path: String, expire_second: u64, - ) -> PyResult> { + ) -> PyResult> { let this = self.core.clone(); future_into_py(py, async move { let res = this @@ -481,7 +481,7 @@ impl AsyncOperator { py: Python<'p>, path: String, expire_second: u64, - ) -> PyResult> { + ) -> PyResult> { let this = self.core.clone(); future_into_py(py, async move { let res = this @@ -500,7 +500,7 @@ impl AsyncOperator { py: Python<'p>, path: String, expire_second: u64, - ) -> PyResult> { + ) -> PyResult> { let this = self.core.clone(); future_into_py(py, async move { let res = this