From 98e0d954b59b7c332ebe599c99aab95dbb87dd00 Mon Sep 17 00:00:00 2001
From: Carl Lerche <me@carllerche.com>
Date: Fri, 23 Sep 2016 12:05:32 -0700
Subject: [PATCH] Reorganize crate

---
 src/alloc/mod.rs             |  4 ++++
 src/{ => imp}/buf/append.rs  |  4 +---
 src/{ => imp}/buf/block.rs   |  4 ++--
 src/{ => imp}/buf/byte.rs    |  0
 src/{ => imp}/buf/mod.rs     |  3 ++-
 src/{ => imp}/buf/ring.rs    |  0
 src/{ => imp}/buf/take.rs    |  2 +-
 src/{ => imp}/bytes/mod.rs   |  3 +--
 src/{ => imp}/bytes/rope.rs  |  8 ++++----
 src/{ => imp}/bytes/seq.rs   |  4 ++--
 src/{ => imp}/bytes/small.rs |  2 +-
 src/imp/mod.rs               |  4 ++++
 src/lib.rs                   | 33 +++++++++++++++++++++++----------
 test/test_append.rs          | 36 ++----------------------------------
 test/test_block.rs           |  4 ++--
 test/test_buf.rs             |  2 +-
 test/test_buf_fill.rs        |  1 +
 test/test_byte_buf.rs        |  2 +-
 test/test_ring.rs            |  3 ++-
 19 files changed, 54 insertions(+), 65 deletions(-)
 rename src/{ => imp}/buf/append.rs (98%)
 rename src/{ => imp}/buf/block.rs (99%)
 rename src/{ => imp}/buf/byte.rs (100%)
 rename src/{ => imp}/buf/mod.rs (99%)
 rename src/{ => imp}/buf/ring.rs (100%)
 rename src/{ => imp}/buf/take.rs (98%)
 rename src/{ => imp}/bytes/mod.rs (99%)
 rename src/{ => imp}/bytes/rope.rs (99%)
 rename src/{ => imp}/bytes/seq.rs (97%)
 rename src/{ => imp}/bytes/small.rs (98%)
 create mode 100644 src/imp/mod.rs

diff --git a/src/alloc/mod.rs b/src/alloc/mod.rs
index ec8dbb2..49978ea 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 2da7a82..13a11c8 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 988318b..b42ac8c 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 e8d6faf..53c6c05 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 965c1f6..69ab443 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 47548c6..34b7d31 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 3eb7948..584f3cb 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 e6a1d33..cdf2552 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 a2f2796..2cc2085 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 0000000..4c5772b
--- /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 bb6741c..4169766 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 3e537db..fd5fcef 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 37a9334..a13c903 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 f28d70f..1385de6 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 05ab308..fbde4c0 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 34f596a..a4a7fa2 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 88c44f6..135597a 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() {
-- 
GitLab