From 73f38414d5299dff032a26a7e5cad5394ee39059 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C3=ABl=20Hauspie?= <michael.hauspie@univ-lille.fr> Date: Mon, 31 Mar 2025 15:54:46 +0200 Subject: [PATCH] Adds a README file --- README.md | 6 ++++++ src/main.rs | 21 +++++++++------------ 2 files changed, 15 insertions(+), 12 deletions(-) create mode 100644 README.md diff --git a/README.md b/README.md new file mode 100644 index 0000000..81713e8 --- /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 2f26e12..da04698 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>; } -- GitLab