mirror of
https://github.com/tokio-rs/bytes.git
synced 2026-08-28 00:00:17 +02:00
Add take fn to Buf & MutBuf
This commit is contained in:
+11
-1
@@ -4,7 +4,7 @@ pub mod byte;
|
|||||||
pub mod ring;
|
pub mod ring;
|
||||||
pub mod take;
|
pub mod take;
|
||||||
|
|
||||||
use {Bytes};
|
use {Bytes, Take};
|
||||||
use byteorder::ByteOrder;
|
use byteorder::ByteOrder;
|
||||||
use std::{cmp, fmt, io, ptr, usize};
|
use std::{cmp, fmt, io, ptr, usize};
|
||||||
|
|
||||||
@@ -165,6 +165,11 @@ pub trait Buf {
|
|||||||
self.read_slice(&mut buf);
|
self.read_slice(&mut buf);
|
||||||
T::read_f64(&buf)
|
T::read_f64(&buf)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Create an adapter which will limit at most `limit` bytes from it.
|
||||||
|
fn take(self, limit: usize) -> Take<Self> where Self: Sized {
|
||||||
|
Take::new(self, limit)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// A trait for values that provide sequential write access to bytes.
|
/// A trait for values that provide sequential write access to bytes.
|
||||||
@@ -329,6 +334,11 @@ pub trait MutBuf {
|
|||||||
T::write_f64(&mut buf, n);
|
T::write_f64(&mut buf, n);
|
||||||
self.write_slice(&buf)
|
self.write_slice(&buf)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Create an adapter which will limit at most `limit` bytes from it.
|
||||||
|
fn take(self, limit: usize) -> Take<Self> where Self: Sized {
|
||||||
|
Take::new(self, limit)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|||||||
Reference in New Issue
Block a user