Code: Select all
use std::collections::HashMap;
use std::sync::Arc;
// A thing with a name and other guff
struct BaseThing {
name : String,
data1 : String,
data2 : f32
// and many more bits of data
}
// a thing raised to a power is a component of our value
struct Component {
pub base_thing: Arc,
pub power: i32,
}
type ComponentsMap = HashMap;
// Ideally want this....
// type ComponentsMap = HashMap;
// A value is a collection of BaseThings raised to a power
// indexed by the name of the thing.
struct Value {
pub components: ComponentsMap
// and some other bits as well
}
fn addComponent(value : &mut Value,
base_thing : Arc,
power : i32)
{
// The map is indexed by the name of the baseThing being inserted.
value.components.insert(base_thing.name.clone(),
Component {
base_thing: base_thing,
power : power });
}
Danke für alle Antworten, ich verwende idordmap von https://github.com/oxidecomputer/iddqd.