ReadOnlyArray with stride

Suppose we have:

struct Foo {
  a: usize,
  b: String,
  c: Bar
}

and we have

x: ReadOnlyArray<Foo>

then I expect we should also be able to, in O(1) time, build

ReadOnlyArray<usize>, ReadOnlyArray<String>, ReadOnlyArray<Bar>

basically by keeping everything behind a Rc<Vec<...>> and playing with stride/offsets.

Is there any crate which provides this ?

I think these would be the building blocks. I don't know of a crate.

Nits:

  • It can't be ReadOnlyArray<WholeOrPart> as the actual type; a type parameter can't choose and replace fields like that
  • Array implies static size, Vec implies dynamic size; maybe you meant Rc<[...]>

It isn't too difficult to write:
https://play.rust-lang.org/?version=stable&mode=debug&edition=2018&gist=59e24e84d48cf6ce7661f15b6ffee892

1 Like

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.