You are viewing a single thread.
View all comments View context
1 point
*

Do you mean this for loop?

for shape in &shapes {
  accum += shape.area();
}

That does use an iterator

for-in-loops, or to be more precise, iterator loops, are a simple syntactic sugar over a common practice within Rust, which is to loop over anything that implements IntoIterator until the iterator returned by .into_iter() returns None (or the loop body uses break).

Anti Commercial AI thingy

CC BY-NC-SA 4.0

permalink
report
parent
reply
9 points

I think they meant using for accumulating, like this:

shapes.iter().map(Shape::area).sum()
permalink
report
parent
reply
4 points

Yes. That’s what I meant.

Though I heavily expect the rust compiler to produce identical assembly for both types of iteration.

permalink
report
parent
reply
2 points

Oh, I see. That would be interesting to benchmark too 👍

Anti Commercial AI thingy

CC BY-NC-SA 4.0

permalink
report
parent
reply
2 points

Anti Commercial AI thingy

Off-topic, but does that actually work? I would assume OpenAI would just ignore it and you’d have to prove that they did so.

permalink
report
parent
reply

Rust

!rust@programming.dev

Create post

Welcome to the Rust community! This is a place to discuss about the Rust programming language.

Wormhole

!performance@programming.dev

Credits
  • The icon is a modified version of the official rust logo (changing the colors to a gradient and black background)

Community stats

  • 596

    Monthly active users

  • 886

    Posts

  • 3.8K

    Comments