obelix 0.2.0

Obélix is a tool to reduce Rust source files to produce MVEs
Documentation
mod remove_item_impl;
mod remove_return_value;
mod remove_statement;
mod simplify_function_body;
pub use remove_item_impl::RemoveItemImplVisitor;
pub use remove_return_value::RemoveReturnValueVisitor;
pub use remove_statement::RemoveStatementVisitor;
pub use simplify_function_body::SimplifyFunctionBodyVisitor;

pub trait Visiter {
    fn reset(&mut self) {}

    fn visited_count(&self) -> usize;
}

#[must_use]
pub(crate) fn fold<V>(expected_errors: &[super::Message], content: &mut syn::File) -> bool
where
    V: syn::fold::Fold + Default + Visiter,
{
    let mut made_change = false;

    let mut visitor = V::default();

    let mut previous_count = visitor.visited_count();
    loop {
        visitor.reset();
        let new_file = visitor.fold_file(content.clone());
        let new_count = visitor.visited_count();
        let new_errors = super::compile(&new_file);

        if expected_errors == new_errors.as_slice()
            && !expected_errors.is_empty()
            && new_file != *content
        {
            *content = new_file;
            made_change = true;
        } else if previous_count == new_count {
            break made_change;
        } else {
            previous_count = new_count;
        }
    }
}