dimforge / dimforge/nalgebra

Implementing borrow for fixed size types

Open
#216 5 comments 4 reactions 0 assignees View on GitHub
Dominant language
Rust
Stars
4.8k
Forks
565
PR merge metrics
No merged PRs in 30d

Description

Right now most types implement AsRef like Vector3 implements AsRef<[T;3]>.

There's a case where being able to accept both a &[f32;3] or a Vec3 would be useful. For example to create universal apis that can work with any library like:

```rs
fn clear_color>(c: &C)
```

can be called as:

```rs
clear_color( &[1., 1., 1., 1.]);
clear_color(&na::Vector4(1., 1., 1., 1.));
clear_color(&color::Rgba(1., 1., 1., 1.));
```

while AsRef only would support the last 2 cases, it's impossible to take &[f32;4] as AsRef without having some really verbose trait implementation while Borrow has a blanket implementation for any &T.

This would allow to create apis that could take any type with the correct memory structure without having dependencies on any specific library.

Not sure though if this is a correct usage of Borrow or there's a better way to accomplish the same.

I can create a PR request implementing Borrow for any type where it makes sense if this is something that seems useful

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.