wasmstore_client/
path.rs

1use crate::*;
2
3#[derive(Debug, PartialEq, Eq, Clone, PartialOrd, Ord)]
4pub enum Path {
5    String(String),
6    Vec(Vec<String>),
7}
8
9impl From<String> for Path {
10    fn from(s: String) -> Self {
11        Path::String(s)
12    }
13}
14
15impl From<Hash> for Path {
16    fn from(s: Hash) -> Self {
17        Path::String(s.0)
18    }
19}
20
21impl From<&Hash> for Path {
22    fn from(s: &Hash) -> Self {
23        Path::String(s.0.clone())
24    }
25}
26
27impl From<Vec<String>> for Path {
28    fn from(s: Vec<String>) -> Self {
29        Path::Vec(s)
30    }
31}
32
33impl From<Vec<&str>> for Path {
34    fn from(v: Vec<&str>) -> Self {
35        Path::Vec(v.iter().map(|x| x.to_string()).collect())
36    }
37}
38
39impl From<&[&str]> for Path {
40    fn from(v: &[&str]) -> Self {
41        Path::Vec(v.iter().map(|x| x.to_string()).collect())
42    }
43}
44
45impl From<&str> for Path {
46    fn from(v: &str) -> Self {
47        Path::String(v.to_string())
48    }
49}
50
51impl ToString for Path {
52    fn to_string(&self) -> String {
53        match self {
54            Path::String(s) => s.clone(),
55            Path::Vec(v) => v.join("/"),
56        }
57    }
58}