#iterator #pointers #iterating

ptr_iter

Iterators to simplify working with pointers

2 releases

0.1.1 Mar 8, 2023
0.1.0 Feb 21, 2023

#2561 in Rust patterns

Download history 47/week @ 2024-07-22 88/week @ 2024-07-29 65/week @ 2024-08-05 59/week @ 2024-08-12 52/week @ 2024-08-19 70/week @ 2024-08-26 54/week @ 2024-09-02 45/week @ 2024-09-09 40/week @ 2024-09-16 74/week @ 2024-09-23 47/week @ 2024-09-30 36/week @ 2024-10-07 58/week @ 2024-10-14 49/week @ 2024-10-21 57/week @ 2024-10-28 46/week @ 2024-11-04

216 downloads per month
Used in 4 crates (via zstring)

Zlib OR Apache-2.0 OR MIT

7KB
57 lines

Docs.rs

ptr_iter

Crate for iterating a pointer.


lib.rs:

A crate with iterators to simplify working with pointers.

Constructing these iterators is unsafe, but once constructed the iteration itself is considered a safe operation.

The two iterators themselves will iterate forever. The constructor functions apply the correct iterator adapters to limit the iteration to stay within safe bounds.

Safety

  • You must always use the iterator before the pointer it's based upon becomes invalidated. This is the same logic as constructing a slice from a raw pointer: If you use a pointer to build a safe type and then invalidate the source pointer, the safe type itself will become invalid too.
  • The iteration is done with the pointer add method, and so these iterators must only be constructed with pointers to valid allocations.

No runtime deps