1276
9
submitted 3 years ago* (last edited 3 years ago) by nerdblood@programming.dev to c/rust@programming.dev

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.
1277
11
1278
9
1.71.0 pre-release testing (blog.rust-lang.org)
1279
17
submitted 3 years ago* (last edited 3 years ago) by Arbitrary@lemmy.fmhy.ml to c/rust@programming.dev

E:url was changed

1280
11
Rust Analyzer Changelog #189 (rust-analyzer.github.io)
1281
4
IntelliJ Rust Changelog #198 (intellij-rust.github.io)
1282
4
submitted 3 years ago* (last edited 3 years ago) by snaggen@programming.dev to c/rust@programming.dev

Docker have added rust server support to docker init, but what does that mean? I would appreciate if someone could clarify this.

1283
20

Unusually high astonishment by Rust standards

1284
6

Your chance to geek out (and finally learn about what Rust's ownership system)

1285
34
Bevy 0.11 (bevyengine.org)
submitted 3 years ago by tormeh@beehaw.org to c/rust@programming.dev
1286
14
1287
6
1288
17
1289
12

My program is small enough that in TS/JS I'd normally just store the data in some global variable to be access from whatever elsewhere in the app. But with Rust from what I can tell this doesn't seem to be a common practice. How should i handle this?

More specifically, I need to:

  1. program start, fetch data from my db (DONE)
  2. store this data somehow somewhere
  3. access said data (for read only in this use case)

Thanks for any insights here!

1290
4
1291
3
1292
9
Learning to learn Rust (blog.danieljanus.pl)
1293
14

Building a Web App in Rust: From Zero to Deployment

1294
10
1295
32
Why Rust is easy (www.linkedin.com)

Have you ever heard that Rust is difficult and has a steep learning curve?

In this blog post, the author will explain why he believe that is wrong and, in some cases, easier than some other programming languages.

1296
25
1297
20
This Week in Rust 502 (this-week-in-rust.org)
submitted 3 years ago* (last edited 3 years ago) by snaggen@programming.dev to c/rust@programming.dev
1298
9
1299
21
submitted 3 years ago* (last edited 3 years ago) by snaggen@programming.dev to c/rust@programming.dev

This blog post was published roughly simultaneously with the regex 1.9 release.

1300
10
view more: ‹ prev next ›

Rust

8256 readers
32 users here now

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)

founded 3 years ago
MODERATORS