Skip to content

Commit

Permalink
fix: cargo fmt and clippy warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
ali77gh committed Jun 5, 2024
1 parent cc11ce7 commit f4edd17
Show file tree
Hide file tree
Showing 24 changed files with 33 additions and 31 deletions.
2 changes: 1 addition & 1 deletion src/builtin_function/bools/equal.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::builtin_function::utils::{param_to_datatype, returns};
use crate::common::data_type::DataType;
use crate::common::errors::Result;
use crate::builtin_function::utils::{param_to_datatype, returns};
use crate::{common::executable::ExecutableLine, runtime::Runtime};

pub fn equal(runtime: &mut Runtime, executable: &ExecutableLine) -> Result<()> {
Expand Down
2 changes: 1 addition & 1 deletion src/builtin_function/bools/greater_than.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::builtin_function::utils::{param_to_datatype, returns};
use crate::common::data_type::DataType;
use crate::common::errors::{ChapError, Result};
use crate::builtin_function::utils::{param_to_datatype, returns};
use crate::{common::executable::ExecutableLine, runtime::Runtime};

pub fn greater_than(runtime: &mut Runtime, executable: &ExecutableLine) -> Result<()> {
Expand Down
2 changes: 1 addition & 1 deletion src/builtin_function/bools/less_than.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::builtin_function::utils::{param_to_datatype, returns};
use crate::common::data_type::DataType;
use crate::common::errors::{ChapError, Result};
use crate::builtin_function::utils::{param_to_datatype, returns};
use crate::{common::executable::ExecutableLine, runtime::Runtime};

pub fn less_than(runtime: &mut Runtime, executable: &ExecutableLine) -> Result<()> {
Expand Down
2 changes: 1 addition & 1 deletion src/builtin_function/bools/not.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::builtin_function::utils::{param_to_datatype, returns};
use crate::common::data_type::DataType;
use crate::common::errors::{ChapError, Result};
use crate::builtin_function::utils::{param_to_datatype, returns};
use crate::{common::executable::ExecutableLine, runtime::Runtime};

pub fn not(runtime: &mut Runtime, executable: &ExecutableLine) -> Result<()> {
Expand Down
2 changes: 1 addition & 1 deletion src/builtin_function/bools/not_equal.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::builtin_function::utils::{param_to_datatype, returns};
use crate::common::data_type::DataType;
use crate::common::errors::Result;
use crate::builtin_function::utils::{param_to_datatype, returns};
use crate::{common::executable::ExecutableLine, runtime::Runtime};

pub fn not_equal(runtime: &mut Runtime, executable: &ExecutableLine) -> Result<()> {
Expand Down
2 changes: 1 addition & 1 deletion src/builtin_function/debugger/dump.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ pub fn dump(runtime: &mut Runtime, executable: &ExecutableLine) -> Result<()> {
for variable in runtime.variables.iter() {
let name = variable.0;
let value = variable.1;
result.push_str(format!("{} -> ${}\n", value.to_string(), name).as_str())
result.push_str(format!("{} -> ${}\n", value, name).as_str())
}
result.pop();
runtime.std_out(
Expand Down
2 changes: 1 addition & 1 deletion src/builtin_function/delay/wait_millis.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::builtin_function::utils::param_to_datatype;
use crate::common::data_type::DataType;
use crate::common::errors::{ChapError, Result};
use crate::builtin_function::utils::param_to_datatype;
use crate::{common::executable::ExecutableLine, runtime::Runtime};
use std::{thread, time};

Expand Down
2 changes: 1 addition & 1 deletion src/builtin_function/list/has.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::builtin_function::utils::{param_to_datatype, returns};
use crate::common::data_type::DataType;
use crate::common::errors::{ChapError, Result};
use crate::builtin_function::utils::{param_to_datatype, returns};
use crate::{common::executable::ExecutableLine, runtime::Runtime};

pub fn has(runtime: &mut Runtime, executable: &ExecutableLine) -> Result<()> {
Expand Down
2 changes: 1 addition & 1 deletion src/builtin_function/list/index_of.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::builtin_function::utils::{param_to_datatype, returns};
use crate::common::data_type::DataType;
use crate::common::errors::{ChapError, Result};
use crate::builtin_function::utils::{param_to_datatype, returns};
use crate::{common::executable::ExecutableLine, runtime::Runtime};

pub fn index_of(runtime: &mut Runtime, executable: &ExecutableLine) -> Result<()> {
Expand Down
2 changes: 1 addition & 1 deletion src/builtin_function/list/insert.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::builtin_function::utils::{param_to_datatype, param_to_datatype_mut};
use crate::common::data_type::DataType;
use crate::common::errors::{ChapError, Result};
use crate::builtin_function::utils::{param_to_datatype, param_to_datatype_mut};
use crate::{common::executable::ExecutableLine, runtime::Runtime};

pub fn insert(runtime: &mut Runtime, executable: &ExecutableLine) -> Result<()> {
Expand Down
2 changes: 1 addition & 1 deletion src/builtin_function/list/last.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::builtin_function::utils::{param_to_datatype_mut, returns};
use crate::common::data_type::DataType;
use crate::common::errors::{ChapError, Result};
use crate::builtin_function::utils::{param_to_datatype_mut, returns};
use crate::{common::executable::ExecutableLine, runtime::Runtime};

pub fn last(runtime: &mut Runtime, executable: &ExecutableLine) -> Result<()> {
Expand Down
2 changes: 1 addition & 1 deletion src/builtin_function/list/pop.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::builtin_function::utils::{param_to_datatype_mut, returns};
use crate::common::data_type::DataType;
use crate::common::errors::{ChapError, Result};
use crate::builtin_function::utils::{param_to_datatype_mut, returns};
use crate::{common::executable::ExecutableLine, runtime::Runtime};

pub fn pop(runtime: &mut Runtime, executable: &ExecutableLine) -> Result<()> {
Expand Down
2 changes: 1 addition & 1 deletion src/builtin_function/list/remove_at.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::builtin_function::utils::{param_to_datatype, param_to_datatype_mut, returns};
use crate::common::data_type::DataType;
use crate::common::errors::{ChapError, Result};
use crate::builtin_function::utils::{param_to_datatype, param_to_datatype_mut, returns};
use crate::{common::executable::ExecutableLine, runtime::Runtime};

pub fn remove_at(runtime: &mut Runtime, executable: &ExecutableLine) -> Result<()> {
Expand Down
4 changes: 2 additions & 2 deletions src/builtin_function/math/add_many.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::common::data_type::DataType;
use crate::common::errors::Result;
use crate::builtin_function::math::add::add_data_types;
use crate::builtin_function::utils::{param_to_datatype, returns};
use crate::common::data_type::DataType;
use crate::common::errors::Result;
use crate::{common::executable::ExecutableLine, runtime::Runtime};

pub fn add_many(runtime: &mut Runtime, executable: &ExecutableLine) -> Result<()> {
Expand Down
2 changes: 1 addition & 1 deletion src/builtin_function/math/divide.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::builtin_function::utils::{param_to_datatype, returns};
use crate::common::data_type::DataType;
use crate::common::errors::{ChapError, Result};
use crate::builtin_function::utils::{param_to_datatype, returns};
use crate::{common::executable::ExecutableLine, runtime::Runtime};

pub fn divide(runtime: &mut Runtime, executable: &ExecutableLine) -> Result<()> {
Expand Down
2 changes: 1 addition & 1 deletion src/builtin_function/random/random_bool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ use crate::{common::executable::ExecutableLine, runtime::Runtime};

#[cfg(not(target_family = "wasm"))]
pub fn random_bool(runtime: &mut Runtime, executable: &ExecutableLine) -> Result<()> {
use crate::common::data_type::DataType;
use crate::builtin_function::utils::returns;
use crate::common::data_type::DataType;
use rand::Rng;

let mut rng = rand::thread_rng();
Expand Down
2 changes: 1 addition & 1 deletion src/builtin_function/random/random_number.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ use crate::{common::executable::ExecutableLine, runtime::Runtime};

#[cfg(not(target_family = "wasm"))]
pub fn random_number(runtime: &mut Runtime, executable: &ExecutableLine) -> Result<()> {
use crate::common::data_type::DataType;
use crate::builtin_function::utils::{param_to_datatype, returns};
use crate::common::data_type::DataType;
use rand::Rng;

let p1 = param_to_datatype(runtime, executable.params.first(), executable.line_number)?;
Expand Down
2 changes: 1 addition & 1 deletion src/builtin_function/random/random_string.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ use crate::{common::executable::ExecutableLine, runtime::Runtime};

#[cfg(not(target_family = "wasm"))]
pub fn random_string(runtime: &mut Runtime, executable: &ExecutableLine) -> Result<()> {
use crate::common::data_type::DataType;
use crate::builtin_function::utils::{param_to_datatype, returns};
use crate::common::data_type::DataType;

let p1 = param_to_datatype(runtime, executable.params.first(), executable.line_number)?;
let p2 = param_to_datatype(runtime, executable.params.get(1), executable.line_number)?;
Expand Down
2 changes: 1 addition & 1 deletion src/builtin_function/strings/contact.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::builtin_function::utils::{param_to_datatype, returns};
use crate::common::data_type::DataType;
use crate::common::errors::Result;
use crate::builtin_function::utils::{param_to_datatype, returns};
use crate::{common::executable::ExecutableLine, runtime::Runtime};

pub fn concat(runtime: &mut Runtime, executable: &ExecutableLine) -> Result<()> {
Expand Down
2 changes: 1 addition & 1 deletion src/builtin_function/strings/contains.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::builtin_function::utils::{param_to_datatype, returns};
use crate::common::data_type::DataType;
use crate::common::errors::Result;
use crate::builtin_function::utils::{param_to_datatype, returns};
use crate::{common::executable::ExecutableLine, runtime::Runtime};

pub fn contains(runtime: &mut Runtime, executable: &ExecutableLine) -> Result<()> {
Expand Down
2 changes: 1 addition & 1 deletion src/builtin_function/strings/length.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::builtin_function::utils::{param_to_datatype, returns};
use crate::common::data_type::DataType;
use crate::common::errors::{ChapError, Result};
use crate::builtin_function::utils::{param_to_datatype, returns};
use crate::{common::executable::ExecutableLine, runtime::Runtime};

pub fn length(runtime: &mut Runtime, executable: &ExecutableLine) -> Result<()> {
Expand Down
2 changes: 1 addition & 1 deletion src/builtin_function/strings/repeat.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::builtin_function::utils::{param_to_datatype, returns};
use crate::common::data_type::DataType;
use crate::common::errors::{ChapError, Result};
use crate::builtin_function::utils::{param_to_datatype, returns};
use crate::{common::executable::ExecutableLine, runtime::Runtime};

pub fn repeat(runtime: &mut Runtime, executable: &ExecutableLine) -> Result<()> {
Expand Down
2 changes: 1 addition & 1 deletion src/builtin_function/strings/slice.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::builtin_function::utils::{param_to_datatype, returns};
use crate::common::data_type::DataType;
use crate::common::errors::{ChapError, Result};
use crate::builtin_function::utils::{param_to_datatype, returns};
use crate::{common::executable::ExecutableLine, runtime::Runtime};

pub fn slice(runtime: &mut Runtime, executable: &ExecutableLine) -> Result<()> {
Expand Down
16 changes: 9 additions & 7 deletions src/common/data_type.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use std::fmt::Display;

#[derive(PartialEq, Debug, Clone)]
pub enum DataType {
String(String),
Expand All @@ -7,18 +9,18 @@ pub enum DataType {
List(Vec<DataType>),
}

impl ToString for DataType {
fn to_string(&self) -> String {
impl Display for DataType {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
Self::String(m) => m.clone(),
Self::Int(i) => i.to_string(),
Self::Float(f) => f.to_string(),
Self::Bool(b) => b.to_string(),
Self::String(m) => write!(f, "{}", m.clone()),
Self::Int(i) => write!(f, "{}", i),
Self::Float(f_) => write!(f, "{}", f_),
Self::Bool(b) => write!(f, "{}", b),
Self::List(b) => {
let a = b.iter().map(|x| x.to_string());
let a: Vec<String> = a.collect();
let i = a.join(" ");
format!("[{}]", i)
write!(f, "[{}]", i)
}
}
}
Expand Down

0 comments on commit f4edd17

Please sign in to comment.