rust and java: Enforce max_edges *before* traversing edges
max_edges was only implemented in a way that any node seen after max_edges is reached is discarded. However, the more sensible semantic is to stop reading edges after max_edges is reached.
This includes significant changes to the Rust code in order to avoid unnecessary accesses to graph.outdegree().