diff --git a/gtk4/src/entry_buffer.rs b/gtk4/src/entry_buffer.rs index 41b65345fc56..40a0992feba1 100644 --- a/gtk4/src/entry_buffer.rs +++ b/gtk4/src/entry_buffer.rs @@ -127,3 +127,11 @@ impl Default for EntryBuffer { glib::Object::new() } } + +impl std::fmt::Write for EntryBuffer { + fn write_str(&mut self, s: &str) -> std::fmt::Result { + let pos = self.length(); + self.insert_text(pos, s); + Ok(()) + } +} diff --git a/gtk4/src/text_buffer.rs b/gtk4/src/text_buffer.rs index 0167c5062c8c..f077f0bc9a90 100644 --- a/gtk4/src/text_buffer.rs +++ b/gtk4/src/text_buffer.rs @@ -103,3 +103,11 @@ pub trait TextBufferExtManual: sealed::Sealed + IsA + 'static { } impl> TextBufferExtManual for O {} + +impl std::fmt::Write for TextBuffer { + fn write_str(&mut self, s: &str) -> std::fmt::Result { + let mut iter = self.end_iter(); + self.insert(&mut iter, s); + Ok(()) + } +}