Skip to content

into_scalar() for 0-dimensional array views #688

Closed

Description

@Palladinium

Array0 has the handy into_scalar() method, which from what I gather roughly equates to calling arr.index(Ix0()).

Unfortunately, this isn't available for array views, so we're stuck using the more obscure and verbose syntax for ArrayView0 and ArrayViewMut0. It looks to me like it'd just be a matter to move the into_scalar() impl up to ArrayBase, letting the view representation choose the return type.

Would it be a breaking change? How difficult would it be to implement?

Activity

  1. bluss commented on Sep 1, 2019

    @bluss
    Member

    arr.index(Ix0()) is the syntax that looks obscure and verbose to me, I'm not sure why you'd use that.

    The standard way of accessing an element in a 0-dim array is to use a 0-dim index and using indexing notation:

    // Alternative A
    let element = array[[]];
    
    // Alternative B
    let element = array[()];
  2. jturner314 commented on Sep 3, 2019

    @jturner314
    Member

    I think @Palladinium may be referring to the .index() method from the IndexLonger trait. It's currently the best way to get an &'a A from an ArrayView0<'a, A, D>. (Note the matching lifetimes.)

    I do think it would make sense to add .into_scalar() methods to ArrayView0 and ArrayViewMut0 for convenience. (Those types specifically, not all of ArrayBase<S, Ix0>.) It would not be a breaking change, and it would be easy to implement.

  3. added
    good first issue
    on Sep 3, 2019
  4. LukeMathWalker commented on Sep 8, 2019

    @LukeMathWalker
    Member

    Solved by #700

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementgood first issue

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions