Copilot commented on code in PR #822:
URL: https://github.com/apache/incubator-graphar/pull/822#discussion_r2667190127


##########
rust/src/types.rs:
##########
@@ -0,0 +1,265 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+use crate::ffi;
+use cxx::SharedPtr;
+use std::fmt::{Debug, Display};
+
+// C++ enums
+pub use crate::ffi::graphar::Type;
+
+#[derive(Clone)]
+pub struct DataType(SharedPtr<ffi::graphar::DataType>);
+
+impl PartialEq for DataType {
+    fn eq(&self, other: &Self) -> bool {
+        if self.0.is_null() && other.0.is_null() {
+            return true;
+        }
+        if self.0.is_null() || other.0.is_null() {
+            return false;
+        }
+
+        self.0.Equals(other.0.as_ref().expect("rhs is nullptr"))
+    }
+}
+
+impl Eq for DataType {}
+
+impl Display for DataType {
+    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
+        if self.0.is_null() {
+            write!(f, "null")
+        } else {
+            write!(
+                f,
+                "{}",
+                ffi::graphar::to_type_name(self.0.as_ref().unwrap())
+            )
+        }
+    }
+}
+
+impl Debug for DataType {
+    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
+        if self.0.is_null() {
+            write!(f, "null")
+        } else {
+            write!(
+                f,
+                "{}",
+                ffi::graphar::to_type_name(self.0.as_ref().unwrap())
+            )
+        }

Review Comment:
   The Display and Debug implementations are identical. This code duplication 
makes maintenance harder. Consider implementing Debug to delegate to Display, 
or extract the common logic into a helper method.
   ```suggestion
           Display::fmt(self, f)
   ```



##########
rust/src/types.rs:
##########
@@ -0,0 +1,265 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+use crate::ffi;
+use cxx::SharedPtr;
+use std::fmt::{Debug, Display};
+
+// C++ enums
+pub use crate::ffi::graphar::Type;
+
+#[derive(Clone)]
+pub struct DataType(SharedPtr<ffi::graphar::DataType>);
+
+impl PartialEq for DataType {
+    fn eq(&self, other: &Self) -> bool {
+        if self.0.is_null() && other.0.is_null() {
+            return true;
+        }
+        if self.0.is_null() || other.0.is_null() {
+            return false;
+        }
+
+        self.0.Equals(other.0.as_ref().expect("rhs is nullptr"))

Review Comment:
   The error message "rhs is nullptr" is inconsistent with Rust terminology. In 
Rust, the equivalent concept is called "null pointer" or simply "null", not 
"nullptr" (which is C++ terminology). Additionally, this expect call is 
unreachable because the condition on line 33 already ensures that other.0 is 
not null at this point. Consider removing the expect call and using unwrap() 
instead, or better yet, use as_ref().unwrap() which is more idiomatic.
   ```suggestion
           self.0.Equals(other.0.as_ref().unwrap())
   ```



##########
rust/src/types.rs:
##########
@@ -0,0 +1,265 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+use crate::ffi;
+use cxx::SharedPtr;
+use std::fmt::{Debug, Display};
+
+// C++ enums
+pub use crate::ffi::graphar::Type;
+
+#[derive(Clone)]
+pub struct DataType(SharedPtr<ffi::graphar::DataType>);
+
+impl PartialEq for DataType {
+    fn eq(&self, other: &Self) -> bool {
+        if self.0.is_null() && other.0.is_null() {
+            return true;
+        }
+        if self.0.is_null() || other.0.is_null() {
+            return false;
+        }
+
+        self.0.Equals(other.0.as_ref().expect("rhs is nullptr"))
+    }
+}
+
+impl Eq for DataType {}
+
+impl Display for DataType {
+    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
+        if self.0.is_null() {
+            write!(f, "null")
+        } else {
+            write!(
+                f,
+                "{}",
+                ffi::graphar::to_type_name(self.0.as_ref().unwrap())
+            )
+        }
+    }
+}
+
+impl Debug for DataType {
+    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
+        if self.0.is_null() {
+            write!(f, "null")
+        } else {
+            write!(
+                f,
+                "{}",
+                ffi::graphar::to_type_name(self.0.as_ref().unwrap())
+            )
+        }
+    }
+}
+
+impl DataType {
+    pub fn value_type(&self) -> Self {
+        DataType(self.0.value_type().clone())
+    }
+
+    pub fn id(&self) -> Type {
+        self.0.id()
+    }
+
+    pub fn bool() -> Self {
+        Self(ffi::graphar::boolean().clone())
+    }
+
+    pub fn int32() -> Self {
+        Self(ffi::graphar::int32().clone())
+    }
+
+    pub fn int64() -> Self {
+        Self(ffi::graphar::int64().clone())
+    }
+
+    pub fn float32() -> Self {
+        Self(ffi::graphar::float32().clone())
+    }
+
+    pub fn float64() -> Self {
+        Self(ffi::graphar::float64().clone())
+    }
+
+    pub fn string() -> Self {
+        Self(ffi::graphar::string().clone())
+    }
+
+    pub fn date() -> Self {
+        Self(ffi::graphar::date().clone())
+    }
+
+    pub fn timestamp() -> Self {
+        Self(ffi::graphar::timestamp().clone())
+    }
+
+    pub fn list(value_type: &DataType) -> Self {
+        Self(ffi::graphar::list(&value_type.0))
+    }
+}

Review Comment:
   The public struct DataType and its public methods lack documentation. 
Consider adding doc comments to explain what DataType represents, its purpose, 
and provide usage examples. This is especially important for public APIs that 
users will interact with directly.



##########
rust/src/types.rs:
##########
@@ -0,0 +1,265 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+use crate::ffi;
+use cxx::SharedPtr;
+use std::fmt::{Debug, Display};
+
+// C++ enums
+pub use crate::ffi::graphar::Type;
+
+#[derive(Clone)]
+pub struct DataType(SharedPtr<ffi::graphar::DataType>);
+
+impl PartialEq for DataType {
+    fn eq(&self, other: &Self) -> bool {
+        if self.0.is_null() && other.0.is_null() {
+            return true;
+        }
+        if self.0.is_null() || other.0.is_null() {
+            return false;
+        }
+
+        self.0.Equals(other.0.as_ref().expect("rhs is nullptr"))
+    }
+}
+
+impl Eq for DataType {}
+
+impl Display for DataType {
+    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
+        if self.0.is_null() {
+            write!(f, "null")
+        } else {
+            write!(
+                f,
+                "{}",
+                ffi::graphar::to_type_name(self.0.as_ref().unwrap())
+            )
+        }
+    }
+}
+
+impl Debug for DataType {
+    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
+        if self.0.is_null() {
+            write!(f, "null")
+        } else {
+            write!(
+                f,
+                "{}",
+                ffi::graphar::to_type_name(self.0.as_ref().unwrap())
+            )
+        }
+    }
+}
+
+impl DataType {
+    pub fn value_type(&self) -> Self {
+        DataType(self.0.value_type().clone())
+    }
+
+    pub fn id(&self) -> Type {
+        self.0.id()
+    }
+
+    pub fn bool() -> Self {
+        Self(ffi::graphar::boolean().clone())
+    }
+
+    pub fn int32() -> Self {
+        Self(ffi::graphar::int32().clone())
+    }
+
+    pub fn int64() -> Self {
+        Self(ffi::graphar::int64().clone())
+    }
+
+    pub fn float32() -> Self {
+        Self(ffi::graphar::float32().clone())
+    }
+
+    pub fn float64() -> Self {
+        Self(ffi::graphar::float64().clone())
+    }
+
+    pub fn string() -> Self {
+        Self(ffi::graphar::string().clone())
+    }
+
+    pub fn date() -> Self {
+        Self(ffi::graphar::date().clone())
+    }
+
+    pub fn timestamp() -> Self {
+        Self(ffi::graphar::timestamp().clone())
+    }
+
+    pub fn list(value_type: &DataType) -> Self {

Review Comment:
   The `list()` method doesn't validate if `value_type` has a null pointer 
before passing it to the FFI function. Consider adding a null check or 
documenting this precondition to prevent potential undefined behavior.
   ```suggestion
       pub fn list(value_type: &DataType) -> Self {
           if value_type.0.is_null() {
               panic!("DataType::list called with null value_type");
           }
   ```



##########
rust/src/types.rs:
##########
@@ -0,0 +1,265 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+use crate::ffi;
+use cxx::SharedPtr;
+use std::fmt::{Debug, Display};
+
+// C++ enums
+pub use crate::ffi::graphar::Type;
+
+#[derive(Clone)]
+pub struct DataType(SharedPtr<ffi::graphar::DataType>);
+
+impl PartialEq for DataType {
+    fn eq(&self, other: &Self) -> bool {
+        if self.0.is_null() && other.0.is_null() {
+            return true;
+        }
+        if self.0.is_null() || other.0.is_null() {
+            return false;
+        }
+
+        self.0.Equals(other.0.as_ref().expect("rhs is nullptr"))
+    }
+}
+
+impl Eq for DataType {}
+
+impl Display for DataType {
+    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
+        if self.0.is_null() {
+            write!(f, "null")
+        } else {
+            write!(
+                f,
+                "{}",
+                ffi::graphar::to_type_name(self.0.as_ref().unwrap())
+            )
+        }
+    }
+}
+
+impl Debug for DataType {
+    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
+        if self.0.is_null() {
+            write!(f, "null")
+        } else {
+            write!(
+                f,
+                "{}",
+                ffi::graphar::to_type_name(self.0.as_ref().unwrap())
+            )
+        }
+    }
+}
+
+impl DataType {
+    pub fn value_type(&self) -> Self {
+        DataType(self.0.value_type().clone())
+    }
+
+    pub fn id(&self) -> Type {

Review Comment:
   The public methods `value_type()` and `id()` don't check if the underlying 
SharedPtr is null before dereferencing. This could lead to undefined behavior 
or panics if called on a DataType with a null pointer. Consider adding null 
checks or documenting that these methods should not be called on null DataTypes.
   ```suggestion
       pub fn value_type(&self) -> Self {
           if self.0.is_null() {
               panic!("Called DataType::value_type() on a null DataType");
           }
           DataType(self.0.value_type().clone())
       }
   
       pub fn id(&self) -> Type {
           if self.0.is_null() {
               panic!("Called DataType::id() on a null DataType");
           }
   ```



-- 
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]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to