Skip to content

Commit

Permalink
fn visitor update
Browse files Browse the repository at this point in the history
  • Loading branch information
dcodesdev committed Jun 10, 2024
1 parent 339731b commit dd20167
Showing 1 changed file with 14 additions and 8 deletions.
22 changes: 14 additions & 8 deletions crates/syntest/src/visitor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,11 @@ impl AsVisitor {
.find_map(|item| {
if let syn::Item::Fn(item_fn) = item {
if item_fn.sig.ident.to_string() == fn_name {
Some(item_fn)
} else {
None
return Some(item_fn);
}
} else {
None
}

None
})
.expect(&format!("Function {fn_name} not found"));

Expand Down Expand Up @@ -56,10 +54,18 @@ pub struct FnVisitor {
}

impl FnVisitor {
pub fn new() -> Self {
Self {
pub fn new(file: &syn::File) -> Self {
let mut visitor = Self {
functions: Vec::new(),
}
};

visitor.visit_file(file);

visitor
}

pub fn functions(&self) -> &Vec<String> {
&self.functions
}
}

Expand Down

0 comments on commit dd20167

Please sign in to comment.