Skip to content

Commit

Permalink
do not clone the vec but only the first String
Browse files Browse the repository at this point in the history
  • Loading branch information
hal3e committed May 24, 2024
1 parent 04702e0 commit b2cf1c5
Showing 1 changed file with 16 additions and 7 deletions.
23 changes: 16 additions & 7 deletions src/abi/full_program.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,13 +124,22 @@ impl FullABIFunction {
pub fn doc_strings(&self) -> Result<Vec<String>> {
self.attributes
.iter()
.filter(|attr| attr.name == "doc-comment")
.map(|attr| {
<[String; 1]>::try_from(attr.arguments.clone())
.map(|[doc]| doc)
.map_err(|_| {
Error("`doc-comment` attribute has more than one argument".to_string())
})
.filter_map(|attr| {
if attr.name == "doc-comment" {
let doc_res = {
if attr.arguments.len() != 1 {
Err(Error(
"`doc-comment` attribute must have one argument".to_string(),
))
} else {
Ok(attr.arguments[0].clone())
}
};

Some(doc_res)
} else {
None
}
})
.collect::<Result<Vec<String>>>()
}
Expand Down

0 comments on commit b2cf1c5

Please sign in to comment.