diff --git a/README.md b/README.md new file mode 100644 index 0000000000000000000000000000000000000000..81713e8490b5e681a9c03b687e086fc3ddee938c --- /dev/null +++ b/README.md @@ -0,0 +1,6 @@ +This crates demonstrates the use of extension traits and Type State encoding. + + The original idea is borrowed from Will Crichton's talk at Strangeloop 2021 + +<https://www.youtube.com/watch?v=bnnacleqg6k> + diff --git a/src/main.rs b/src/main.rs index 2f26e1256256303df6dcbb5c8ddaedc508099533..da046984a442e7f8bae2a72c11982a713956ec28 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,9 +1,6 @@ -//! This crates demonstrates the use of extension traits and Type State encoding. -//! -//! The original idea is borrowed from Will Crichton's talk at Strangeloop 2021 -//! -//! https://www.youtube.com/watch?v=bnnacleqg6k -//! +#![doc = include_str!("../README.md")] + + const CLEAR: &str = "\x1b[2J\x1b[1;1H"; fn compute<T>(_val: T) { @@ -11,14 +8,14 @@ fn compute<T>(_val: T) { } /// This type defines the /unbounded/ state for our progress bar -struct Unbounded; +pub struct Unbounded; /// This type defines the /bounded/ state for our progress bar -struct Bounded { +pub struct Bounded { bound: usize, } /// Defines how to display a progress bar -trait ProgressDisplay: Sized { +pub trait ProgressDisplay: Sized { /// Displays the progress bar. It is for each item yielded by the iterator fn display<Iter>(&self, progress: &Progress<Iter, Self>); } @@ -42,7 +39,7 @@ impl ProgressDisplay for Bounded { #[derive(Debug)] /// An Iterator that display progress -struct Progress<Iter, Bound> { +pub struct Progress<Iter, Bound> { iter: Iter, i: usize, bound: Bound, @@ -50,7 +47,7 @@ struct Progress<Iter, Bound> { impl<Iter: ExactSizeIterator> Progress<Iter, Unbounded> { /// Creates a new bounded progress bar from an unbounded one - fn with_bounds(self) -> Progress<Iter, Bounded> { + pub fn with_bounds(self) -> Progress<Iter, Bounded> { let bound = Bounded { bound: self.iter.len(), }; @@ -74,7 +71,7 @@ impl<Iter: Iterator, Bound: ProgressDisplay> Iterator for Progress<Iter, Bound> } /// A trait that allows the creation of a progress bar from a type -trait ProgressIteratorExt: Sized { +pub trait ProgressIteratorExt: Sized { /// Create a new unbounded progress bar from self fn progress(self) -> Progress<Self, Unbounded>; }