diff options
author | Kent Overstreet <kent.overstreet@linux.dev> | 2023-02-28 01:01:50 -0500 |
---|---|---|
committer | Kent Overstreet <kent.overstreet@linux.dev> | 2023-02-28 01:01:50 -0500 |
commit | 59528398cf367df1e84372946b7031a2e3eb2b7e (patch) | |
tree | 542f805458e9afa541ebfa6a06d081397aee7fcd /rust-src/bch_bindgen/src/lib.rs | |
parent | a999dc0a9f22a2f403defa26d09257f7600a4312 (diff) |
rust: BkeySC
Implement a rust equivalent to bkey_s_c, which uses references with the
correct lifetimes: now cmd_list.rs doesn't need unsafe.
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
Diffstat (limited to 'rust-src/bch_bindgen/src/lib.rs')
-rw-r--r-- | rust-src/bch_bindgen/src/lib.rs | 23 |
1 files changed, 0 insertions, 23 deletions
diff --git a/rust-src/bch_bindgen/src/lib.rs b/rust-src/bch_bindgen/src/lib.rs index b1474bc2..e853edbb 100644 --- a/rust-src/bch_bindgen/src/lib.rs +++ b/rust-src/bch_bindgen/src/lib.rs @@ -154,26 +154,3 @@ impl FromStr for c::bpos { Ok(c::bpos { inode: ino, offset: off, snapshot: snp }) } } - -pub struct BkeySCToText<'a, 'b> { - k: &'a c::bkey_s_c, - fs: &'b fs::Fs, -} - -impl<'a, 'b> fmt::Display for BkeySCToText<'a, 'b> { - fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - let mut buf = c::printbuf::new(); - - unsafe { c::bch2_bkey_val_to_text(&mut buf, self.fs.raw, *self.k) }; - - let s = unsafe { CStr::from_ptr(buf.buf) }; - let s = s.to_str().unwrap(); - write!(f, "{}", s) - } -} - -impl c::bkey_s_c { - pub fn to_text<'a, 'b>(&'a self, fs: &'b fs::Fs) -> BkeySCToText<'a, 'b> { - BkeySCToText { k: self, fs } - } -} |