Skip to content

Commit

Permalink
Update documentation prepare for 0.15 (#384)
Browse files Browse the repository at this point in the history
* Update documentation

* Update doc comments

* Fix cargo fmt

* Update docs
  • Loading branch information
zhiburt authored Dec 19, 2023
1 parent 6701acd commit 184abb2
Show file tree
Hide file tree
Showing 23 changed files with 1,568 additions and 1,063 deletions.
1,497 changes: 818 additions & 679 deletions README.md

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions papergrid/src/ansi/mod.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//! A module which contains [`Color`] trait and its implementation [`AnsiColor`].
//! A module which contains [`ANSIFmt`] trait and its implementation [`ANSIStr`]
#[cfg_attr(feature = "std", doc = "and [`ANSIBuf`].")]
#[cfg(feature = "std")]
mod ansi_buf;
mod ansi_str;
Expand Down
114 changes: 114 additions & 0 deletions papergrid/src/config/entity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,3 +118,117 @@ impl Iterator for EntityIterator {
}
}
}

#[cfg(test)]
mod tests {
use super::*;

#[test]
fn test_entity_iter() {
assert_eq!(
Entity::Global.iter(10, 10).collect::<Vec<_>>(),
vec![
(0, 0),
(0, 1),
(0, 2),
(0, 3),
(0, 4),
(0, 5),
(0, 6),
(0, 7),
(0, 8),
(0, 9),
(1, 0),
(1, 1),
(1, 2),
(1, 3),
(1, 4),
(1, 5),
(1, 6),
(1, 7),
(1, 8),
(1, 9),
(2, 0),
(2, 1),
(2, 2),
(2, 3),
(2, 4),
(2, 5),
(2, 6),
(2, 7),
(2, 8),
(2, 9),
(3, 0),
(3, 1),
(3, 2),
(3, 3),
(3, 4),
(3, 5),
(3, 6),
(3, 7),
(3, 8),
(3, 9),
(4, 0),
(4, 1),
(4, 2),
(4, 3),
(4, 4),
(4, 5),
(4, 6),
(4, 7),
(4, 8),
(4, 9),
(5, 0),
(5, 1),
(5, 2),
(5, 3),
(5, 4),
(5, 5),
(5, 6),
(5, 7),
(5, 8),
(5, 9),
(6, 0),
(6, 1),
(6, 2),
(6, 3),
(6, 4),
(6, 5),
(6, 6),
(6, 7),
(6, 8),
(6, 9),
(7, 0),
(7, 1),
(7, 2),
(7, 3),
(7, 4),
(7, 5),
(7, 6),
(7, 7),
(7, 8),
(7, 9),
(8, 0),
(8, 1),
(8, 2),
(8, 3),
(8, 4),
(8, 5),
(8, 6),
(8, 7),
(8, 8),
(8, 9),
(9, 0),
(9, 1),
(9, 2),
(9, 3),
(9, 4),
(9, 5),
(9, 6),
(9, 7),
(9, 8),
(9, 9)
]
);
}
}
11 changes: 3 additions & 8 deletions tabled/src/grid/records/into_records/buf_records.rs
Original file line number Diff line number Diff line change
@@ -1,22 +1,17 @@
//! A module contains [`BufRows`] and [`BufColumns`] iterators.
//!
//! Almoust always they both can be used interchangeably but [`BufRows`] is supposed to be lighter cause it
//! does not reads columns.
//! A module contains [`BufRecords`] iterator.
use crate::grid::records::IntoRecords;

/// BufRecords inspects [`IntoRecords`] iterator and keeps read data buffered.
/// So it can be checking before hand.
///
/// In contrast to [`BufRows`] it keeps records by columns.
#[derive(Debug)]
pub struct BufRecords<I, T> {
iter: I,
buf: Vec<Vec<T>>,
}

impl BufRecords<(), ()> {
/// Creates new [`BufColumns`] structure, filling the buffer.
/// Creates new [`BufRecords`] structure, filling the buffer.
pub fn new<I>(
records: I,
sniff: usize,
Expand Down Expand Up @@ -60,7 +55,7 @@ where
}
}

/// A row iterator for [`BufColumns`]
/// A row iterator for [`BufRecords`]
#[derive(Debug)]
pub struct BufRecordsIter<I, T> {
iter: I,
Expand Down
67 changes: 41 additions & 26 deletions tabled/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
//! You can use [`Tabled`] trait if the data type is known.
//! Or you can use [`Builder`] to construct the table from scratch.
//!
//! ## Usage
//! ## Derive
//!
//! If you want to build a table for your custom type.
//! A starting point is to a anotate your type with `#[derive(Tabled)]`.
Expand Down Expand Up @@ -55,9 +55,12 @@
//! assert_eq!(table, expected);
//! ```
//!
//! Not all types can derive [`Tabled`] trait though.
//! BEWARE not all types can derive [`Tabled`] trait.
//! The example below can't be compiled.
//!
//! Because `tabled` must know what we're up to print as a field, so
//! each field must implement [`std::fmt::Display`].
//!
//! ```rust,compile_fail
//! # use tabled::Tabled;
//! #[derive(Tabled)]
Expand All @@ -68,8 +71,7 @@
//! struct SomeOtherType;
//! ```
//!
//! Because `tabled` must know what we're up to print as a field, so
//! each (almost) field must implement [`std::fmt::Display`].
//! You can tweak it by derive options.
//!
//! ### Default implementations
//!
Expand All @@ -92,7 +94,7 @@
//! # assert_eq!(table.to_string(), expected);
//! ```
//!
//! ### Dynamic table
//! ### Builder
//!
//! When you data scheme is not known at compile time.
//! You most likely will not able to relay on [`Tabled`] trait.
Expand Down Expand Up @@ -171,14 +173,21 @@
//!
//! You can use many settings which is found in [`tabled::settings`] module.
//!
//! # Features
//!
//! - `std` - Used by default. If not its considered `no_std` with a limited set of functionality.
//! - `derive` - Used by default. A support for `Tabled` derive macro.
//! - `ansi` - A support for ANSI sequences.
//! - `macros` - A support for `row!`, `col!` macro.
//!
//! # Advanced
//!
//! ## Alloc
//! ## Table types
//!
//! [`Table`] keeps data buffered, which sometimes not ideal choise.
//! For such reason there is [`IterTable`] and [`CompactTable`].
//!
//! ### Less allocations
//! ### [`IterTable`]
//!
//! [`IterTable`] stands on a middle ground between [`Table`] and [`CompactTable`].
//!
Expand All @@ -205,9 +214,9 @@
//! );
//! ```
//!
//! ## Alloc free (`#nostd`)
//! ### [`CompactTable`]
//!
//! [`CompactTable`] can be configured ('1) to not make any allocations.
//! Alloc free can be configured ('1) to not make any allocations.
//! But the price is that the set of settings which can be applied to it is limited.
//!
//! It also can be printed directly to [`fmt::Write`] to not have any intermidiaries.
Expand Down Expand Up @@ -237,6 +246,10 @@
//! table.fmt(StubWriter);
//! ```
//!
//! ## `no_std`
//!
//! [`CompactTable`] can be used in `no_std` context.
//!
//! ## More information
//!
//! You can find more examples of settings and attributes in
Expand Down Expand Up @@ -275,6 +288,8 @@
)]
#![allow(clippy::uninlined_format_args)]

mod util;

#[cfg(feature = "std")]
mod tabled;

Expand All @@ -294,12 +309,12 @@ pub mod grid;
#[cfg_attr(docsrs, doc(cfg(feature = "std")))]
pub use crate::{tabled::Tabled, tables::Table};

/// A derive to implement a [`Tabled`] trait.
/// A derive macro to implement a [`Tabled`] trait.
///
/// The macros available only when `derive` feature in turned on (and it is by default).
/// The macro available only when `derive` feature in turned on (and it is by default).
///
/// To be able to use the derive each field must implement `std::fmt::Display`.
/// The following example will cause a error because of that.
/// The following example will cause an error because of that.
///
/// ```rust,compile_fail
/// use tabled::Tabled;
Expand All @@ -323,9 +338,9 @@ pub use crate::{tabled::Tabled, tables::Table};
/// #[derive(Tabled)]
/// struct Person {
/// #[tabled(rename = "Name")]
/// first_name: &'static str,
/// first_name: String,
/// #[tabled(rename = "Surname")]
/// last_name: &'static str,
/// last_name: String,
/// }
/// ```
///
Expand All @@ -342,8 +357,8 @@ pub use crate::{tabled::Tabled, tables::Table};
/// struct Person {
/// id: u8,
/// #[tabled(skip)]
/// number: &'static str,
/// name: &'static str,
/// number: String,
/// name: String,
/// }
/// ```
///
Expand All @@ -358,9 +373,9 @@ pub use crate::{tabled::Tabled, tables::Table};
/// struct Person {
/// id: u8,
/// #[tabled(order = 0)]
/// number: &'static str,
/// number: String,
/// #[tabled(order = 1)]
/// name: &'static str,
/// name: String,
/// }
/// ```
///
Expand Down Expand Up @@ -427,10 +442,10 @@ pub use crate::{tabled::Tabled, tables::Table};
/// #[tabled(rename_all = "CamelCase")]
/// struct Person {
/// id: u8,
/// number: &'static str,
/// name: &'static str,
/// number: String,
/// name: String,
/// #[tabled(rename_all = "snake_case")]
/// middle_name: &'static str,
/// middle_name: String,
/// }
/// ```
///
Expand All @@ -445,14 +460,14 @@ pub use crate::{tabled::Tabled, tables::Table};
/// #[derive(Tabled)]
/// struct Person {
/// id: u8,
/// name: &'static str,
/// name: String,
/// #[tabled(inline)]
/// ed: Education,
/// }
///
/// #[derive(Tabled)]
/// struct Education {
/// uni: &'static str,
/// uni: String,
/// graduated: bool,
/// }
/// ```
Expand All @@ -466,12 +481,12 @@ pub use crate::{tabled::Tabled, tables::Table};
/// enum Vehicle {
/// #[tabled(inline("Auto::"))]
/// Auto {
/// model: &'static str,
/// engine: &'static str,
/// model: String,
/// engine: String,
/// },
/// #[tabled(inline)]
/// Bikecycle(
/// &'static str,
/// String,
/// #[tabled(inline)] Bike,
/// ),
/// }
Expand Down
5 changes: 5 additions & 0 deletions tabled/src/settings/color/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,11 @@ impl Color {
Self { inner }
}

/// Creates a new empty [`Color`]`.
pub fn empty() -> Self {
Self::new_static("", "")
}

const fn new_static(prefix: &'static str, suffix: &'static str) -> Self {
let color = StaticColor::new(prefix, suffix);
let inner = ColorInner::Static(color);
Expand Down
3 changes: 3 additions & 0 deletions tabled/src/settings/concat/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ use crate::{
/// [`Concat`] in horizontal mode has similar behaviour to tuples `(a, b)`.
/// But it behaves on tables rather than on an actual data.
///
/// [`Concat`] DOES NOT handle style merge and other configuration of 2nd table,
/// it just uses 1st one as a bases.
///
/// # Example
///
///
Expand Down
8 changes: 4 additions & 4 deletions tabled/src/settings/height/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -119,8 +119,8 @@ impl Height {
/// +---------------------+------+------------+",
/// )
/// ```
pub fn increase<W: Measurement<Height>>(width: W) -> CellHeightIncrease<W> {
CellHeightIncrease::new(width)
pub fn increase<W: Measurement<Height>>(height: W) -> CellHeightIncrease<W> {
CellHeightIncrease::new(height)
}

/// Create [`CellHeightLimit`] to set a table/cell height.
Expand Down Expand Up @@ -189,8 +189,8 @@ impl Height {
/// +--+--+--+",
/// );
/// ```
pub fn limit<W: Measurement<Height>>(width: W) -> CellHeightLimit<W> {
CellHeightLimit::new(width)
pub fn limit<W: Measurement<Height>>(height: W) -> CellHeightLimit<W> {
CellHeightLimit::new(height)
}

/// Create [`HeightList`] to set a table height to a constant list of row heights.
Expand Down
Loading

0 comments on commit 184abb2

Please sign in to comment.