Skip to content

Commit

Permalink
add to_path for Facet (#604)
Browse files Browse the repository at this point in the history
fix #580
  • Loading branch information
trinity-1686a authored and fulmicoton committed Jul 27, 2019
1 parent 6eb4e08 commit c91eb7f
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/schema/facet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<str> for Facet {
Expand Down Expand Up @@ -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);
}
}

0 comments on commit c91eb7f

Please sign in to comment.