diff --git a/src/alloc/mod.rs b/src/alloc/mod.rs index ec8dbb2e51b30b23a21dd8287720e891b6e1f7ad..49978ea59076b232efa3290fd28cf376e2c3ee4f 100644 --- a/src/alloc/mod.rs +++ b/src/alloc/mod.rs @@ -1,3 +1,7 @@ +//! Buffer allocation +//! +//! This module is currently not really in use + mod heap; use std::sync::Arc; diff --git a/src/buf/append.rs b/src/imp/buf/append.rs similarity index 98% rename from src/buf/append.rs rename to src/imp/buf/append.rs index 2da7a822b5af93f25432a662dc7536f1056a39a8..13a11c89c9227b19ab4d3d852c7072546128301f 100644 --- a/src/buf/append.rs +++ b/src/imp/buf/append.rs @@ -1,6 +1,4 @@ -use alloc; -use buf::{MutBuf}; -use bytes::Bytes; +use {alloc, MutBuf, Bytes}; use std::cell::Cell; /// A `Buf` backed by a contiguous region of memory. diff --git a/src/buf/block.rs b/src/imp/buf/block.rs similarity index 99% rename from src/buf/block.rs rename to src/imp/buf/block.rs index 988318bcbda7f85115a14dc35c637ee083cd5eb9..b42ac8cc7d9cab099f29192c44cdf301aa4bed68 100644 --- a/src/buf/block.rs +++ b/src/imp/buf/block.rs @@ -1,7 +1,7 @@ #![allow(warnings)] -use {Buf, MutBuf, AppendBuf, Bytes}; -use alloc::{self, /* Pool */}; +use {alloc, Buf, MutBuf, Bytes}; +use buf::AppendBuf; use std::{cmp, ptr, slice}; use std::io::Cursor; use std::rc::Rc; diff --git a/src/buf/byte.rs b/src/imp/buf/byte.rs similarity index 100% rename from src/buf/byte.rs rename to src/imp/buf/byte.rs diff --git a/src/buf/mod.rs b/src/imp/buf/mod.rs similarity index 99% rename from src/buf/mod.rs rename to src/imp/buf/mod.rs index e8d6faf54eb2f55e128044b94d71e0608590385d..53c6c0545cb96c8d9bef5d619e61dc64cc019000 100644 --- a/src/buf/mod.rs +++ b/src/imp/buf/mod.rs @@ -4,7 +4,8 @@ pub mod byte; pub mod ring; pub mod take; -use {Bytes, Take}; +use {Bytes}; +use buf::Take; use byteorder::ByteOrder; use std::{cmp, fmt, io, ptr, usize}; diff --git a/src/buf/ring.rs b/src/imp/buf/ring.rs similarity index 100% rename from src/buf/ring.rs rename to src/imp/buf/ring.rs diff --git a/src/buf/take.rs b/src/imp/buf/take.rs similarity index 98% rename from src/buf/take.rs rename to src/imp/buf/take.rs index 965c1f6f6be0f22dcc6c36488176afcb3a930fa6..69ab443a362ad88c7923ad62c05ab6df8a4af53c 100644 --- a/src/buf/take.rs +++ b/src/imp/buf/take.rs @@ -1,4 +1,4 @@ -use buf::{Buf, MutBuf}; +use {Buf, MutBuf}; use std::{cmp}; #[derive(Debug)] diff --git a/src/bytes/mod.rs b/src/imp/bytes/mod.rs similarity index 99% rename from src/bytes/mod.rs rename to src/imp/bytes/mod.rs index 47548c67a22d74654b421f648a0c8fcf20ee133a..34b7d31ff10e1b5a9719fb5294d37722bb45ce87 100644 --- a/src/bytes/mod.rs +++ b/src/imp/bytes/mod.rs @@ -2,8 +2,7 @@ mod rope; mod seq; mod small; -use alloc; -use buf::Buf; +use {alloc, Buf}; use self::seq::Seq; use self::small::Small; use self::rope::{Rope, RopeBuf}; diff --git a/src/bytes/rope.rs b/src/imp/bytes/rope.rs similarity index 99% rename from src/bytes/rope.rs rename to src/imp/bytes/rope.rs index 3eb79488b15b65a79b3afbd155d733b139ebb37d..584f3cb388d5e66d9838292879db0d6eebb8d3d8 100644 --- a/src/bytes/rope.rs +++ b/src/imp/bytes/rope.rs @@ -1,7 +1,7 @@ -use {Bytes, MutByteBuf}; -use buf::{Buf, MutBuf, Source}; -use bytes::seq::Seq; -use bytes::small::{Small}; +use {Buf, MutBuf, Bytes}; +use super::seq::Seq; +use super::small::{Small}; +use buf::{Source, MutByteBuf}; use std::{cmp, ops}; use std::io::Cursor; use std::sync::Arc; diff --git a/src/bytes/seq.rs b/src/imp/bytes/seq.rs similarity index 97% rename from src/bytes/seq.rs rename to src/imp/bytes/seq.rs index e6a1d335ae86ec7bb94692ff464df13c867524d7..cdf2552ffcc9f704cec47ee49109b3ca52c3257a 100644 --- a/src/bytes/seq.rs +++ b/src/imp/bytes/seq.rs @@ -1,7 +1,7 @@ //! Immutable set of bytes sequential in memory. -use {alloc, MutByteBuf, MutBuf}; -use bytes::{Bytes}; +use {alloc, MutBuf, Bytes}; +use buf::{MutByteBuf}; use std::ops; use std::io::Cursor; diff --git a/src/bytes/small.rs b/src/imp/bytes/small.rs similarity index 98% rename from src/bytes/small.rs rename to src/imp/bytes/small.rs index a2f27960de2ea17990131edef66f17b0cf2aa408..2cc208540feb0a153ef155d1139e577bb35efa78 100644 --- a/src/bytes/small.rs +++ b/src/imp/bytes/small.rs @@ -1,4 +1,4 @@ -use bytes::{Bytes}; +use {Bytes}; use std::ops; use std::io::Cursor; diff --git a/src/imp/mod.rs b/src/imp/mod.rs new file mode 100644 index 0000000000000000000000000000000000000000..4c5772bf97c2ef5197a995df3a8dbc7ca59a2c67 --- /dev/null +++ b/src/imp/mod.rs @@ -0,0 +1,4 @@ +//! Used for internal code structure + +pub mod buf; +pub mod bytes; diff --git a/src/lib.rs b/src/lib.rs index bb6741c46da395f51827a82a746f9f8fddb19b75..4169766665d3b299f2a1d01c55353647158913c8 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -3,21 +3,34 @@ #[macro_use] extern crate log; - extern crate byteorder; -mod buf; -mod bytes; +// Implementation in here +mod imp; pub mod alloc; -pub use buf::{Buf, MutBuf, Source, Sink, Reader, ReadExt, Writer, WriteExt, Fmt}; -pub use buf::append::AppendBuf; -pub use buf::block::{BlockBuf, BlockBufCursor}; -pub use buf::byte::{ByteBuf, MutByteBuf}; -pub use buf::ring::RingBuf; -pub use buf::take::Take; -pub use bytes::Bytes; +pub use imp::buf::{Buf, MutBuf}; +pub use imp::bytes::Bytes; + +pub mod buf { + pub use imp::buf::{ + Source, + Sink, + Reader, + ReadExt, + Writer, + WriteExt, + Fmt, + }; + pub use imp::buf::append::AppendBuf; + pub use imp::buf::block::{BlockBuf, BlockBufCursor}; + pub use imp::buf::byte::{ByteBuf, MutByteBuf}; + pub use imp::buf::ring::RingBuf; + pub use imp::buf::take::Take; + + pub use imp::bytes::BytesBuf; +} use std::u32; diff --git a/test/test_append.rs b/test/test_append.rs index 3e537db55cc05378c937765136886f77993f9860..fd5fcef22bc997365cd1dbebbd1a42665b6b5999 100644 --- a/test/test_append.rs +++ b/test/test_append.rs @@ -1,4 +1,5 @@ -use bytes::{Buf, MutBuf, AppendBuf}; +use bytes::{Buf, MutBuf}; +use bytes::buf::AppendBuf; #[test] pub fn test_initial_buf_empty() { @@ -27,36 +28,3 @@ pub fn test_initial_buf_empty() { assert_eq!(dst, b"hello world"); } } - -/* -#[test] -pub fn test_append_buf_from_pool() { - use bytes::alloc::Pool; - let pool = Pool::with_capacity(2, 256); - - // Run in a loop a bunch in hope that if there is a memory issue, it will - // be exposed - for _ in 0..1000 { - let mut buf = pool.new_append_buf().unwrap(); - let mut dst: Vec<u8> = vec![]; - - assert_eq!(buf.remaining(), 256); - - buf.write_slice(b"hello world"); - assert_eq!(buf.remaining(), 245); - assert_eq!(buf.bytes(), b"hello world"); - - let view1 = buf.slice(0, 11); - view1.buf().copy_to(&mut dst); - - assert_eq!(dst, b"hello world"); - assert_eq!(view1, buf.slice(0, 11)); - - drop(buf); - let mut buf = pool.new_append_buf().unwrap(); - buf.write_slice(b"zomg no no no no"); - - assert_eq!(dst, b"hello world"); - } -} -*/ diff --git a/test/test_block.rs b/test/test_block.rs index 37a9334dcc0995f40e8408a8b7d483ba71b73d84..a13c9030014233ca064c49961d1761bf3ee36bd9 100644 --- a/test/test_block.rs +++ b/test/test_block.rs @@ -1,5 +1,5 @@ -use bytes::{MutBuf, BlockBuf}; - +use bytes::{MutBuf}; +use bytes::buf::{BlockBuf}; #[test] pub fn test_block_drop() { diff --git a/test/test_buf.rs b/test/test_buf.rs index f28d70ff0d00e200613315fb91c0991663565b0c..1385de65bb65dd2107a4d77cfa5f6f27f0e9e6c5 100644 --- a/test/test_buf.rs +++ b/test/test_buf.rs @@ -48,7 +48,7 @@ fn test_read_u16_buffer_underflow() { #[test] fn test_vec_sink_capacity() { - use bytes::Sink; + use bytes::buf::Sink; let mut sink: Vec<u8> = Vec::new(); sink.reserve(16); diff --git a/test/test_buf_fill.rs b/test/test_buf_fill.rs index 05ab30854cc218d7279a79cabb748232f5aaf826..fbde4c0cf5a26f2ab907397efd747b8b28f8b1d8 100644 --- a/test/test_buf_fill.rs +++ b/test/test_buf_fill.rs @@ -1,4 +1,5 @@ use bytes::*; +use bytes::buf::*; use std::io; #[test] diff --git a/test/test_byte_buf.rs b/test/test_byte_buf.rs index 34f596a47829fde909b4220051d8757785ecea54..a4a7fa26932b99bba02aa8648d209136aa6c9557 100644 --- a/test/test_byte_buf.rs +++ b/test/test_byte_buf.rs @@ -1,5 +1,5 @@ use bytes::{Buf, MutBuf}; -use bytes::MutByteBuf; +use bytes::buf::MutByteBuf; #[test] pub fn test_initial_buf_empty() { diff --git a/test/test_ring.rs b/test/test_ring.rs index 88c44f61ec408741ffce50b334662ba237cf7027..135597ac90b844684e99d9ea5a4881a1019b0157 100644 --- a/test/test_ring.rs +++ b/test/test_ring.rs @@ -1,4 +1,5 @@ -use bytes::{RingBuf, Buf, MutBuf}; +use bytes::{Buf, MutBuf}; +use bytes::buf::RingBuf; #[test] pub fn test_initial_buf_empty() {