Skip to content

Commit

Permalink
Apply suggestions from MR
Browse files Browse the repository at this point in the history
  • Loading branch information
Shir0kamii authored and becheran committed Oct 27, 2023
1 parent fcbfadc commit 6ec6a18
Showing 1 changed file with 29 additions and 15 deletions.
44 changes: 29 additions & 15 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,7 @@ macro_rules! count {
/// assert_eq!(grid.size(), (3, 3))
/// ```
///
/// # Examples
///
/// Not that each row must be of the same length. The following example will not compile:
/// Note that each row must be of the same length. The following example will not compile:
///
/// ``` ignore
/// use grid::grid;
Expand Down Expand Up @@ -136,26 +134,24 @@ macro_rules! grid {
/// In this example a grid of numbers from 1 to 9 is created:
///
/// ```
/// use grid::grid2;
/// let grid = grid2![[1, 2, 3]
/// use grid::grid_cm;
/// let grid = grid_cm![[1, 2, 3]
/// [4, 5, 6]
/// [7, 8, 9]];
/// assert_eq!(grid.size(), (3, 3));
/// assert_eq!(grid[(1, 1)], 5);
/// ```
///
/// # Examples
///
/// Not that each row must be of the same length. The following example will not compile:
/// Note that each row must be of the same length. The following example will not compile:
///
/// ``` ignore
/// use grid::grid2;
/// let grid = grid2![[1, 2, 3]
/// use grid::grid_cm;
/// let grid = grid_cm![[1, 2, 3]
/// [4, 5] // This does not work!
/// [7, 8, 9]];
/// ```
#[macro_export]
macro_rules! grid2 {
macro_rules! grid_cm {
() => {
$crate::Grid::from_vec_with_order(vec![], 0, $crate::Order::ColumnMajor)
};
Expand Down Expand Up @@ -634,6 +630,11 @@ impl<T> Grid<T> {
/// assert_eq!(col_iter.next(), None);
/// ```
///
/// # Performance
///
/// This method will be significantly slower if the grid uses a row-major memory layout,
/// which is the default.
///
/// # Panics
///
/// Panics if the col index is out of bounds.
Expand Down Expand Up @@ -667,6 +668,11 @@ impl<T> Grid<T> {
/// assert_eq!(grid[(0, 1)], 10);
/// ```
///
/// # Performance
///
/// This method will be significantly slower if the grid uses a row-major memory layout,
/// which is the default.
///
/// # Panics
///
/// Panics if the col index is out of bounds.
Expand Down Expand Up @@ -700,6 +706,10 @@ impl<T> Grid<T> {
/// assert_eq!(col_iter.next(), None);
/// ```
///
/// # Performance
///
/// This method will be significantly slower if the grid uses a column-major memory layout.
///
/// # Panics
///
/// Panics if the row index is out of bounds.
Expand Down Expand Up @@ -732,6 +742,10 @@ impl<T> Grid<T> {
/// assert_eq!(grid[(1, 0)], 10);
/// ```
///
/// # Performance
///
/// This method will be significantly slower if the grid uses a column-major memory layout.
///
/// # Panics
///
/// Panics if the row index is out of bounds.
Expand Down Expand Up @@ -2526,13 +2540,13 @@ mod test {

#[test]
fn macro2_empty() {
let grid: Grid<u8> = grid2![];
let grid: Grid<u8> = grid_cm![];
test_grid(&grid, 0, 0, Order::ColumnMajor, &[]);
}

#[test]
fn macro2_init() {
let grid = grid2![[1, 2, 3]
let grid = grid_cm![[1, 2, 3]
[4, 5, 6]
[7, 8, 9]];
let expected = [1, 4, 7, 2, 5, 8, 3, 6, 9];
Expand All @@ -2541,13 +2555,13 @@ mod test {

#[test]
fn macro2_init_char() {
let grid = grid2![['a', 'b']['c', 'd']];
let grid = grid_cm![['a', 'b']['c', 'd']];
test_grid(&grid, 2, 2, Order::ColumnMajor, &['a', 'c', 'b', 'd']);
}

#[test]
fn macro2_one_row() {
let grid = grid2![[1, 2, 3, 4]];
let grid = grid_cm![[1, 2, 3, 4]];
test_grid(&grid, 1, 4, Order::ColumnMajor, &[1, 2, 3, 4]);
}

Expand Down

0 comments on commit 6ec6a18

Please sign in to comment.