I'm working on a geometry crate and I thought in order for things to work nicely I should use Rc when referencing shared points. For example:
struct Point {
point: Vec4,
}
struct Line {
points: [Rc<Point>; 2],
}
struct Tri {
points: [Weak<Point>; 3],
edges: [Rc<Line>; 3],
}
struct Tetra {
points: [Weak<Point>; 4],
edges: [Weak<Line>; 6],
faces: [Rc<Tri>; 4],
}
This makes sense as it seems to be the most efficient way to keep track of the components of a simplex. The problem is in the API. I don't want to expose this Rc internal, and I'd like it if I can just pass references in. For example, something like this:
let points = [Point::new(p0), Point::new(p1), Point::new(p2), Point::new(p3)];
let tris = [
Tri::new(&points[0], &points[1], &points[2]),
Tri::new(&points[2], &points[3], &points[0])
];
Etc. Without the user having to explicitly deal with Rc themselves.
What sort of pattern do we typically see here?