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

feature request: add convenient [] operator to std::vec::Vec #13031

Closed
alsam opened this issue Mar 20, 2014 · 6 comments
Closed

feature request: add convenient [] operator to std::vec::Vec #13031

alsam opened this issue Mar 20, 2014 · 6 comments

Comments

@alsam
Copy link

alsam commented Mar 20, 2014

Dear Developers,

Rust language occurred to be amazingly suitable for many programming tasks.
For example, I successfully completed in Rust Coursera Illinois VLSI CAD: Logic to Layout one of the programming assignments and going to use Rust for the others.
Unfortunately after recent changes to the language the Rust code for the completed assignment occurred to be broken. No problem with it as the language evolves.

But the following constructs proposed for the new vec_ng::Vec design (below) v.get(1) and especially *v.get_mut(1) instead of used to be [] are bulky and over-complicated in my opinion:

use std::io::println;
use std::vec::Vec;

fn main()
{
    let mut v = vec!(1, 2, 3);
    //let elem = v[1];
    let elem = v.get(1);
    //v[1] = 4;
    *v.get_mut(1) = 4;
}

Could you please add more usual [] index access to std::vec_ng::Vec design?
Thanks!

@alsam alsam changed the title feature request: add convenient [] operator to std::vec_ng::Vec feature request: add convenient [] operator to std::vec::Vec Mar 20, 2014
@huonw
Copy link
Member

huonw commented Mar 20, 2014

I agree that [] syntax is nice, unfortunately our current index overloading technique needs an overhaul: #6515

When #6515 gets fixed, Vec will be the first thing to use the new traits.

@alsam
Copy link
Author

alsam commented Mar 20, 2014

Ok, thanks for clarification.

@thestinger
Copy link
Contributor

I don't think we need this as another issue. I've already mentioned this in #11875.

@alsam
Copy link
Author

alsam commented Jul 18, 2014

Dear Developers,
Just noticed that convenient [] works from the box for read accesses for 0.11, e.g.
let elem = v[1]; instead of deprecated let elem = v.get(1);
However wasn't able to figure out how to write:
any attempt to write to the vector, e.g. v[1] = 4; leads to error:
error: cannot assign to immutable dereference (dereference is implicit, due to indexing)
in documentation for http://doc.rust-lang.org/std/vec/struct.Vec.html
it is noted that get_mut is deprecated.
Could you please give a working example for write mutable access to vector elements?
Thanks!

@huonw
Copy link
Member

huonw commented Jul 19, 2014

@alsam #12825 means that mutable indexing doesn't work as we'd like it yet, so we haven't changed the old form yet, that is, *v.get_mut(1) = 4; is still the correct way to write to a vector (I believe only get is deprecated, get_mut is still experimental).

@alsam
Copy link
Author

alsam commented Jul 19, 2014

@huonw Thanks a lot for clarification!

lnicola pushed a commit to lnicola/rust that referenced this issue Aug 23, 2022
fix: resolve associated types of bare dyn types

Fixes rust-lang#13031

We've been dropping the associated type bindings of trait object types that were written without the `dyn` keyword. This patch reuses the lowering logic for `TypeRef::DynTrait` so the associated type bindings are properly lowered.
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

3 participants