diff options
| author | troido <troido@protonmail.com> | 2020-02-09 23:54:24 +0100 |
|---|---|---|
| committer | troido <troido@protonmail.com> | 2020-02-09 23:54:24 +0100 |
| commit | b0e665f5436e08e4fd7446a59b87ac28f562a601 (patch) | |
| tree | fcdeee5178606eadfe1e1b5744410bfd4fef260a /src | |
| parent | b9cfb78c20fd309929aae98f24acc8ba4a9a7481 (diff) | |
refactoring using cargo clippy
Diffstat (limited to 'src')
| -rw-r--r-- | src/assemblage.rs | 12 | ||||
| -rw-r--r-- | src/componentparameter.rs | 2 | ||||
| -rw-r--r-- | src/componentwrapper.rs | 2 | ||||
| -rw-r--r-- | src/gameserver.rs | 4 | ||||
| -rw-r--r-- | src/main.rs | 2 | ||||
| -rw-r--r-- | src/room.rs | 2 | ||||
| -rw-r--r-- | src/systems/moving.rs | 4 | ||||
| -rw-r--r-- | src/systems/view.rs | 4 | ||||
| -rw-r--r-- | src/util.rs | 2 |
9 files changed, 18 insertions, 16 deletions
diff --git a/src/assemblage.rs b/src/assemblage.rs index 879cd3e..3433a76 100644 --- a/src/assemblage.rs +++ b/src/assemblage.rs @@ -5,17 +5,19 @@ use super::componentparameter::ComponentParameter; use super::parameter::{Parameter, ParameterType}; use super::componentwrapper::{ComponentWrapper, ComponentType}; +type ArgumentDef = (String, ParameterType, Option<Parameter>); + #[derive(Debug, PartialEq, Clone)] pub struct Assemblage { - pub arguments: Vec<(String, ParameterType, Option<Parameter>)>, + pub arguments: Vec<ArgumentDef>, pub components: Vec<(ComponentType, HashMap<String, ComponentParameter>)> } impl Assemblage { - fn parse_definition_arguments(args: &Value) -> Result<Vec<(String, ParameterType, Option<Parameter>)>, &'static str> { - let mut arguments: Vec<(String, ParameterType, Option<Parameter>)> = Vec::new(); + fn parse_definition_arguments(args: &Value) -> Result<Vec<ArgumentDef>, &'static str> { + let mut arguments: Vec<ArgumentDef> = Vec::new(); for arg in args.as_array().ok_or("arguments is not an array")? { let tup = arg.as_array().ok_or("argument is not an array")?; let key = tup.get(0).ok_or("argument has no name")?.as_str().ok_or("argument name is not a string")?.to_string(); @@ -69,7 +71,7 @@ impl Assemblage { Ok(assemblage) } - fn prepare_arguments(&self, args: &Vec<Parameter>, kwargs: &HashMap<String, Parameter>) -> Result<HashMap<&str, Parameter>, &'static str> { + fn prepare_arguments(&self, args: &[Parameter], kwargs: &HashMap<String, Parameter>) -> Result<HashMap<&str, Parameter>, &'static str> { let mut arguments: HashMap<&str, Parameter> = HashMap::new(); for (idx, (name, typ, def)) in self.arguments.iter().enumerate() { let value: Option<Parameter> = { @@ -92,7 +94,7 @@ impl Assemblage { Ok(arguments) } - pub fn instantiate(&self, args: &Vec<Parameter>, kwargs: &HashMap<String, Parameter>) -> Result<Vec<ComponentWrapper>, &'static str>{ + pub fn instantiate(&self, args: &[Parameter], kwargs: &HashMap<String, Parameter>) -> Result<Vec<ComponentWrapper>, &'static str>{ let mut components: Vec<ComponentWrapper> = Vec::new(); let arguments = self.prepare_arguments(args, kwargs)?; for (comptype, compparams) in &self.components { diff --git a/src/componentparameter.rs b/src/componentparameter.rs index e6e0062..a76f243 100644 --- a/src/componentparameter.rs +++ b/src/componentparameter.rs @@ -62,7 +62,7 @@ impl ComponentParameter { } } - pub fn get_type(&self, arguments: &Vec<(String, ParameterType, Option<Parameter>)>) -> Result<ParameterType, &'static str>{ + pub fn get_type(&self, arguments: &[(String, ParameterType, Option<Parameter>)]) -> Result<ParameterType, &'static str>{ Ok(match self { Self::Constant(param) => param.paramtype(), Self::Argument(argname) => arguments.iter().find(|(n, _t, _d)| n == argname).ok_or("unknown argument name")?.1, diff --git a/src/componentwrapper.rs b/src/componentwrapper.rs index c60c23f..c21d263 100644 --- a/src/componentwrapper.rs +++ b/src/componentwrapper.rs @@ -91,7 +91,7 @@ components!( }; Blocking () {Blocking}; Floor () {Floor}; - Player (name: String) {Player::new(name.to_string())}; + Player (name: String) {Player::new(name)}; Item (ent: Template) {Item{ent}}; Inventory () {Inventory::default()} diff --git a/src/gameserver.rs b/src/gameserver.rs index c7c5062..d7b2ccd 100644 --- a/src/gameserver.rs +++ b/src/gameserver.rs @@ -183,10 +183,10 @@ fn parse_message(msg: &str) -> Message { Message::Input(arr[1].clone()) } _ => { - Message::Invalid(format!("unknown messsage type {:?}", msgtype).to_string()) + Message::Invalid(format!("unknown messsage type {:?}", msgtype)) } } - } else { Message::Invalid(format!("first array value not string: {:?}", arr[0].to_string()).to_string()) } + } else { Message::Invalid(format!("first array value not string: {:?}", arr[0].to_string())) } } else { Message::Invalid("not json array".to_string()) } } else { Message::Invalid("not json message".to_string()) } } diff --git a/src/main.rs b/src/main.rs index 0b055c9..9020fe7 100644 --- a/src/main.rs +++ b/src/main.rs @@ -70,7 +70,7 @@ fn main() { fn gen_room<'a, 'b>() -> Room<'a, 'b> { let assemblages = default_assemblages(); - let mut room = Room::new(assemblages.clone()); + let mut room = Room::new(assemblages); let roomtemplate = RoomTemplate::from_json(&json!({ "width": 42, diff --git a/src/room.rs b/src/room.rs index 6af2c95..9aad22d 100644 --- a/src/room.rs +++ b/src/room.rs @@ -88,7 +88,7 @@ impl <'a, 'b>Room<'a, 'b> { } pub fn update(&mut self) { - self.dispatcher.dispatch(&mut self.world); + self.dispatcher.dispatch(&self.world); self.world.maintain(); } diff --git a/src/systems/moving.rs b/src/systems/moving.rs index 98b0979..3e7803d 100644 --- a/src/systems/moving.rs +++ b/src/systems/moving.rs @@ -74,8 +74,8 @@ impl <'a> System<'a> for Move { let mut pos_mut = pos.get_mut_unchecked(); moved.insert(ent, Moved{from: pos_mut.pos}).expect("can't insert Moved"); ground.cells.get_mut(&pos_mut.pos).unwrap().remove(&ent); - pos_mut.pos = newpos.clone(); - ground.cells.entry(newpos).or_insert(HashSet::new()).insert(ent); + pos_mut.pos = newpos; + ground.cells.entry(newpos).or_insert_with(HashSet::new).insert(ent); } } _ => {} diff --git a/src/systems/view.rs b/src/systems/view.rs index 6c0b1f8..a884d35 100644 --- a/src/systems/view.rs +++ b/src/systems/view.rs @@ -48,7 +48,7 @@ impl <'a> System<'a> for View { } - let has_changed: bool = changed.len() > 0; + let has_changed: bool = !changed.is_empty(); let mut changes: Vec<(Pos, Vec<String>)> = Vec::new(); for pos in changed { changes.push((pos, cell_sprites(ground.cells.get(&pos).unwrap_or(&HashSet::new()), &visible))); @@ -92,7 +92,7 @@ fn draw_room(ground: &HashMap<Pos, HashSet<Entity>>, (width, height): (i64, i64) let mut mapping: Vec<Vec<String>> = Vec::new(); for y in 0..height { for x in 0..width { - let sprites: Vec<String> = match ground.get(&Pos{x: x, y: y}) { + let sprites: Vec<String> = match ground.get(&Pos{x, y}) { Some(ents) => {cell_sprites(ents, visible)} None => {vec![]} }; diff --git a/src/util.rs b/src/util.rs index d9ff32e..34d5670 100644 --- a/src/util.rs +++ b/src/util.rs @@ -4,7 +4,7 @@ use std::cmp::{min, max}; use serde_json::Value; pub fn clamp<T: Ord>(val: T, lower: T, upper: T) -> T{ - return max(min(val, upper), lower); + max(min(val, upper), lower) } pub trait ToJson { |
