summaryrefslogtreecommitdiff
path: root/rust-src/bch_bindgen/src/lib.rs
diff options
context:
space:
mode:
Diffstat (limited to 'rust-src/bch_bindgen/src/lib.rs')
-rw-r--r--rust-src/bch_bindgen/src/lib.rs10
1 files changed, 10 insertions, 0 deletions
diff --git a/rust-src/bch_bindgen/src/lib.rs b/rust-src/bch_bindgen/src/lib.rs
index d2b58511..86592c6b 100644
--- a/rust-src/bch_bindgen/src/lib.rs
+++ b/rust-src/bch_bindgen/src/lib.rs
@@ -157,3 +157,13 @@ impl FromStr for c::bpos {
Ok(c::bpos { inode: ino, offset: off, snapshot: snp })
}
}
+
+pub fn printbuf_to_formatter<F>(f: &mut fmt::Formatter<'_>, func: F) -> fmt::Result
+ where F: Fn(*mut c::printbuf) {
+ let mut buf = c::printbuf::new();
+
+ func(&mut buf);
+
+ let s = unsafe { CStr::from_ptr(buf.buf) };
+ f.write_str(s.to_str().unwrap())
+}