aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorGravatar Sean McArthur <sean@seanmonstar.com> 2019-11-26 18:08:39 -0800
committerGravatar Carl Lerche <me@carllerche.com> 2019-11-26 18:08:39 -0800
commita642e1c075362a81abfff43ed7cb332337b64643 (patch)
tree26ee0371a56415e81bd7035ff1fbec9a1fc4c9c4 /src
parent3cf91283f8b4019d84d9b57674cb788179f40f58 (diff)
downloadbytes-a642e1c075362a81abfff43ed7cb332337b64643.tar.gz
bytes-a642e1c075362a81abfff43ed7cb332337b64643.tar.zst
bytes-a642e1c075362a81abfff43ed7cb332337b64643.zip
Add accessors to Limit combinator (#325)
Diffstat (limited to 'src')
-rw-r--r--src/buf/ext/limit.rs41
1 files changed, 41 insertions, 0 deletions
diff --git a/src/buf/ext/limit.rs b/src/buf/ext/limit.rs
index b16c049..f86e011 100644
--- a/src/buf/ext/limit.rs
+++ b/src/buf/ext/limit.rs
@@ -17,6 +17,47 @@ pub(super) fn new<T>(inner: T, limit: usize) -> Limit<T> {
}
}
+impl<T> Limit<T> {
+ /// 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<T: BufMut> BufMut for Limit<T> {
fn remaining_mut(&self) -> usize {
cmp::min(self.inner.remaining_mut(), self.limit)