Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Vector<F> trait #147

Open
Chris00 opened this issue Mar 23, 2024 · 1 comment
Open

Vector<F> trait #147

Chris00 opened this issue Mar 23, 2024 · 1 comment

Comments

@Chris00
Copy link
Contributor

Chris00 commented Mar 23, 2024

Many GSL functions take a slice &[F] (with F being f32, f64), a stride, and a length (not always checked to be sound in the higher level bindings). What about having a trait such as

trait Vector<F> {
    fn len(&self) -> usize;
    fn stride(&self) -> usize;
    fn as_slice(&self) -> &[F];
    fn as_slice_mut(&mut self) -> &mut [F];
}

which could be implemented for various types (all that implement AsRef<[f64]> but maybe also (impl AsRef<[f64]>, usize) to specify a stride,...). The length would never be passed to the functions, restricting the slice would be the way to go.

@GuillaumeGomez
Copy link
Owner

This is a pretty good idea if it allows to use more types for the same APIs. 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants