# Dedicated Coordinate struct or coordinates as args?

**URL:** <https://users.rust-lang.org/t/dedicated-coordinate-struct-or-coordinates-as-args/140493>\
**Category:** help\
**Created:** [June 5, 2026, 10:24pm UTC](https://users.rust-lang.org/t/dedicated-coordinate-struct-or-coordinates-as-args/140493 "2026-06-05T22:24:58Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![left-alert-chaos](https://sea1.discourse-cdn.com/flex019/user_avatar/users.rust-lang.org/left-alert-chaos/32/50869_2.png) [@left-alert-chaos](https://users.rust-lang.org/u/left-alert-chaos)\
**Post date:** [June 5, 2026, 10:24pm UTC](https://users.rust-lang.org/t/dedicated-coordinate-struct-or-coordinates-as-args/140493/1 "2026-06-05T22:24:58Z")

</div>

For some context, I wrote a semi-functional chess engine in Python, and I'm learning Rust by porting it over. The functions in the Python project that operated on locations took the coordinates as different arguments, like: `def __init__ (self, from_col: str, from_row: int, to_col: str, to_row: int ...`  
However, I could alternatively use a Coordinate struct:

```Rust
pub struct Coordinate {
    pub(crate) row: usize,
    pub(crate) col: char,
}

```

Which would be better in your view?

---

<div class="post-metadata">

**Author:** ![tczajka](https://sea1.discourse-cdn.com/flex019/user_avatar/users.rust-lang.org/tczajka/32/24743_2.png) [@tczajka](https://users.rust-lang.org/u/tczajka)\
**Post date:** [June 5, 2026, 11:07pm UTC](https://users.rust-lang.org/t/dedicated-coordinate-struct-or-coordinates-as-args/140493/2 "2026-06-05T23:07:20Z")

</div>

A struct is better. However, it's even better to have the struct internally store its coordinates as integers from 0 to 7 (or a single integer from 0 to 63). You can convert to and from strings by having the struct implement the `FromStr` and `Display` traits.

---

<div class="post-metadata">

**Author:** ![left-alert-chaos](https://sea1.discourse-cdn.com/flex019/user_avatar/users.rust-lang.org/left-alert-chaos/32/50869_2.png) [@left-alert-chaos](https://users.rust-lang.org/u/left-alert-chaos)\
**Post date:** [June 5, 2026, 11:33pm UTC](https://users.rust-lang.org/t/dedicated-coordinate-struct-or-coordinates-as-args/140493/3 "2026-06-05T23:33:35Z")

</div>

Thanks for your reply. The `col` field is a character to make development easier. When the board is fetching a square, it converts the `col` to a `usize`.  
However, as I say this I can see that that's unnecessary overhead.

---

<div class="post-metadata">

**Author:** ![system](https://sea1.discourse-cdn.com/flex019/user_avatar/users.rust-lang.org/system/32/51372_2.png) [@system](https://users.rust-lang.org/u/system)\
**Post date:** [September 3, 2026, 11:34pm UTC](https://users.rust-lang.org/t/dedicated-coordinate-struct-or-coordinates-as-args/140493/4 "2026-09-03T23:34:33Z")

</div>

Closed on September 3, 2026, 11:34pm UTC

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.
