#One set of getter/setter functions that get the type from the key or separate ones for each type?

16 messages · Page 1 of 1 (latest)

inland sequoia
#

I already implied something like
fn get<T>(&self, key: ID<T>) -> T

but I'm wondering now that I got it working I'm doubting if it the the Rustationian way of handling it

maiden current
#

Assuming a single get is implemented, it's probably preferrable

#

That said, what type is Id?

#

Because if it's zero-sized, you can even remove it entirely

inland sequoia
quick vector
#

I assume you have a finite list of types that could be stored in this thing. What is the relationship between these types?

inland sequoia
#

It's just proporties for a game entities

strunt Agent {
  i8s: HashMap<ID, i8>,
  strings: HashMap<ID, String>
}

should you access the proporties with a generit getter/setter like
println!("{} wacks {}", actor.get(NAME), actee.get(NAME))
or shoulf it be
println!("{} wacks {}", actor.get_string(NAME), actee.get_string(NAME))

quick vector
#

btw i think strings is not a great field name

inland sequoia
#

That's not the actual code just something to explain the concept

quick vector
#

oh ok

#

Is there a reason not to expose the hashmaps as public fields? 😅

inland sequoia
#

because then you can't keep people from editing them

#

That and I've ran into the sistual when instead of storing the value you calculate it and if you use Getter/setters then you just have to change the struct whie if you where accessing the field direct you have to replace every where you where accessing it with the functions

quick vector
inland sequoia