use to_owned for lit -> String

This commit is contained in:
Emil Gardström
2024-03-29 15:19:41 +01:00
parent 5dc021f953
commit 5e3ba95a83
3 changed files with 102 additions and 102 deletions

View File

@@ -59,14 +59,14 @@ fn write_repr_enum<T: std::io::Write, I, P>(
.collect::<Vec<String>>()
.join(", ");
let deprecated_str = if variant.deprecated {
", deprecated = \"true\"".to_string()
", deprecated = \"true\"".to_owned()
} else {
"".to_string()
"".to_owned()
};
let props_str = if let Some(val) = &variant.value {
format!(", props( value = \"{val}\"{deprecated_str})")
} else {
"".to_string()
"".to_owned()
};
writeln!(
writer,

View File

@@ -230,7 +230,7 @@ impl FromStr for Instruction {
line: 0,
start: 0,
end: 0,
msg: "Missing instruction".to_string(),
msg: "Missing instruction".to_owned(),
})
}
}?;
@@ -420,7 +420,7 @@ impl FromStr for Operand {
line: 0,
start: 0,
end: 0,
msg: "Invalid register specifier".to_string(),
msg: "Invalid register specifier".to_owned(),
})
}
['d', rest @ ..] => match rest {
@@ -439,7 +439,7 @@ impl FromStr for Operand {
line: 0,
start: 3,
end: 3,
msg: "Invalid device connection specifier".to_string(),
msg: "Invalid device connection specifier".to_owned(),
})
}
}
@@ -467,7 +467,7 @@ impl FromStr for Operand {
line: 0,
start,
end: start,
msg: "Invalid device connection specifier".to_string(),
msg: "Invalid device connection specifier".to_owned(),
})
}
} else {
@@ -488,7 +488,7 @@ impl FromStr for Operand {
line: 0,
start: 0,
end: 0,
msg: "Invalid register specifier".to_string(),
msg: "Invalid register specifier".to_owned(),
})
}
} else {
@@ -517,7 +517,7 @@ impl FromStr for Operand {
line: 0,
start,
end: start,
msg: "Invalid device connection specifier".to_string(),
msg: "Invalid device connection specifier".to_owned(),
})
}
} else {
@@ -535,7 +535,7 @@ impl FromStr for Operand {
line: 0,
start: 0,
end: 0,
msg: "Invalid device specifier".to_string(),
msg: "Invalid device specifier".to_owned(),
})
}
} else {
@@ -551,7 +551,7 @@ impl FromStr for Operand {
line: 0,
start: 0,
end: 0,
msg: "Invalid hash string: Can not contain '\"'".to_string(),
msg: "Invalid hash string: Can not contain '\"'".to_owned(),
})
}
}
@@ -568,7 +568,7 @@ impl FromStr for Operand {
line: 0,
start: 0,
end: 0,
msg: "Invalid Hexadecimal Number".to_string(),
msg: "Invalid Hexadecimal Number".to_owned(),
})
}
}
@@ -585,7 +585,7 @@ impl FromStr for Operand {
line: 0,
start: 0,
end: 0,
msg: "Invalid Binary Number".to_string(),
msg: "Invalid Binary Number".to_owned(),
})
}
}
@@ -594,7 +594,7 @@ impl FromStr for Operand {
let float_str = if rest_iter.peek() == Some(&&'-') {
format!("{}", rest_iter.next().unwrap())
} else {
"".to_string()
"".to_owned()
} + &rest_iter
.take_while_ref(|c| c.is_ascii_digit())
.collect::<String>();
@@ -614,7 +614,7 @@ impl FromStr for Operand {
line: 0,
start,
end: start,
msg: "Invalid Decimal Number".to_string(),
msg: "Invalid Decimal Number".to_owned(),
})
}
} else if rest_iter.next().is_none() {
@@ -626,7 +626,7 @@ impl FromStr for Operand {
line: 0,
start,
end: start,
msg: "Invalid Integer Number".to_string(),
msg: "Invalid Integer Number".to_owned(),
})
}
} else if let Some(val) = CONSTANTS_LOOKUP.get(s) {
@@ -672,13 +672,13 @@ impl FromStr for Label {
line: 0,
start: index,
end: index,
msg: "Missing ':' at end of label".to_string(),
msg: "Missing ':' at end of label".to_owned(),
}),
None => Err(ParseError {
line: 0,
start: 0,
end: 0,
msg: "empty string for label? parse miscalled".to_string(),
msg: "empty string for label? parse miscalled".to_owned(),
}),
}
}
@@ -723,7 +723,7 @@ impl FromStr for Identifier {
line: 0,
start: 0,
end: 0,
msg: "Empty Identifier".to_string(),
msg: "Empty Identifier".to_owned(),
})
}
}
@@ -775,7 +775,7 @@ mod tests {
],
},),),
comment: Some(Comment {
comment: " This is a comment".to_string(),
comment: " This is a comment".to_owned(),
},),
},],
);
@@ -827,7 +827,7 @@ mod tests {
Line {
code: None,
comment: Some(Comment {
comment: " This is a comment".to_string(),
comment: " This is a comment".to_owned(),
},),
},
Line {
@@ -835,7 +835,7 @@ mod tests {
instruction: InstructionOp::Define,
operands: vec![
Operand::Identifier(Identifier {
name: "a_def".to_string(),
name: "a_def".to_owned(),
},),
Operand::Number(Number::Float(10.0,),),
],
@@ -847,9 +847,9 @@ mod tests {
instruction: InstructionOp::Define,
operands: vec![
Operand::Identifier(Identifier {
name: "a_hash".to_string(),
name: "a_hash".to_owned(),
},),
Operand::Number(Number::String("This is a String".to_string()),),
Operand::Number(Number::String("This is a String".to_owned()),),
],
},),),
comment: None,
@@ -859,7 +859,7 @@ mod tests {
instruction: InstructionOp::Alias,
operands: vec![
Operand::Identifier(Identifier {
name: "a_var".to_string(),
name: "a_var".to_owned(),
},),
Operand::RegisterSpec {
indirection: 0,
@@ -874,7 +874,7 @@ mod tests {
instruction: InstructionOp::Alias,
operands: vec![
Operand::Identifier(Identifier {
name: "a_device".to_string(),
name: "a_device".to_owned(),
},),
Operand::DeviceSpec {
device: Device::Numbered(0),
@@ -927,7 +927,7 @@ mod tests {
Line {
code: Some(Code::Label(Label {
id: Identifier {
name: "main".to_string(),
name: "main".to_owned(),
},
},),),
comment: None,
@@ -964,7 +964,7 @@ mod tests {
indirection: 0,
target: 0,
},
Operand::Number(Number::String("AccessCardBlack".to_string()),),
Operand::Number(Number::String("AccessCardBlack".to_owned()),),
],
},),),
comment: None,
@@ -1032,7 +1032,7 @@ mod tests {
code: Some(Code::Instruction(Instruction {
instruction: InstructionOp::J,
operands: vec![Operand::Identifier(Identifier {
name: "main".to_string(),
name: "main".to_owned(),
},),],
},),),
comment: None,

View File

@@ -146,9 +146,9 @@ pub enum ICState {
impl Display for ICState {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
let out = match self {
ICState::Start => "Not Run".to_string(),
ICState::Running => "Running".to_string(),
ICState::Yield => "Ic has yielded, Resume on next tick".to_string(),
ICState::Start => "Not Run".to_owned(),
ICState::Running => "Running".to_owned(),
ICState::Yield => "Ic has yielded, Resume on next tick".to_owned(),
ICState::Sleep(then, sleep_for) => {
let format = format_description::parse("[hour]:[minute]:[second]").unwrap();
let resume = *then + time::Duration::new(*sleep_for as i64, 0);
@@ -158,7 +158,7 @@ impl Display for ICState {
)
}
ICState::Error(err) => format!("{err}"),
ICState::HasCaughtFire => "IC has caught fire! this is not a joke!".to_string(),
ICState::HasCaughtFire => "IC has caught fire! this is not a joke!".to_owned(),
};
write!(f, "{out}")
}
@@ -456,13 +456,13 @@ impl IC {
let &Operand::Identifier(ident) = &name else {
break 'inst Err(IncorrectOperandType {
index: 1,
desired: "Name".to_string(),
desired: "Name".to_owned(),
});
};
let &Operand::Number(num) = &number else {
break 'inst Err(IncorrectOperandType {
index: 2,
desired: "Number".to_string(),
desired: "Number".to_owned(),
});
};
if self.defines.contains_key(&ident.name) {
@@ -479,7 +479,7 @@ impl IC {
let &Operand::Identifier(ident) = &name else {
break 'inst Err(IncorrectOperandType {
index: 1,
desired: "Name".to_string(),
desired: "Name".to_owned(),
});
};
let alias = match &device_reg {
@@ -497,7 +497,7 @@ impl IC {
_ => {
break 'inst Err(IncorrectOperandType {
index: 2,
desired: "Device Or Register".to_string(),
desired: "Device Or Register".to_owned(),
})
}
};
@@ -515,7 +515,7 @@ impl IC {
else {
break 'inst Err(IncorrectOperandType {
index: 1,
desired: "Register".to_string(),
desired: "Register".to_owned(),
});
};
@@ -1241,7 +1241,7 @@ impl IC {
else {
break 'inst Err(IncorrectOperandType {
index: 1,
desired: "Register".to_string(),
desired: "Register".to_owned(),
});
};
let a = a.get_value(self)?;
@@ -1260,7 +1260,7 @@ impl IC {
else {
break 'inst Err(IncorrectOperandType {
index: 1,
desired: "Register".to_string(),
desired: "Register".to_owned(),
});
};
let a = a.get_value(self)?;
@@ -1278,7 +1278,7 @@ impl IC {
else {
break 'inst Err(IncorrectOperandType {
index: 1,
desired: "Register".to_string(),
desired: "Register".to_owned(),
});
};
let a = a.get_value(self)?;
@@ -1297,7 +1297,7 @@ impl IC {
else {
break 'inst Err(IncorrectOperandType {
index: 1,
desired: "Register".to_string(),
desired: "Register".to_owned(),
});
};
let a = a.get_value(self)?;
@@ -1315,7 +1315,7 @@ impl IC {
else {
break 'inst Err(IncorrectOperandType {
index: 1,
desired: "Register".to_string(),
desired: "Register".to_owned(),
});
};
let a = a.get_value(self)?;
@@ -1334,7 +1334,7 @@ impl IC {
else {
break 'inst Err(IncorrectOperandType {
index: 1,
desired: "Register".to_string(),
desired: "Register".to_owned(),
});
};
let a = a.get_value(self)?;
@@ -1352,7 +1352,7 @@ impl IC {
else {
break 'inst Err(IncorrectOperandType {
index: 1,
desired: "Register".to_string(),
desired: "Register".to_owned(),
});
};
let a = a.get_value(self)?;
@@ -1371,7 +1371,7 @@ impl IC {
else {
break 'inst Err(IncorrectOperandType {
index: 1,
desired: "Register".to_string(),
desired: "Register".to_owned(),
});
};
let a = a.get_value(self)?;
@@ -1389,7 +1389,7 @@ impl IC {
else {
break 'inst Err(IncorrectOperandType {
index: 1,
desired: "Register".to_string(),
desired: "Register".to_owned(),
});
};
let a = a.get_value(self)?;
@@ -1408,7 +1408,7 @@ impl IC {
else {
break 'inst Err(IncorrectOperandType {
index: 1,
desired: "Register".to_string(),
desired: "Register".to_owned(),
});
};
let a = a.get_value(self)?;
@@ -1426,7 +1426,7 @@ impl IC {
else {
break 'inst Err(IncorrectOperandType {
index: 1,
desired: "Register".to_string(),
desired: "Register".to_owned(),
});
};
let a = a.get_value(self)?;
@@ -1445,7 +1445,7 @@ impl IC {
else {
break 'inst Err(IncorrectOperandType {
index: 1,
desired: "Register".to_string(),
desired: "Register".to_owned(),
});
};
let a = a.get_value(self)?;
@@ -1463,7 +1463,7 @@ impl IC {
else {
break 'inst Err(IncorrectOperandType {
index: 1,
desired: "Register".to_string(),
desired: "Register".to_owned(),
});
};
let a = a.get_value(self)?;
@@ -1493,7 +1493,7 @@ impl IC {
else {
break 'inst Err(IncorrectOperandType {
index: 1,
desired: "Register".to_string(),
desired: "Register".to_owned(),
});
};
let a = a.get_value(self)?;
@@ -1520,7 +1520,7 @@ impl IC {
else {
break 'inst Err(IncorrectOperandType {
index: 1,
desired: "Register".to_string(),
desired: "Register".to_owned(),
});
};
let a = a.get_value(self)?;
@@ -1550,7 +1550,7 @@ impl IC {
else {
break 'inst Err(IncorrectOperandType {
index: 1,
desired: "Register".to_string(),
desired: "Register".to_owned(),
});
};
let a = a.get_value(self)?;
@@ -1577,7 +1577,7 @@ impl IC {
else {
break 'inst Err(IncorrectOperandType {
index: 1,
desired: "Register".to_string(),
desired: "Register".to_owned(),
});
};
let (device, _connection) = device.get_device_id(self)?;
@@ -1599,7 +1599,7 @@ impl IC {
else {
break 'inst Err(IncorrectOperandType {
index: 1,
desired: "Register".to_string(),
desired: "Register".to_owned(),
});
};
let (device, _connection) = device.get_device_id(self)?;
@@ -1621,7 +1621,7 @@ impl IC {
else {
break 'inst Err(IncorrectOperandType {
index: 1,
desired: "Register".to_string(),
desired: "Register".to_owned(),
});
};
let a = a.get_value(self)?;
@@ -1639,7 +1639,7 @@ impl IC {
else {
break 'inst Err(IncorrectOperandType {
index: 1,
desired: "Register".to_string(),
desired: "Register".to_owned(),
});
};
let a = a.get_value(self)?;
@@ -1658,7 +1658,7 @@ impl IC {
else {
break 'inst Err(IncorrectOperandType {
index: 1,
desired: "Register".to_string(),
desired: "Register".to_owned(),
});
};
let a = a.get_value(self)?;
@@ -1679,7 +1679,7 @@ impl IC {
else {
break 'inst Err(IncorrectOperandType {
index: 1,
desired: "Register".to_string(),
desired: "Register".to_owned(),
});
};
let a = a.get_value(self)?;
@@ -1698,7 +1698,7 @@ impl IC {
else {
break 'inst Err(IncorrectOperandType {
index: 1,
desired: "Register".to_string(),
desired: "Register".to_owned(),
});
};
let a = a.get_value(self)?;
@@ -1717,7 +1717,7 @@ impl IC {
else {
break 'inst Err(IncorrectOperandType {
index: 1,
desired: "Register".to_string(),
desired: "Register".to_owned(),
});
};
let a = a.get_value(self)?;
@@ -1736,7 +1736,7 @@ impl IC {
else {
break 'inst Err(IncorrectOperandType {
index: 1,
desired: "Register".to_string(),
desired: "Register".to_owned(),
});
};
let a = a.get_value(self)?;
@@ -1755,7 +1755,7 @@ impl IC {
else {
break 'inst Err(IncorrectOperandType {
index: 1,
desired: "Register".to_string(),
desired: "Register".to_owned(),
});
};
let a = a.get_value(self)?;
@@ -1774,7 +1774,7 @@ impl IC {
else {
break 'inst Err(IncorrectOperandType {
index: 1,
desired: "Register".to_string(),
desired: "Register".to_owned(),
});
};
let a = a.get_value(self)?;
@@ -1792,7 +1792,7 @@ impl IC {
else {
break 'inst Err(IncorrectOperandType {
index: 1,
desired: "Register".to_string(),
desired: "Register".to_owned(),
});
};
let a = a.get_value(self)?;
@@ -1810,7 +1810,7 @@ impl IC {
else {
break 'inst Err(IncorrectOperandType {
index: 1,
desired: "Register".to_string(),
desired: "Register".to_owned(),
});
};
let a = a.get_value(self)?;
@@ -1829,7 +1829,7 @@ impl IC {
else {
break 'inst Err(IncorrectOperandType {
index: 1,
desired: "Register".to_string(),
desired: "Register".to_owned(),
});
};
let a = a.get_value(self)?;
@@ -1848,7 +1848,7 @@ impl IC {
else {
break 'inst Err(IncorrectOperandType {
index: 1,
desired: "Register".to_string(),
desired: "Register".to_owned(),
});
};
let a = a.get_value(self)?;
@@ -1867,7 +1867,7 @@ impl IC {
else {
break 'inst Err(IncorrectOperandType {
index: 1,
desired: "Register".to_string(),
desired: "Register".to_owned(),
});
};
let a = a.get_value(self)?;
@@ -1885,7 +1885,7 @@ impl IC {
else {
break 'inst Err(IncorrectOperandType {
index: 1,
desired: "Register".to_string(),
desired: "Register".to_owned(),
});
};
let a = a.get_value(self)?;
@@ -1903,7 +1903,7 @@ impl IC {
else {
break 'inst Err(IncorrectOperandType {
index: 1,
desired: "Register".to_string(),
desired: "Register".to_owned(),
});
};
let a = a.get_value(self)?;
@@ -1921,7 +1921,7 @@ impl IC {
else {
break 'inst Err(IncorrectOperandType {
index: 1,
desired: "Register".to_string(),
desired: "Register".to_owned(),
});
};
let a = a.get_value(self)?;
@@ -1939,7 +1939,7 @@ impl IC {
else {
break 'inst Err(IncorrectOperandType {
index: 1,
desired: "Register".to_string(),
desired: "Register".to_owned(),
});
};
let a = a.get_value(self)?;
@@ -1958,7 +1958,7 @@ impl IC {
else {
break 'inst Err(IncorrectOperandType {
index: 1,
desired: "Register".to_string(),
desired: "Register".to_owned(),
});
};
let val = vm.random.clone().borrow_mut().next_f64();
@@ -1977,7 +1977,7 @@ impl IC {
else {
break 'inst Err(IncorrectOperandType {
index: 1,
desired: "Register".to_string(),
desired: "Register".to_owned(),
});
};
let a = a.get_value(self)?;
@@ -1995,7 +1995,7 @@ impl IC {
else {
break 'inst Err(IncorrectOperandType {
index: 1,
desired: "Register".to_string(),
desired: "Register".to_owned(),
});
};
let a = a.get_value(self)?;
@@ -2013,7 +2013,7 @@ impl IC {
else {
break 'inst Err(IncorrectOperandType {
index: 1,
desired: "Register".to_string(),
desired: "Register".to_owned(),
});
};
let a = a.get_value(self)?;
@@ -2031,7 +2031,7 @@ impl IC {
else {
break 'inst Err(IncorrectOperandType {
index: 1,
desired: "Register".to_string(),
desired: "Register".to_owned(),
});
};
let a = a.get_value(self)?;
@@ -2049,7 +2049,7 @@ impl IC {
else {
break 'inst Err(IncorrectOperandType {
index: 1,
desired: "Register".to_string(),
desired: "Register".to_owned(),
});
};
let a = a.get_value(self)?;
@@ -2067,7 +2067,7 @@ impl IC {
else {
break 'inst Err(IncorrectOperandType {
index: 1,
desired: "Register".to_string(),
desired: "Register".to_owned(),
});
};
let a = a.get_value(self)?;
@@ -2085,7 +2085,7 @@ impl IC {
else {
break 'inst Err(IncorrectOperandType {
index: 1,
desired: "Register".to_string(),
desired: "Register".to_owned(),
});
};
let a = a.get_value(self)?;
@@ -2105,7 +2105,7 @@ impl IC {
else {
break 'inst Err(IncorrectOperandType {
index: 1,
desired: "Register".to_string(),
desired: "Register".to_owned(),
});
};
let a = a.get_value_i64(self, true)?;
@@ -2124,7 +2124,7 @@ impl IC {
else {
break 'inst Err(IncorrectOperandType {
index: 1,
desired: "Register".to_string(),
desired: "Register".to_owned(),
});
};
let a = a.get_value_i64(self, false)?;
@@ -2143,7 +2143,7 @@ impl IC {
else {
break 'inst Err(IncorrectOperandType {
index: 1,
desired: "Register".to_string(),
desired: "Register".to_owned(),
});
};
let a = a.get_value_i64(self, true)?;
@@ -2163,7 +2163,7 @@ impl IC {
else {
break 'inst Err(IncorrectOperandType {
index: 1,
desired: "Register".to_string(),
desired: "Register".to_owned(),
});
};
let a = a.get_value_i64(self, true)?;
@@ -2182,7 +2182,7 @@ impl IC {
else {
break 'inst Err(IncorrectOperandType {
index: 1,
desired: "Register".to_string(),
desired: "Register".to_owned(),
});
};
let a = a.get_value_i64(self, true)?;
@@ -2201,7 +2201,7 @@ impl IC {
else {
break 'inst Err(IncorrectOperandType {
index: 1,
desired: "Register".to_string(),
desired: "Register".to_owned(),
});
};
let a = a.get_value_i64(self, true)?;
@@ -2220,7 +2220,7 @@ impl IC {
else {
break 'inst Err(IncorrectOperandType {
index: 1,
desired: "Register".to_string(),
desired: "Register".to_owned(),
});
};
let a = a.get_value_i64(self, true)?;
@@ -2239,7 +2239,7 @@ impl IC {
else {
break 'inst Err(IncorrectOperandType {
index: 1,
desired: "Register".to_string(),
desired: "Register".to_owned(),
});
};
let a = a.get_value_i64(self, true)?;
@@ -2266,7 +2266,7 @@ impl IC {
else {
break 'inst Err(IncorrectOperandType {
index: 1,
desired: "Register".to_string(),
desired: "Register".to_owned(),
});
};
let val = self.pop()?;
@@ -2293,7 +2293,7 @@ impl IC {
else {
break 'inst Err(IncorrectOperandType {
index: 1,
desired: "Register".to_string(),
desired: "Register".to_owned(),
});
};
let val = self.peek()?;
@@ -2312,7 +2312,7 @@ impl IC {
else {
break 'inst Err(IncorrectOperandType {
index: 1,
desired: "Register".to_string(),
desired: "Register".to_owned(),
});
};
let (Some(device_id), _connection) = dev_id.get_device_id(self)? else {
@@ -2344,7 +2344,7 @@ impl IC {
else {
break 'inst Err(IncorrectOperandType {
index: 1,
desired: "Register".to_string(),
desired: "Register".to_owned(),
});
};
let (Some(device_id), _connection) = dev_id.get_device_id(self)? else {
@@ -2524,7 +2524,7 @@ impl IC {
else {
break 'inst Err(IncorrectOperandType {
index: 1,
desired: "Register".to_string(),
desired: "Register".to_owned(),
});
};
let (Some(device_id), connection) = dev.get_device_id(self)? else {
@@ -2565,7 +2565,7 @@ impl IC {
else {
break 'inst Err(IncorrectOperandType {
index: 1,
desired: "Register".to_string(),
desired: "Register".to_owned(),
});
};
let device_id = dev.get_value(self)?;
@@ -2594,7 +2594,7 @@ impl IC {
else {
break 'inst Err(IncorrectOperandType {
index: 1,
desired: "Register".to_string(),
desired: "Register".to_owned(),
});
};
let (Some(device_id), _connection) = dev.get_device_id(self)? else {
@@ -2623,7 +2623,7 @@ impl IC {
else {
break 'inst Err(IncorrectOperandType {
index: 1,
desired: "Register".to_string(),
desired: "Register".to_owned(),
});
};
let (Some(device_id), _connection) = dev.get_device_id(self)? else {
@@ -2652,7 +2652,7 @@ impl IC {
else {
break 'inst Err(IncorrectOperandType {
index: 1,
desired: "Register".to_string(),
desired: "Register".to_owned(),
});
};
let prefab = prefab.get_value(self)?;
@@ -2673,7 +2673,7 @@ impl IC {
else {
break 'inst Err(IncorrectOperandType {
index: 1,
desired: "Register".to_string(),
desired: "Register".to_owned(),
});
};
let prefab = prefab.get_value(self)?;
@@ -2696,7 +2696,7 @@ impl IC {
else {
break 'inst Err(IncorrectOperandType {
index: 1,
desired: "Register".to_string(),
desired: "Register".to_owned(),
});
};
let prefab = prefab.get_value(self)?;
@@ -2726,7 +2726,7 @@ impl IC {
else {
break 'inst Err(IncorrectOperandType {
index: 1,
desired: "Register".to_string(),
desired: "Register".to_owned(),
});
};
let prefab = prefab.get_value(self)?;