Skip to content

Commit b83e9c3

Browse files
committed
chore(basic): Fixed a few clippy issues
1 parent 5529396 commit b83e9c3

6 files changed

Lines changed: 10 additions & 14 deletions

File tree

rusty_basic/src/interpreter/built_ins/string_fn.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ fn run_with_ascii_code_argument(count: usize, ascii: i32) -> Result<String, Runt
4040
}
4141

4242
fn run_with_char(count: usize, ch: char) -> Result<String, RuntimeError> {
43-
Ok(std::iter::repeat(ch).take(count).collect())
43+
Ok(std::iter::repeat_n(ch, count).collect())
4444
}
4545

4646
#[cfg(test)]

rusty_basic/src/interpreter/built_ins/val.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ fn val(s: &str) -> Result<Variant, VariantError> {
2727
let mut state: u8 = STATE_INITIAL;
2828

2929
for c in s.chars() {
30-
if ('0'..='9').contains(&c) {
30+
if c.is_ascii_digit() {
3131
if state == STATE_INITIAL || state == STATE_SIGN {
3232
state = STATE_INT;
3333
} else if state == STATE_DOT {

rusty_basic/src/interpreter/default_stdlib.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,7 @@ impl Stdlib for DefaultStdlib {
88
}
99

1010
fn get_env_var(&self, name: &str) -> String {
11-
match std::env::var(name) {
12-
Ok(x) => x,
13-
Err(_) => String::new(),
14-
}
11+
std::env::var(name).unwrap_or_default()
1512
}
1613

1714
fn set_env_var(&mut self, name: String, value: String) {

rusty_basic/src/interpreter/handlers/allocation.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use rusty_variant::{UserDefinedTypeValue, VArray, Variant};
44

55
use crate::RuntimeError;
66

7-
/// TODO add unit tests
7+
// TODO add unit tests
88

99
/// Creates the default variant for the given type.
1010
pub fn allocate_built_in(type_qualifier: TypeQualifier) -> Variant {

rusty_basic/src/interpreter/io.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ impl FileInfo {
9292
let offset = ((record_number - 1) * self.rec_len) as u64;
9393
let file = self.random.as_mut().expect("Should have file");
9494
file.seek(SeekFrom::Start(offset))?;
95-
let mut buffer: Vec<u8> = std::iter::repeat(0_u8).take(self.rec_len).collect();
95+
let mut buffer: Vec<u8> = std::iter::repeat_n(0_u8, self.rec_len).collect();
9696
let bytes_read = file.read(&mut buffer)?;
9797
if bytes_read < buffer.len() {
9898
// zero out missing bytes

rusty_basic/src/interpreter/read_input.rs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -81,12 +81,11 @@ impl<T: Read> ReadInputSource<T> {
8181
if let Some(ch) = self.read()? {
8282
if predicate(ch as char) {
8383
// if it was '\r', try to also get the next '\n', if exists
84-
if ch as char == '\r' {
85-
if let Some(next_ch) = self.peek()?
86-
&& next_ch as char == '\n'
87-
{
88-
self.read()?;
89-
}
84+
if ch as char == '\r'
85+
&& let Some(next_ch) = self.peek()?
86+
&& next_ch as char == '\n'
87+
{
88+
self.read()?;
9089
}
9190
} else {
9291
buf.push(ch);

0 commit comments

Comments
 (0)