Hi! I'm making a 2D tilemap struct (for games that use tilemaps) that will hold tile data - and I'm currently trying to make functions that will allow you to get the tile data.
However, I'm stuck on what type to return. As it stands, some errors can happen while attempting to get the tile data:
- The tile position that the user specifies is not within the bounds of the tilemap
- The tile index (calculated from a
TilePositionstruct which holds two numbers) would overflow ausize.
Because of these two issues, I'm stuck on what the return type of such get_tile functions should be:
- A
Result<&Option<T>, SomeErr>(whereSomeErrdescribes the above errors) - A
Option<&Option<T>>(The outside option isNoneif one of the above error occurs, andSome(_)otherwise).
(The inner Option<T> is because of how the tiles are stored - in a Vec<Option<T>> - and because a tile not existing is not an error. Additionally, I plan to include impls of the Index and IndexMut traits, that will panic upon an error.)
Primarily, I'm not sure whether to consider the tile index calculation (something that's more internal than anything) an error that should be returned. Could anyone provide any advice here?
