Skip to content

Commit

Permalink
factorize as_str method
Browse files Browse the repository at this point in the history
this method is now generated by the wrap! macro
for all str-borrowing wrappers
  • Loading branch information
pchampin committed Jun 9, 2024
1 parent a65c19d commit e8bb39e
Show file tree
Hide file tree
Showing 5 changed files with 5 additions and 29 deletions.
5 changes: 0 additions & 5 deletions api/src/prefix/_wrapper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,6 @@ sophia_iri::wrap! { Prefix borrowing str :
Err(InvalidPrefix(prefix.borrow().to_string()))
}
}

/// Gets a reference to the underlying &str.
pub fn as_str(&self) -> &str {
self.0.borrow()
}
}

impl<T: Borrow<str>> IsPrefix for Prefix<T> {}
Expand Down
5 changes: 0 additions & 5 deletions api/src/term/bnode_id.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,6 @@ wrap! { BnodeId borrowing str :
Err(InvalidBnodeId(id.borrow().to_string()))
}
}

/// Gets a reference to the underlying &str.
pub fn as_str(&self) -> &str {
self.0.borrow()
}
}
/// This error is raised when trying to parse an invalid blank node identifier.
#[derive(Debug, Error)]
Expand Down
5 changes: 0 additions & 5 deletions api/src/term/var_name.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,6 @@ wrap! { VarName borrowing str :
Err(InvalidVarName(name.borrow().to_string()))
}
}

/// Gets a reference to the underlying &str.
pub fn as_str(&self) -> &str {
self.0.borrow()
}
}
/// This error is raised when trying to parse an invalid variable name.
#[derive(Debug, Error)]
Expand Down
9 changes: 5 additions & 4 deletions iri/src/_wrap_macro.rs
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,11 @@ macro_rules! wrap {
$new

$($item)*

/// Gets a reference to the underlying &str.
pub fn as_str(&self) -> &str {
self.0.borrow()
}
}

impl<T: std::borrow::Borrow<str>> std::fmt::Debug for $wid<T> {
Expand Down Expand Up @@ -379,10 +384,6 @@ pub mod test_wrap_borrowing {
Err(())
}
}

pub fn as_str(&self) -> &str {
self.0.borrow()
}
}

#[test]
Expand Down
10 changes: 0 additions & 10 deletions iri/src/_wrapper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,6 @@ wrap! { Iri borrowing str :
}
}

/// Gets a reference to the underlying &str.
pub fn as_str(&self) -> &str {
self.0.borrow()
}

/// Resolve a relative IRI reference against this one.
///
/// NB: when resolving multiple IRI references against the same base,
Expand Down Expand Up @@ -70,11 +65,6 @@ wrap! { IriRef borrowing str :
}
}

/// Gets a reference to the underlying &str.
pub fn as_str(&self) -> &str {
self.0.borrow()
}

/// Resolve a relative IRI reference against this one.
///
/// NB: when resolving multiple IRI references against the same base,
Expand Down

0 comments on commit e8bb39e

Please sign in to comment.