silver-ymz commented on code in PR #3001:
URL: 
https://github.com/apache/incubator-opendal/pull/3001#discussion_r1313208015


##########
bindings/cpp/src/lib.rs:
##########
@@ -56,7 +83,120 @@ impl Operator {
         Ok(self.0.read(path)?)
     }
 
-    fn write(&self, path: &str, bs: &[u8]) -> Result<()> {
-        Ok(self.0.write(path, bs.to_owned())?)
+    // To avoid copying the bytes, we use &'static [u8] here.
+    //
+    // Safety: The bytes created from bs will be dropped after the function 
call.
+    // So it's safe to declare its lifetime as 'static.
+    fn write(&self, path: &str, bs: &'static [u8]) -> Result<()> {
+        Ok(self.0.write(path, bs)?)
+    }
+
+    fn is_exist(&self, path: &str) -> Result<bool> {
+        Ok(self.0.is_exist(path)?)
+    }
+
+    fn create_dir(&self, path: &str) -> Result<()> {
+        Ok(self.0.create_dir(path)?)
+    }
+
+    fn copy(&self, src: &str, dst: &str) -> Result<()> {
+        Ok(self.0.copy(src, dst)?)
+    }
+
+    fn rename(&self, src: &str, dst: &str) -> Result<()> {
+        Ok(self.0.rename(src, dst)?)
+    }
+
+    // We can't name it to delete because it's a keyword in C++
+    fn remove(&self, path: &str) -> Result<()> {
+        Ok(self.0.delete(path)?)
+    }
+
+    fn stat(&self, path: &str) -> Result<ffi::Metadata> {
+        Ok(self.0.stat(path)?.into())
+    }
+
+    fn list(&self, path: &str) -> Result<Vec<ffi::Entry>> {
+        Ok(self.0.list(path)?.into_iter().map(Into::into).collect())
+    }
+}
+
+impl From<od::Metadata> for ffi::Metadata {
+    fn from(meta: od::Metadata) -> Self {
+        let mut tag = 0u8;

Review Comment:
   The comment is on `struct Metadata`.
   
   
https://github.com/apache/incubator-opendal/blob/cpp-more-operation/bindings/cpp/src/lib.rs#L30-L36



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to