Skip to content

Commit efc7e08

Browse files
committed
Keep string representation
1 parent e43714d commit efc7e08

File tree

1 file changed

+23
-6
lines changed

1 file changed

+23
-6
lines changed

commons/zenoh-protocol/src/core/whatami.rs

+23-6
Original file line numberDiff line numberDiff line change
@@ -142,12 +142,11 @@ impl WhatAmIMatcher {
142142
Self::U8_R => WhatAmI::STR_R,
143143
Self::U8_P => WhatAmI::STR_P,
144144
Self::U8_C => WhatAmI::STR_C,
145-
Self::U8_R_P => formatcp!("[{},{}]", WhatAmI::STR_R, WhatAmI::STR_P),
146-
Self::U8_R_C => formatcp!("[{},{}]", WhatAmI::STR_R, WhatAmI::STR_C),
147-
Self::U8_P_C => formatcp!("[{},{}]", WhatAmI::STR_P, WhatAmI::STR_C),
148-
Self::U8_R_P_C => {
149-
formatcp!("[{},{},{}]", WhatAmI::STR_R, WhatAmI::STR_P, WhatAmI::STR_C)
150-
}
145+
Self::U8_R_P => formatcp!("{}|{}", WhatAmI::STR_R, WhatAmI::STR_P),
146+
Self::U8_R_C => formatcp!("{}|{}", WhatAmI::STR_R, WhatAmI::STR_C),
147+
Self::U8_P_C => formatcp!("{}|{}", WhatAmI::STR_P, WhatAmI::STR_C),
148+
Self::U8_R_P_C => formatcp!("{}|{}|{}", WhatAmI::STR_R, WhatAmI::STR_P, WhatAmI::STR_C),
149+
151150
_ => unreachable!(),
152151
}
153152
}
@@ -188,6 +187,24 @@ impl TryFrom<u8> for WhatAmIMatcher {
188187
}
189188
}
190189

190+
impl FromStr for WhatAmIMatcher {
191+
type Err = ();
192+
193+
fn from_str(s: &str) -> Result<Self, Self::Err> {
194+
let mut inner = 0;
195+
for s in s.split('|') {
196+
match s.trim() {
197+
"" => {}
198+
WhatAmI::STR_R => inner |= WhatAmI::U8_R,
199+
WhatAmI::STR_P => inner |= WhatAmI::U8_P,
200+
WhatAmI::STR_C => inner |= WhatAmI::U8_C,
201+
_ => return Err(()),
202+
}
203+
}
204+
Self::try_from(inner)
205+
}
206+
}
207+
191208
impl fmt::Display for WhatAmIMatcher {
192209
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
193210
f.write_str(self.to_str())

0 commit comments

Comments
 (0)