Skip to content

Commit 7c38446

Browse files
MarijnS95emilio
authored andcommitted
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`.
1 parent 953fc76 commit 7c38446

File tree

2 files changed

+4
-4
lines changed
  • bindgen-tests/tests/parse_callbacks/add_derives_callback
  • bindgen

2 files changed

+4
-4
lines changed

bindgen-tests/tests/parse_callbacks/add_derives_callback/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ mod tests {
2020
}
2121

2222
fn write_bindings_to_string(bindings: &Bindings) -> String {
23-
let mut output = Vec::<u8>::new();
23+
let mut output = vec![];
2424
bindings.write(&mut output).unwrap_or_else(|e| {
2525
panic!("Failed to write generated bindings: {e}")
2626
});

bindgen/lib.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -927,17 +927,17 @@ impl Bindings {
927927

928928
/// Write these bindings as source text to a file.
929929
pub fn write_to_file<P: AsRef<Path>>(&self, path: P) -> io::Result<()> {
930-
let mut file = OpenOptions::new()
930+
let file = OpenOptions::new()
931931
.write(true)
932932
.truncate(true)
933933
.create(true)
934934
.open(path.as_ref())?;
935-
self.write(&mut file)?;
935+
self.write(file)?;
936936
Ok(())
937937
}
938938

939939
/// Write these bindings as source text to the given `Write`able.
940-
pub fn write(&self, writer: &mut dyn Write) -> io::Result<()> {
940+
pub fn write(&self, mut writer: impl Write) -> io::Result<()> {
941941
const NL: &str = if cfg!(windows) { "\r\n" } else { "\n" };
942942

943943
if !self.options.disable_header_comment {

0 commit comments

Comments
 (0)