Xuanwo commented on code in PR #641:
URL: https://github.com/apache/iceberg-rust/pull/641#discussion_r1770894847
##########
crates/iceberg/src/catalog/mod.rs:
##########
@@ -133,6 +133,16 @@ impl NamespaceIdent {
pub fn inner(self) -> Vec<String> {
self.0
}
+
+ /// Get the parent of this namespace.
+ /// Returns None if this namespace only has a single element and thus has
no parent.
+ pub fn parent(&self) -> Option<Self> {
+ if self.0.len() <= 1 {
+ None
+ } else {
+ Some(Self(self.0[..self.0.len() - 1].to_vec()))
+ }
+ }
Review Comment:
How about using
[split_last](https://doc.rust-lang.org/stable/std/primitive.slice.html#method.split_last)?
So that we have:
```rust
pub fn parent(&self) -> Option<Self> {
let (parent, _) = self.0.split_last()?;
Some(Self(parent.to_vec()))
}
```
--
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]