Rename RingBuf::new -> with_capacity

This commit is contained in:
Carl Lerche
2016-09-20 13:42:24 -07:00
parent 1f188b5628
commit 4105901244
2 changed files with 8 additions and 8 deletions
+1 -1
View File
@@ -22,7 +22,7 @@ pub struct RingBuf {
// TODO: There are most likely many optimizations that can be made
impl RingBuf {
/// Allocates a new `RingBuf` with the specified capacity.
pub fn new(mut capacity: usize) -> RingBuf {
pub fn with_capacity(mut capacity: usize) -> RingBuf {
// Round to the next power of 2 for better alignment
capacity = capacity.next_power_of_two();
+7 -7
View File
@@ -2,7 +2,7 @@ use bytes::{RingBuf, Buf, MutBuf};
#[test]
pub fn test_initial_buf_empty() {
let mut buf = RingBuf::new(16);
let mut buf = RingBuf::with_capacity(16);
assert_eq!(MutBuf::remaining(&buf), 16);
assert_eq!(Buf::remaining(&buf), 0);
@@ -32,7 +32,7 @@ pub fn test_initial_buf_empty() {
#[test]
fn test_wrapping_write() {
let mut buf = RingBuf::new(16);
let mut buf = RingBuf::with_capacity(16);
let mut out = [0;10];
buf.copy_from(&[42;12][..]);
@@ -54,7 +54,7 @@ fn test_wrapping_write() {
#[test]
fn test_io_write_and_read() {
let mut buf = RingBuf::new(16);
let mut buf = RingBuf::with_capacity(16);
let mut out = [0u8;8];
let written = buf.copy_from(&[1;8][..]);
@@ -74,7 +74,7 @@ fn test_io_write_and_read() {
#[test]
#[should_panic]
fn test_wrap_reset() {
let mut buf = RingBuf::new(8);
let mut buf = RingBuf::with_capacity(8);
buf.copy_from(&[1, 2, 3, 4, 5, 6, 7][..]);
buf.mark();
buf.copy_to(&mut [0; 4][..]);
@@ -85,7 +85,7 @@ fn test_wrap_reset() {
#[test]
// Test that writes across a mark/reset are preserved.
fn test_mark_write() {
let mut buf = RingBuf::new(8);
let mut buf = RingBuf::with_capacity(8);
buf.copy_from(&[1, 2, 3, 4, 5, 6, 7][..]);
buf.mark();
buf.copy_from(&[8][..]);
@@ -100,7 +100,7 @@ fn test_mark_write() {
// Test that "RingBuf::reset" does not reset the length of a
// full buffer to zero.
fn test_reset_full() {
let mut buf = RingBuf::new(8);
let mut buf = RingBuf::with_capacity(8);
buf.copy_from(&[1, 2, 3, 4, 5, 6, 7, 8][..]);
assert_eq!(MutBuf::remaining(&buf), 0);
buf.mark();
@@ -112,7 +112,7 @@ fn test_reset_full() {
#[test]
// Test that "RingBuf::clear" does the full reset
fn test_clear() {
let mut buf = RingBuf::new(8);
let mut buf = RingBuf::with_capacity(8);
buf.copy_from(&[0; 8][..]);
assert_eq!(MutBuf::remaining(&buf), 0);
assert_eq!(Buf::remaining(&buf), 8);