Implement `Debug` for `ViewRepr`

Open
#1,057 6 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
35/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Stale
Tech stack
rust
Domain
data

Research direction

Start by locating the ViewRepr definition and its existing trait implementations. Implement the requested Debug support, then verify that the generic example in the issue compiles and that formatting a view works as shown.

Written by the indexing model from the issue text.

Description

Basically if you ever try to write a function that is generic over any array subtype (ArrayView, Array etc), then you aren't able to use debug features, because ViewRepr doesn't implement Debug:

use ndarray::*;
use core::fmt::Debug;
fn print_arr<S: Data<Elem=T> + Debug, T: Debug>(array: &ArrayBase<S, Ix1>){
    dbg!(array);
}
fn main(){
    let arr = array![1, 2, 3];
    print_arr(&arr);
    print_arr(&arr.view());
}
    print_arr(&arr.view());
              ^^^^^^^^^^^ `ViewRepr<&{integer}>` cannot be formatted using `{:?}` because it doesn't implement `Debug`
`ViewRepr<&{integer}>` doesn't implement `Debug`
help: the trait `Debug` is not implemented for `ViewRepr<&{integer}>`

Here's a playground link: https://play.rust-lang.org/?version=stable&mode=debug&edition=2018&gist=9754536345631a70374f14d3703050cf.

Happy to write a PR but it looks like PR review is pretty slow at the moment so I'll hold off until this issue has been approved.

Dominant language
Rust
Stars
4.3k
Forks
391
PR merge metrics
No merged PRs in 30d

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from rust-ndarray/ndarray

All issues in rust-ndarray/ndarray

Similar issues

More Rust issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.