nerdblood

joined 1 year ago
[–] [email protected] 1 points 1 year ago* (last edited 1 year ago) (1 children)

It was basically me passing BaseArmy in as a param to a fucntion, then returning an Army type. I tried a few different things, but what I really wanted to do was just spread out the struct like I would in Typescript. Rust seems to support this UNLESS there's one field that's different.

Let me give builder pattern a try. I was literally just learning more about it, but didn't think to apply it here.

EDIT:

Here's what' I'm trying to do: Battalion { count: count, position, ..db_battalion_template }

Then the error I get:

mismatched types expected Battalion, found BattalionTemplate

EDIT2:

After more fiddling around and adding the from conversion:

Battalion { count: count, position, ..Battalion::from(db_battalion_template) } impl From<BattalionTemplate> for Battalion { fn from(a: BattalionTemplate) -> Self { let serialized = serde_json::to_string(&a).unwrap(); Self { position: 0, ..serde_json::from_str(&serialized).unwrap() } } }

I get this error: thread 'main' panicked at 'called Result::unwrap() on an Err value: Error("missing field position", line: 1, column: 227)'

Edit 3:

I at least got the from conversion to work by just manually specifying the Battalion fields. Should I just accept that I can't spread struct properties from one type on to another unless they have exactly the same fields?

[–] [email protected] 3 points 1 year ago

This is fantastic, thanks for sharing!

[–] [email protected] 4 points 1 year ago (1 children)

I might not need global state, the more I think about it. I'll start with passing a struct and see where that gets me, thanks!

[–] [email protected] 3 points 1 year ago

Yeah I tried out lazy_static, but the compiler was strongly urging me not to use it since it's being deprecated. Thanks, I didn't know about OneCell.

[–] [email protected] 1 points 1 year ago

Eh , its probably just temporary. People just had apps they've used for 10 years yanked away and it's jaring how it all went down. Of course people are going to want to talk about it.

[–] [email protected] 2 points 1 year ago (1 children)

Have you thought about wiping your comments? I had 1300 (more than I thought I would) and have no regrets.

[–] [email protected] 6 points 1 year ago (1 children)

It's basically the same premise. Link aggregator with a forum attached, where upvoted content rises to the top. She doesn't need to know how instances work in order to use it in the same way that she doesn't need to be a mechanic in order to drive her car.

[–] [email protected] 6 points 1 year ago (1 children)

I've tried only Connect, and it's been great.

[–] [email protected] 3 points 1 year ago (1 children)

I love lamp.

view more: ‹ prev next ›