Need help with boolean type condition

⚓ Rust    📅 2025-07-08    👤 surdeus    👁️ 2      

surdeus

I found some app working unexpectedly when I'm extending condition with simply add | self.write_json_to_file | self.write_bin_to_file part like:

impl StatisticsConfig {
    pub fn active(&self) -> bool {
        (self.interval != 0) & (self.print_to_stdout | self.write_html_to_file | self.write_json_to_file | self.write_bin_to_file)
    }
}

On this example, all values (self.print_to_stdout | self.write_html_to_file | self.write_json_to_file | self.write_bin_to_file) are boolean.

I would prefer to use logical operators || but not sure, why does maintainer use bitwise condition, maybe for performance reasons.

3 posts - 2 participants

Read full topic

🏷️ rust_feed