3 ms·
I think it is substantially equivalent to C++ std::span (essentially a typed pointer + length pair).
by loeg 2y ago
I think it is substantially equivalent to C++ std::span (essentially a typed pointer + length pair).
- Dwedit 2y agoSpan<T> is a "ref struct" type, and thus has a lot of restrictions on its use. For instance, you can't have one as a field or property in a class, so you can't assign it to outside of the scope that it was declared in.
- neonsunset 2y agoYou can assign the span to an out of scope variable as long as it does not violate the scoping of the memory referenced by that said span. The closer primitive to C#'s Span<T> is Rust's &mut [T] since both are subject to lifetime analysis (of course the one in C#[0] is quite rudimentary in comparison to Rust). [0]: https://em-tg.github.io/csborrow/ https://em-tg.github.io/csborrow/