Skip to content
Snippets Groups Projects
Commit 73f38414 authored by Michael Hauspie's avatar Michael Hauspie
Browse files

Adds a README file

parent b2f9b846
No related branches found
No related tags found
No related merge requests found
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>
//! This crates demonstrates the use of extension traits and Type State encoding. #![doc = include_str!("../README.md")]
//!
//! The original idea is borrowed from Will Crichton's talk at Strangeloop 2021
//!
//! https://www.youtube.com/watch?v=bnnacleqg6k
//!
const CLEAR: &str = "\x1b[2J\x1b[1;1H"; const CLEAR: &str = "\x1b[2J\x1b[1;1H";
fn compute<T>(_val: T) { fn compute<T>(_val: T) {
...@@ -11,14 +8,14 @@ fn compute<T>(_val: T) { ...@@ -11,14 +8,14 @@ fn compute<T>(_val: T) {
} }
/// This type defines the /unbounded/ state for our progress bar /// 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 /// This type defines the /bounded/ state for our progress bar
struct Bounded { pub struct Bounded {
bound: usize, bound: usize,
} }
/// Defines how to display a progress bar /// 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 /// Displays the progress bar. It is for each item yielded by the iterator
fn display<Iter>(&self, progress: &Progress<Iter, Self>); fn display<Iter>(&self, progress: &Progress<Iter, Self>);
} }
...@@ -42,7 +39,7 @@ impl ProgressDisplay for Bounded { ...@@ -42,7 +39,7 @@ impl ProgressDisplay for Bounded {
#[derive(Debug)] #[derive(Debug)]
/// An Iterator that display progress /// An Iterator that display progress
struct Progress<Iter, Bound> { pub struct Progress<Iter, Bound> {
iter: Iter, iter: Iter,
i: usize, i: usize,
bound: Bound, bound: Bound,
...@@ -50,7 +47,7 @@ struct Progress<Iter, Bound> { ...@@ -50,7 +47,7 @@ struct Progress<Iter, Bound> {
impl<Iter: ExactSizeIterator> Progress<Iter, Unbounded> { impl<Iter: ExactSizeIterator> Progress<Iter, Unbounded> {
/// Creates a new bounded progress bar from an unbounded one /// 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 { let bound = Bounded {
bound: self.iter.len(), bound: self.iter.len(),
}; };
...@@ -74,7 +71,7 @@ impl<Iter: Iterator, Bound: ProgressDisplay> Iterator for Progress<Iter, Bound> ...@@ -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 /// 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 /// Create a new unbounded progress bar from self
fn progress(self) -> Progress<Self, Unbounded>; fn progress(self) -> Progress<Self, Unbounded>;
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment