Skip to content

Commit

Permalink
witx: Add trait implementations to Id (WebAssembly#287)
Browse files Browse the repository at this point in the history
* witx: add AsRef implementation to witx::Id

* witx: add PartialEq implementations for Id
  • Loading branch information
katie.martin authored Jun 4, 2020
1 parent 2ccb606 commit 7d1f396
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions tools/witx/src/ast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,30 @@ impl Id {
}
}

impl AsRef<str> for Id {
fn as_ref(&self) -> &str {
self.0.as_ref()
}
}

impl PartialEq<&str> for Id {
fn eq(&self, rhs: &&str) -> bool {
PartialEq::eq(self.as_ref(), *rhs)
}
}

impl PartialEq<Id> for &str {
fn eq(&self, rhs: &Id) -> bool {
PartialEq::eq(*self, rhs.as_ref())
}
}

impl From<&str> for Id {
fn from(s: &str) -> Self {
Self::new(s)
}
}

#[derive(Debug, Clone)]
pub struct Document {
definitions: Vec<Definition>,
Expand Down

0 comments on commit 7d1f396

Please sign in to comment.