Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

> The "safe" solution recommended by the rustaceans was to use integers as references to the data in a vec or hashmap

This is not correct advice; not sure why you've been given this answer.

There are a couple of solutions.

1. you use a data structure (library) that returns you a handler, which can be an int, but it's not an int as in "position inside a vec" (index), but a symbolic reference, whose management is deferred to the library.

You can't use an index directly because if a position is freed, then taken, you will hold an invalid reference (int).

This is a handy solution, convenient to work with; if you do something wrong, you'll get an error from the library.

2. the manual solution is to use strong/weak references, which are quite ugly to use :)



Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: