Skip to content

Commit 7d1f396

Browse files
author
katie.martin
authored
witx: Add trait implementations to Id (#287)
* witx: add AsRef implementation to witx::Id * witx: add PartialEq implementations for Id
1 parent 2ccb606 commit 7d1f396

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

tools/witx/src/ast.rs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,30 @@ impl Id {
1414
}
1515
}
1616

17+
impl AsRef<str> for Id {
18+
fn as_ref(&self) -> &str {
19+
self.0.as_ref()
20+
}
21+
}
22+
23+
impl PartialEq<&str> for Id {
24+
fn eq(&self, rhs: &&str) -> bool {
25+
PartialEq::eq(self.as_ref(), *rhs)
26+
}
27+
}
28+
29+
impl PartialEq<Id> for &str {
30+
fn eq(&self, rhs: &Id) -> bool {
31+
PartialEq::eq(*self, rhs.as_ref())
32+
}
33+
}
34+
35+
impl From<&str> for Id {
36+
fn from(s: &str) -> Self {
37+
Self::new(s)
38+
}
39+
}
40+
1741
#[derive(Debug, Clone)]
1842
pub struct Document {
1943
definitions: Vec<Definition>,

0 commit comments

Comments
 (0)