Repository: zhiburt/tabled (rust)

Issue:
Infinite loop if empty Table is modified
The following code produces an infinite loop:

    let mut table = tabled::builder::Builder::default().build();
    println!("{}", table
        .with(Modify::new(Columns::new(1..)).with(Alignment::right())));


Pull request description:
tabled/ Fix infinite loop in object with empty table
close #316

Patch:
diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml
index fcdda38..5901010 100644
--- a/.github/workflows/ci.yml
+++ b/.github/workflows/ci.yml
@@ -120,7 +120,7 @@ jobs:
     runs-on: ubuntu-latest
     steps:
       - uses: actions/checkout@v3
-      - uses: dtolnay/rust-toolchain@1.70.0
+      - uses: dtolnay/rust-toolchain@1.61.0
       - run: cargo build --manifest-path=./tabled/Cargo.toml --all-features
 
   fmt:
diff --git a/tabled/src/settings/object/columns.rs b/tabled/src/settings/object/columns.rs
index 7f25f7d..bcbe2ac 100644
--- a/tabled/src/settings/object/columns.rs
+++ b/tabled/src/settings/object/columns.rs
@@ -197,7 +197,7 @@ impl Iterator for ColumnsIter {
     type Item = Entity;
 
     fn next(&mut self) -> Option<Self::Item> {
-        if self.start == self.end {
+        if self.start >= self.end {
             return None;
         }
 
diff --git a/tabled/src/settings/object/mod.rs b/tabled/src/settings/object/mod.rs
index be3a50a..f5b3151 100644
--- a/tabled/src/settings/object/mod.rs
+++ b/tabled/src/settings/object/mod.rs
@@ -490,6 +490,7 @@ mod tests {
         );
         assert_eq!(vec_cells(Columns::new(2..), 2, 3), [Entity::Column(2)]);
         assert_eq!(vec_cells(Columns::new(3..), 2, 3), []);
+        assert_eq!(vec_cells(Columns::new(3..), 0, 0), []);
         assert_eq!(vec_cells(Columns::new(0..1), 2, 3), [Entity::Column(0)]);
         assert_eq!(vec_cells(Columns::new(1..2), 2, 3), [Entity::Column(1)]);
         assert_eq!(vec_cells(Columns::new(2..3), 2, 3), [Entity::Column(2)]);
@@ -544,6 +545,7 @@ mod tests {
         );
         assert_eq!(vec_cells(Rows::new(1..), 2, 3), [Entity::Row(1)]);
         assert_eq!(vec_cells(Rows::new(2..), 2, 3), []);
+        assert_eq!(vec_cells(Rows::new(2..), 0, 0), []);
         assert_eq!(vec_cells(Rows::new(0..1), 2, 3), [Entity::Row(0)],);
         assert_eq!(vec_cells(Rows::new(1..2), 2, 3), [Entity::Row(1)],);
         assert_eq!(vec_cells(Rows::new(..), 0, 0), []);
diff --git a/tabled/src/settings/object/rows.rs b/tabled/src/settings/object/rows.rs
index a1c251f..b32e79a 100644
--- a/tabled/src/settings/object/rows.rs
+++ b/tabled/src/settings/object/rows.rs
@@ -201,7 +201,7 @@ impl Iterator for RowsIter {
     type Item = Entity;
 
     fn next(&mut self) -> Option<Self::Item> {
-        if self.start == self.end {
+        if self.start >= self.end {
             return None;
         }
 
diff --git a/tabled_derive/src/lib.rs b/tabled_derive/src/lib.rs
index e50a145..e1fa632 100644
--- a/tabled_derive/src/lib.rs
+++ b/tabled_derive/src/lib.rs
@@ -45,7 +45,7 @@ fn impl_tabled(ast: &DeriveInput) -> TokenStream {
     let name = &ast.ident;
     let (impl_generics, ty_generics, where_clause) = ast.generics.split_for_impl();
     let expanded = quote! {
-        impl #impl_generics Tabled for #name #ty_generics #where_clause {
+        impl #impl_generics ::tabled::Tabled for #name #ty_generics #where_clause {
             const LENGTH: usize = #length;
 
             fn fields(&self) -> Vec<::std::borrow::Cow<'_, str>> {


Test patch:
diff --git a/tabled/tests/derive_test.rs b/tabled/tests/derive_test.rs
index 34ec8ca..d27e43e 100644
--- a/tabled/tests/derive_test.rs
+++ b/tabled/tests/derive_test.rs
@@ -1080,3 +1080,11 @@ fn test_skip_enum_0() {
     assert_eq!(Letters::Consonant('c').fields(), vec!["", "+"]);
     assert_eq!(Letters::Digit.fields(), vec!["", ""]);
 }
+
+mod __ {
+    #[test]
+    fn dont_import_the_trait() {
+        #[derive(tabled::Tabled)]
+        struct __;
+    }
+}