From e088ec99841c11e60ce5f92240c6d4b26182f2f1 Mon Sep 17 00:00:00 2001 From: Julien Enoch Date: Fri, 30 Oct 2020 12:48:31 +0100 Subject: [PATCH] zenoh API: add Path::last_segment() --- zenoh/src/path.rs | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/zenoh/src/path.rs b/zenoh/src/path.rs index 428bb4fe2a..7bf9e0f195 100644 --- a/zenoh/src/path.rs +++ b/zenoh/src/path.rs @@ -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() {