I’m wondering with my game project how best to handle types. I’m basically fetching all the rows in a particular table and creating a struct to represent that data. I then have like 5 or 6 sequential steps I’m trying to go through where I need to modify those initial values from the db.

My first thought was to have a base type called ‘BaseArmy’, then I needed to add new temporary properties that are not in the db and not represented in the original struct, so I decided to create a new struct ‘Army’. The problem is I keep running into errors when passing converting from BaseArmy to Army. I tried writing a From impl, but it wasn’t working (and I’m not even sure if it’s the approach I should be taking).

So should I:

  1. Have multiple different types to handle these kinds of cases
  2. Have just one type somehow where I add properties to it? If so, how? I recently tried using Options for the fields that are not initially available, and that seems to be working but it feels weird.
  • @[email protected]
    link
    fedilink
    21 year ago

    I don’t know how you’re trying to do this BaseArmy / Army conversion. Perhaps you should try and show this code?