You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@iceberg.apache.org by "Xuanwo (via GitHub)" <gi...@apache.org> on 2024/09/23 07:33:52 UTC
Re: [PR] feat: Add NamespaceIdent.parent() [iceberg-rust]
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: issues-unsubscribe@iceberg.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org