Diference between #[allowed(unused_variables)] and _

โš“ Rust    ๐Ÿ“… 2026-05-03    ๐Ÿ‘ค surdeus    ๐Ÿ‘๏ธ 1      

surdeus

Hello everyone,
Iโ€™m writing some code where, when I call a function from the genpdf crate called set_header, it generates a variable representing the pages, but I donโ€™t need to use it.
There are two ways I know of to tell the compiler that I donโ€™t need to use it. My question is: what is the difference between using #[allowed(unused_variables)] and _<variable_name>?

fn decorator_pdf(file_decorator: &mut Document) {
    let mut decorator = SimplePageDecorator::new();
    decorator.set_margins(10);

    #[allow(unused_variables)]
    decorator.set_header(|page_number| {
        let mut layout = LinearLayout::vertical();
        let bre = elements::Break::new(2);

        layout.push(
            elements::Paragraph::new("Github user activity")
                .styled(style::Style::new().bold().with_font_size(18)),
        );

        layout.push(bre);
        layout
    });

    file_decorator.set_page_decorator(decorator);
}
fn decorator_pdf(file_decorator: &mut Document) {
    let mut decorator = SimplePageDecorator::new();
    decorator.set_margins(10);

   
    decorator.set_header(|_page_number| {
        let mut layout = LinearLayout::vertical();
        let bre = elements::Break::new(2);

        layout.push(
            elements::Paragraph::new("Github user activity")
                .styled(style::Style::new().bold().with_font_size(18)),
        );

        layout.push(bre);
        layout
    });

    file_decorator.set_page_decorator(decorator);
}

Thank you very much for clarifying that

1 post - 1 participant

Read full topic

๐Ÿท๏ธ Rust_feed