Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Going through all the documentation and trying to use #15

Merged
merged 5 commits into from
Jul 15, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion examples/default_array.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ fn main() {
fn matrix<const N: usize>() -> [[usize; N]; N] {
let mut matrix = [[0; N]; N];

#[allow(clippy::clippy::needless_range_loop)]
#[allow(clippy::needless_range_loop)]
for i in 0..N {
for j in 0..N {
matrix[i][j] = (i + 1) * (j + 1);
Expand Down
4 changes: 2 additions & 2 deletions papergrid/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ impl Grid {
self.size.0 += 1;
}

/// Remove_row removes a `row` from a grid.
/// Removes a `row` from a grid.
///
/// The row index must be started from 0
pub fn remove_row(&mut self, row: usize) {
Expand All @@ -190,7 +190,7 @@ impl Grid {
self.size.0 -= 1;
}

/// Remove_row removes a `column` from a grid.
/// Removes a `column` from a grid.
///
/// The column index must be started from 0
pub fn remove_column(&mut self, column: usize) {
Expand Down
18 changes: 11 additions & 7 deletions src/alignment.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
use crate::CellOption;
#[allow(unused)]
use crate::Table;
use papergrid::{AlignmentHorizontal, AlignmentVertical, Entity, Grid, Settings};

/// Alignment represent a horizontal and vertical alignemt setting for a [`Table`](./struct.Table.html)
/// Alignment represent a horizontal and vertical alignemt setting for a [Table].
///
/// ```rust,no_run
/// # use tabled::{Style, Alignment, Modify, Row, Table};
Expand All @@ -15,40 +17,42 @@ pub enum Alignment {
}

impl Alignment {
/// Top constructs a vertical alignment to TOP
/// Top constructs a vertical alignment to [AlignmentVertical::Top]
pub fn top() -> Self {
Self::vertical(AlignmentVertical::Top)
}

/// Bottom constructs a vertical alignment to BOTTOM
/// Bottom constructs a vertical alignment to [AlignmentVertical::Bottom]
pub fn bottom() -> Self {
Self::vertical(AlignmentVertical::Bottom)
}

/// Center_vertical constructs a vertical alignment to CENTER
/// Center_vertical constructs a vertical alignment to [AlignmentVertical::Center]
pub fn center_vertical() -> Self {
Self::vertical(AlignmentVertical::Center)
}

/// Left constructs a horizontal alignment to LEFT
/// Left constructs a horizontal alignment to [AlignmentHorizontal::Left]
pub fn left() -> Self {
Self::horizontal(AlignmentHorizontal::Left)
}

/// Right constructs a horizontal alignment to RIGHT
/// Right constructs a horizontal alignment to [AlignmentHorizontal::Right]
pub fn right() -> Self {
Self::horizontal(AlignmentHorizontal::Right)
}

/// Center_horizontal constructs a horizontal alignment to CENTER
/// Center_horizontal constructs a horizontal alignment to [AlignmentHorizontal::Center]
pub fn center_horizontal() -> Self {
Self::horizontal(AlignmentHorizontal::Center)
}

/// Returns an alignment with the given horizontal alignment.
fn horizontal(alignment: AlignmentHorizontal) -> Self {
Self::Horizontal(alignment)
}

/// Returns an alignment with the given vertical alignment.
fn vertical(alignment: AlignmentVertical) -> Self {
Self::Vertical(alignment)
}
Expand Down
4 changes: 3 additions & 1 deletion src/disable.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
#[allow(unused)]
use crate::Table;
use crate::{bounds_to_usize, TableOption};
use papergrid::Grid;
use std::ops::RangeBounds;

/// Disable represent a disable setting for a [`Table`](./struct.Table.html)
/// Disable represent a disable setting for a [Table].
///
/// ```rust,no_run
/// # use tabled::{Disable, Table};
Expand Down
2 changes: 1 addition & 1 deletion src/formating.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::CellOption;
use papergrid::{Entity, Grid, Settings};

/// Format a structure which modifies a `Grid`
/// Format a structure which modifies a [Grid]
///
/// # Example
///
Expand Down
2 changes: 1 addition & 1 deletion src/indent.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::CellOption;
use papergrid::{Entity, Grid, Settings};

/// Indent is responsilbe for a left/right/top/bottom indent.
/// Indent is responsible for a left/right/top/bottom indent.
///
/// ```rust,no_run
/// # use tabled::{Style, Indent, Row, Table, Modify};
Expand Down
27 changes: 11 additions & 16 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ pub use crate::{
pub use papergrid;
pub use tabled_derive::Tabled;

/// Tabled a trait responsible for providing a header filds and a row fields.
/// Tabled a trait responsible for providing a header fields and a row fields.
///
/// It's urgent that `header` len is equal to `fields` len.
///
Expand All @@ -163,11 +163,11 @@ where
}
}

/// A trait for configuring a `Grid`.
/// A trait for configuring a [Grid].
///
/// Mainly was created to be able to have a variadic set of parameters in a [the `table` macros](./macros.table.html)
pub trait TableOption {
/// Modification function of a `Grid`
/// Modification function of a [Grid]
fn change(&self, grid: &mut Grid);
}

Expand All @@ -180,13 +180,13 @@ where
}
}

/// CellOption is trait for configuring a `Cell` which represented by 'row' and 'column' indexes.
/// CellOption is trait for configuring a [Cell] which represented by 'row' and 'column' indexes.
pub trait CellOption {
/// Modification function of a `Cell`
/// Modification function of a [Cell]
fn change_cell(&self, grid: &mut Grid, row: usize, column: usize);
}

/// Table structure provides an interface for building a table for types that implements [`Tabled`].
/// Table structure provides an interface for building a table for types that implements [Tabled].
///
/// # Example
///
Expand All @@ -201,8 +201,7 @@ pub trait CellOption {
///
/// ## A list of settings
///
/// It may take a list of arguments such as [`Style`](./enum.Style.html),
/// [`Alignment`](./struct.Alignment.html), [`ChangeRing`](./struct.ChangeRing.html)
/// It may take a list of arguments such as [Style] and [Alignment].
///
/// ```rust,no_run
/// use tabled::{Table, Style, Alignment, Full, Modify};
Expand All @@ -213,7 +212,6 @@ pub trait CellOption {
/// println!("{}", table);
/// ```
///
/// [`Tabled`]: ./trait.Tabled.html
pub struct Table {
grid: Grid,
}
Expand Down Expand Up @@ -242,9 +240,8 @@ impl fmt::Display for Table {
}
}

/// Modify structure provide a conviniet way for applying a set of [`CellOption`]s to the same object.
/// Modify structure provide a conviniet way for applying a set of [CellOption]s to the same object.
///
/// [`CellOption`]: trait.CellOption.html
pub struct Modify<O> {
obj: O,
modifiers: Vec<Box<dyn CellOption>>,
Expand All @@ -254,18 +251,16 @@ impl<O> Modify<O>
where
O: Object,
{
/// New creates a instance of Modify structure
/// Creates a new [Modify] without any options.
pub fn new(obj: O) -> Self {
Self {
obj,
modifiers: Vec::new(),
}
}

/// With a generic function which stores a [`CellOption`] to apply it later to an [`Object`]
/// With a generic function which stores a [CellOption] to apply it later to an [Object]
///
/// [`CellOption`]: trait.CellOption.html
/// [`Object`]: trait.Object.html
pub fn with<F>(mut self, f: F) -> Self
where
F: CellOption + 'static,
Expand All @@ -290,7 +285,7 @@ where
}
}

/// Build_grid function build a [`Grid`](../papergrid/struct.Grid.html) from a data.
/// Build_grid function build a [Grid] from a data.
/// A [`table` macros](./macro.table.html) should be prefered over this function.
pub fn build_grid<T: Tabled>(iter: impl IntoIterator<Item = T>) -> Grid {
let headers = T::headers();
Expand Down
12 changes: 7 additions & 5 deletions src/object.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
#[allow(unused)]
use papergrid::Grid;
use std::{
collections::BTreeSet,
ops::{Bound, RangeBounds},
};

/// Object helps to locate a nessesary part of a `Grid`.
/// Object helps to locate a nessesary part of a [Grid].
pub trait Object: Sized {
/// Cells returns a set of cordinates of cells
fn cells(&self, count_rows: usize, count_columns: usize) -> Vec<(usize, usize)>;
Expand Down Expand Up @@ -36,7 +38,7 @@ impl Object for Head {
}
}

/// Head represent all cells on a `Grid`
/// Head represent all cells on a [Grid]
pub struct Full;

impl Object for Full {
Expand All @@ -52,7 +54,7 @@ impl Object for Full {
}
}

/// Row denotes a set of cells on given rows on a `Grid`
/// Row denotes a set of cells on given rows on a [Grid]
pub struct Row<R: RangeBounds<usize>>(pub R);

impl<R: RangeBounds<usize>> Object for Row<R> {
Expand All @@ -66,7 +68,7 @@ impl<R: RangeBounds<usize>> Object for Row<R> {
}
}

/// Column denotes a set of cells on given columns on a `Grid`
/// Column denotes a set of cells on given columns on a [Grid]
pub struct Column<R: RangeBounds<usize>>(pub R);

impl<R: RangeBounds<usize>> Object for Column<R> {
Expand All @@ -80,7 +82,7 @@ impl<R: RangeBounds<usize>> Object for Column<R> {
}
}

/// Cell denotes a particular of cells on a `Grid`
/// Cell denotes a particular of cells on a [Grid].
pub struct Cell(pub usize, pub usize);

impl Object for Cell {
Expand Down
7 changes: 4 additions & 3 deletions src/panel.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
#[allow(unused)]
use crate::Disable;
use crate::TableOption;
use papergrid::{Entity, Grid, Settings};

/// Panel allows to add a custom panel to table.
///
/// Don't use `Disable` after the calling `Panel`.
#[derive(Debug)]
pub struct Panel<S: AsRef<str>>(pub S, pub usize);

Expand All @@ -20,7 +21,7 @@ impl<S: AsRef<str>> TableOption for Panel<S> {
}

/// Header renders information at the top.
/// see `Panel`
/// See [Panel]
#[derive(Debug)]
pub struct Header<S: AsRef<str>>(pub S);

Expand All @@ -31,7 +32,7 @@ impl<S: AsRef<str>> TableOption for Header<S> {
}

/// Footer renders information at the bottom.
/// see `Panel`
/// See [Panel]
#[derive(Debug)]
pub struct Footer<S: AsRef<str>>(pub S);

Expand Down
2 changes: 1 addition & 1 deletion src/style.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use crate::TableOption;

/// Style is responsible for a look of a table.
///
/// It's suppose to take only 1 type of `Line`s short or bordered.
/// It's suppose to take only 1 type of [Line]s short or bordered.
///
/// # Example
///
Expand Down
2 changes: 1 addition & 1 deletion src/width.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::CellOption;
use papergrid::{Entity, Grid, Settings};

/// Format a structure which modifies a `Grid`
/// Format a structure which modifies a [Grid]
pub struct MaxWidth<S>(pub usize, pub S)
where
S: AsRef<str>;
Expand Down