Skip to content

Conversation

@yui-915
Copy link
Contributor

@yui-915 yui-915 commented Nov 7, 2025

Introduces new helper methods to make some common patterns less verbose.

  • xs.items.add(i) -> xs.at(i)

    • returns *mut T instead of T to allow assignment like *xs.at(i) = x;.
    • couldn't find a better name (get would imply returning a value).
    • doesn't do any bounds checking (read comment).
    • using it in generic da_* function requires adding a Copy constraint to T ,
      but this should be fine as crust™ requires all types to be Clone + Copy.
  • for i in 0..xs.count { let x = *xs.at(i); /*...*/ } -> for x in xs.iter() { /*...*/ }

    • for iterating over values (T).
  • for i in 0..xs.count { let x = xs.at(i); /*...*/ } -> for x in xs.iter_mut() { /*...*/ }

    • for iterating over pointers (*mut T, can implicitly convert to *const T).
  • existing functions like da_last and da_last_mut can be turned into methods but I kept them as-is for backwards compatibility (da_append would be tricky to get working as a method without references).

  • The last commit is more or less an excuse for me to use Array::iter() more, feel free to drop it if you feel it's unnecessary.

to replace the common case of
```
for i in 0..xs.count {
    let x = xs.at(i);
    // ..
}
```
Use `Array::iter()` where possible.

Keep backwards compatibilty by not touching the signature of:
- get_apis
- TargetAPI
- da_append_many
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

Successfully merging this pull request may close these issues.

1 participant