copyspan 0.1.0

An alternative to `Range<T>` that has a defined memory layout and implements `Copy`
Documentation
  • Coverage
  • 64.29%
    9 out of 14 items documented3 out of 12 items with examples
  • Size
  • Source code size: 8.38 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 1.71 MB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 13s Average build duration of successful builds.
  • all releases: 10s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • wr7/copyspan
    0 0 0
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • wr7

A an alternative to Range<T> that has a defined memory layout, implements [std::marker::Copy], and has some convenience methods.

use copyspan::Span;

let text = "hello world";
let s = Span::from(6..11);

for i in s {
    dbg!(i);
}

// Because `Span` is copyable, we can reuse it without calling `clone`
assert_eq!(&text[s], "world");
assert_eq!(&text[s.with_len(2)], "wo");

This is also useful for making copyable datastructures that contain ranges.

use copyspan::Span;
use std::ops::Range;

#[derive(Clone, Copy, Default)]
struct HoldsSpan {
    x: Span<usize>,
}

fn expects_range(_: Range<usize>) {}
fn takes_val(_: HoldsSpan) {}

let val = HoldsSpan::default();
takes_val(val); // If `HoldSpan` wasn't `Copy`, `val` would be moved into this function

expects_range(val.x.range());