Open koba-e964 opened 3 years ago
This isn't really a bug, this is intended behavior. We could add another iterator type which returns an enum for either an element or an improper tail.
Also, the direct functions are internal only, but Term
has a list_get_cell
method that you can use instead. With this, you should be able to build your own iterator.
This is documented: https://docs.rs/rustler/0.22.0-rc.0/rustler/struct.Term.html#method.list_get_cell
Last edit: We could probably add a line to the docs of ListIterator
that it can only be used with proper lists, and refer to Term::list_get_cell
for improper lists.
Also, the direct functions are internal only, but Term has a list_get_cell method that you can use instead. With this, you should be able to build your own iterator. This is documented: https://docs.rs/rustler/0.22.0-rc.0/rustler/struct.Term.html#method.list_get_cell
Uh, I overlooked that. Thank you for pointing this out.
Last edit: We could probably add a line to the docs of ListIterator that it can only be used with proper lists, and refer to Term::list_get_cell for improper lists.
It would be great if we had these explanations in the doc.
If
ListIterator
tries to iterate over an improper list, it panics while retrieving its elements.Is it possible for
ListIterator
to fail in a modest way like throwing errors, rather thanpanic!
-ing? Besides, because the functions inrustler::types::list
are hidden, there are no documented ways to decouple improper lists (e.g.rustler::types::lists::list_get_cell
). It would be very helpful if they were documented.Here is the output:
(Code used to reproduce this
panic!
-ing: https://github.com/koba-e964/phx_rust_21/compare/bug/improper-lists)