Skip to content
Snippets Groups Projects
Commit 41059012 authored by Carl Lerche's avatar Carl Lerche
Browse files

Rename RingBuf::new -> with_capacity

parent 1f188b56
No related branches found
No related tags found
No related merge requests found
...@@ -22,7 +22,7 @@ pub struct RingBuf { ...@@ -22,7 +22,7 @@ pub struct RingBuf {
// TODO: There are most likely many optimizations that can be made // TODO: There are most likely many optimizations that can be made
impl RingBuf { impl RingBuf {
/// Allocates a new `RingBuf` with the specified capacity. /// 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 // Round to the next power of 2 for better alignment
capacity = capacity.next_power_of_two(); capacity = capacity.next_power_of_two();
......
...@@ -2,7 +2,7 @@ use bytes::{RingBuf, Buf, MutBuf}; ...@@ -2,7 +2,7 @@ use bytes::{RingBuf, Buf, MutBuf};
#[test] #[test]
pub fn test_initial_buf_empty() { 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!(MutBuf::remaining(&buf), 16);
assert_eq!(Buf::remaining(&buf), 0); assert_eq!(Buf::remaining(&buf), 0);
...@@ -32,7 +32,7 @@ pub fn test_initial_buf_empty() { ...@@ -32,7 +32,7 @@ pub fn test_initial_buf_empty() {
#[test] #[test]
fn test_wrapping_write() { fn test_wrapping_write() {
let mut buf = RingBuf::new(16); let mut buf = RingBuf::with_capacity(16);
let mut out = [0;10]; let mut out = [0;10];
buf.copy_from(&[42;12][..]); buf.copy_from(&[42;12][..]);
...@@ -54,7 +54,7 @@ fn test_wrapping_write() { ...@@ -54,7 +54,7 @@ fn test_wrapping_write() {
#[test] #[test]
fn test_io_write_and_read() { 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 mut out = [0u8;8];
let written = buf.copy_from(&[1;8][..]); let written = buf.copy_from(&[1;8][..]);
...@@ -74,7 +74,7 @@ fn test_io_write_and_read() { ...@@ -74,7 +74,7 @@ fn test_io_write_and_read() {
#[test] #[test]
#[should_panic] #[should_panic]
fn test_wrap_reset() { 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.copy_from(&[1, 2, 3, 4, 5, 6, 7][..]);
buf.mark(); buf.mark();
buf.copy_to(&mut [0; 4][..]); buf.copy_to(&mut [0; 4][..]);
...@@ -85,7 +85,7 @@ fn test_wrap_reset() { ...@@ -85,7 +85,7 @@ fn test_wrap_reset() {
#[test] #[test]
// Test that writes across a mark/reset are preserved. // Test that writes across a mark/reset are preserved.
fn test_mark_write() { 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.copy_from(&[1, 2, 3, 4, 5, 6, 7][..]);
buf.mark(); buf.mark();
buf.copy_from(&[8][..]); buf.copy_from(&[8][..]);
...@@ -100,7 +100,7 @@ fn test_mark_write() { ...@@ -100,7 +100,7 @@ fn test_mark_write() {
// Test that "RingBuf::reset" does not reset the length of a // Test that "RingBuf::reset" does not reset the length of a
// full buffer to zero. // full buffer to zero.
fn test_reset_full() { 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][..]); buf.copy_from(&[1, 2, 3, 4, 5, 6, 7, 8][..]);
assert_eq!(MutBuf::remaining(&buf), 0); assert_eq!(MutBuf::remaining(&buf), 0);
buf.mark(); buf.mark();
...@@ -112,7 +112,7 @@ fn test_reset_full() { ...@@ -112,7 +112,7 @@ fn test_reset_full() {
#[test] #[test]
// Test that "RingBuf::clear" does the full reset // Test that "RingBuf::clear" does the full reset
fn test_clear() { fn test_clear() {
let mut buf = RingBuf::new(8); let mut buf = RingBuf::with_capacity(8);
buf.copy_from(&[0; 8][..]); buf.copy_from(&[0; 8][..]);
assert_eq!(MutBuf::remaining(&buf), 0); assert_eq!(MutBuf::remaining(&buf), 0);
assert_eq!(Buf::remaining(&buf), 8); assert_eq!(Buf::remaining(&buf), 8);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment