From 3f433f1cde54f8be56ff20b5e4a7ff509de126b7 Mon Sep 17 00:00:00 2001 From: "Tobin C. Harding" Date: Sun, 29 Dec 2024 09:17:25 +1100 Subject: [PATCH] Improve Cursor ref API Our `Cursor` is a replacement of sorts for the `std::io::Cursor`. Users of the `Cursor` are likely to expect the same API so to get a reference and/or mutable reference users will likely reach for `get_ref` and `get_mut`. We should provide these. Deprecate `inner` since it is the same as `get_ref` but less idiomatically named (should have been `as_inner`). Add `get_ref` and `get_mut` methods to the `Cursor` type. --- io/src/lib.rs | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/io/src/lib.rs b/io/src/lib.rs index 9770f6ce8..35e12b631 100644 --- a/io/src/lib.rs +++ b/io/src/lib.rs @@ -224,6 +224,19 @@ impl> Cursor { /// /// This is the whole wrapped buffer, including the bytes already read. #[inline] + pub fn get_ref(&self) -> &T { &self.inner } + + /// Returns a mutable reference to the inner buffer. + /// + /// This is the whole wrapped buffer, including the bytes already read. + #[inline] + pub fn get_mut(&mut self) -> &mut T { &mut self.inner } + + /// Returns a reference to the inner buffer. + /// + /// This is the whole wrapped buffer, including the bytes already read. + #[inline] + #[deprecated(since = "TBD", note = "use `get_ref()` instead")] pub fn inner(&self) -> &T { &self.inner } }