From c91eb7fba73709a974ca8c7b91c7a429dae82118 Mon Sep 17 00:00:00 2001 From: fdb-hiroshima <35889323+fdb-hiroshima@users.noreply.github.com> Date: Sat, 27 Jul 2019 10:58:43 +0200 Subject: [PATCH] add to_path for Facet (#604) fix #580 --- src/schema/facet.rs | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/schema/facet.rs b/src/schema/facet.rs index 4477982ee..a77146fc2 100644 --- a/src/schema/facet.rs +++ b/src/schema/facet.rs @@ -117,6 +117,13 @@ impl Facet { && other_str.starts_with(self_str) && other_str.as_bytes()[self_str.len()] == FACET_SEP_BYTE } + + /// Extract path from the `Facet`. + pub fn to_path(&self) -> Vec<&str> { + self.encoded_str() + .split(|c| c == FACET_SEP_CHAR) + .collect() + } } impl Borrow for Facet { @@ -254,4 +261,10 @@ mod tests { assert_eq!(format!("{:?}", facet), "Facet(/first/second/third)"); } + #[test] + fn test_to_path() { + let v = ["first", "second", "third\\/not_fourth"]; + let facet = Facet::from_path(v.iter()); + assert_eq!(facet.to_path(), v); + } }