From a642e1c075362a81abfff43ed7cb332337b64643 Mon Sep 17 00:00:00 2001 From: Sean McArthur Date: Tue, 26 Nov 2019 18:08:39 -0800 Subject: [PATCH] Add accessors to Limit combinator (#325) --- src/buf/ext/limit.rs | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/src/buf/ext/limit.rs b/src/buf/ext/limit.rs index b16c049c7..f86e01151 100644 --- a/src/buf/ext/limit.rs +++ b/src/buf/ext/limit.rs @@ -17,6 +17,47 @@ pub(super) fn new(inner: T, limit: usize) -> Limit { } } +impl Limit { + /// Consumes this `Limit`, returning the underlying value. + pub fn into_inner(self) -> T { + self.inner + } + + /// Gets a reference to the underlying `BufMut`. + /// + /// It is inadvisable to directly write to the underlying `BufMut`. + pub fn get_ref(&self) -> &T { + &self.inner + } + + /// Gets a mutable reference to the underlying `BufMut`. + /// + /// It is inadvisable to directly write to the underlying `BufMut`. + pub fn get_mut(&mut self) -> &mut T { + &mut self.inner + } + + /// Returns the maximum number of bytes that can be written + /// + /// # Note + /// + /// If the inner `BufMut` has fewer bytes than indicated by this method then + /// that is the actual number of available bytes. + pub fn limit(&self) -> usize { + self.limit + } + + /// Sets the maximum number of bytes that can be written. + /// + /// # Note + /// + /// If the inner `BufMut` has fewer bytes than `lim` then that is the actual + /// number of available bytes. + pub fn set_limit(&mut self, lim: usize) { + self.limit = lim + } +} + impl BufMut for Limit { fn remaining_mut(&self) -> usize { cmp::min(self.inner.remaining_mut(), self.limit)