From 5785a0773a71572f2435ad4330783fa3e6a285d5 Mon Sep 17 00:00:00 2001 From: Marijn Suijten Date: Mon, 8 Dec 2025 14:24:29 +0100 Subject: [PATCH] Change `Bindings::write()` to take `impl Write` instead of `&mut dyn Write` Dynamic dispatch is not (always) needed here, and this way an owned `File` can trivially be moved into the function again like before without forcing a mutable borrow. Noting that `Write` is even implemented on `&File`, which can now be more easily passed without having it under `mut`. --- .../tests/parse_callbacks/add_derives_callback/mod.rs | 2 +- bindgen/lib.rs | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/bindgen-tests/tests/parse_callbacks/add_derives_callback/mod.rs b/bindgen-tests/tests/parse_callbacks/add_derives_callback/mod.rs index 570cef7ce1..4b6f210dce 100644 --- a/bindgen-tests/tests/parse_callbacks/add_derives_callback/mod.rs +++ b/bindgen-tests/tests/parse_callbacks/add_derives_callback/mod.rs @@ -20,7 +20,7 @@ mod tests { } fn write_bindings_to_string(bindings: &Bindings) -> String { - let mut output = Vec::::new(); + let mut output = vec![]; bindings.write(&mut output).unwrap_or_else(|e| { panic!("Failed to write generated bindings: {e}") }); diff --git a/bindgen/lib.rs b/bindgen/lib.rs index e7ea44e19a..0305b5cd7b 100644 --- a/bindgen/lib.rs +++ b/bindgen/lib.rs @@ -927,17 +927,17 @@ impl Bindings { /// Write these bindings as source text to a file. pub fn write_to_file>(&self, path: P) -> io::Result<()> { - let mut file = OpenOptions::new() + let file = OpenOptions::new() .write(true) .truncate(true) .create(true) .open(path.as_ref())?; - self.write(&mut file)?; + self.write(file)?; Ok(()) } /// Write these bindings as source text to the given `Write`able. - pub fn write(&self, writer: &mut dyn Write) -> io::Result<()> { + pub fn write(&self, mut writer: impl Write) -> io::Result<()> { const NL: &str = if cfg!(windows) { "\r\n" } else { "\n" }; if !self.options.disable_header_comment {