Skip to content

Commit

Permalink
zenoh API: add Path::last_segment()
Browse files Browse the repository at this point in the history
  • Loading branch information
JEnoch committed Oct 30, 2020
1 parent cf33209 commit e088ec9
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions zenoh/src/path.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,15 @@ impl Path {
!self.p.starts_with('/')
}

/// Returns the last segment of this Path.
/// I.e.: the part after the last '/', or the complete Path if there is no '/'.
pub fn last_segment(&self) -> &str {
match self.p.rfind('/') {
Some(i) => &self.p[i + 1..],
None => self.p.as_str(),
}
}

/// Returns the concatenation of `prefix` with this Path.
pub fn with_prefix(&self, prefix: &Path) -> Self {
if self.is_relative() {
Expand Down

0 comments on commit e088ec9

Please sign in to comment.