Use variable interpolation for println!.
This commit is contained in:
parent
6b24cc151e
commit
3c2e031883
@ -38,7 +38,7 @@ fn main() -> Result<(), Box<EvalAltResult>> {
|
||||
engine
|
||||
.gen_fn_signatures(false)
|
||||
.into_iter()
|
||||
.for_each(|func| println!("{}", func));
|
||||
.for_each(|func| println!("{func}"));
|
||||
|
||||
println!();
|
||||
}
|
||||
@ -51,7 +51,7 @@ fn main() -> Result<(), Box<EvalAltResult>> {
|
||||
",
|
||||
)?;
|
||||
|
||||
println!("{:?}", result);
|
||||
println!("{result:?}");
|
||||
|
||||
let result = engine.eval::<TestStruct>(
|
||||
"
|
||||
@ -61,7 +61,7 @@ fn main() -> Result<(), Box<EvalAltResult>> {
|
||||
",
|
||||
)?;
|
||||
|
||||
println!("{:?}", result);
|
||||
println!("{result:?}");
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
@ -36,7 +36,7 @@ fn main() -> Result<(), Box<EvalAltResult>> {
|
||||
let r2 = func(1, 2);
|
||||
let r3 = func(1, 2);
|
||||
|
||||
println!("The Answers: {}, {}, {}", r1, r2, r3); // prints 40, 42, 44
|
||||
println!("The Answers: {r1}, {r2}, {r3}"); // prints 40, 42, 44
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
@ -67,7 +67,7 @@ fn main() -> Result<(), Box<EvalAltResult>> {
|
||||
engine
|
||||
.gen_fn_signatures(false)
|
||||
.into_iter()
|
||||
.for_each(|func| println!("{}", func));
|
||||
.for_each(|func| println!("{func}"));
|
||||
|
||||
println!();
|
||||
}
|
||||
@ -89,7 +89,7 @@ fn main() -> Result<(), Box<EvalAltResult>> {
|
||||
",
|
||||
)?;
|
||||
|
||||
println!("result: {}", result); // prints 1085764
|
||||
println!("result: {result}"); // prints 1085764
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
@ -48,7 +48,7 @@ fn main() -> Result<(), Box<EvalAltResult>> {
|
||||
engine
|
||||
.gen_fn_signatures(false)
|
||||
.into_iter()
|
||||
.for_each(|func| println!("{}", func));
|
||||
.for_each(|func| println!("{func}"));
|
||||
|
||||
println!();
|
||||
}
|
||||
@ -62,7 +62,7 @@ fn main() -> Result<(), Box<EvalAltResult>> {
|
||||
",
|
||||
)?;
|
||||
|
||||
println!("result: {}", result); // prints 1085764
|
||||
println!("result: {result}"); // prints 1085764
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
@ -78,12 +78,12 @@ pub fn main() {
|
||||
scope.push_constant("MY_CONSTANT", 42_i64);
|
||||
|
||||
// Compile the handler script.
|
||||
println!("> Loading script file: {}", path);
|
||||
println!("> Loading script file: {path}");
|
||||
|
||||
let ast = match engine.compile_file_with_scope(&mut scope, path.into()) {
|
||||
Ok(ast) => ast,
|
||||
Err(err) => {
|
||||
eprintln!("! Error: {}", err);
|
||||
eprintln!("! Error: {err}");
|
||||
println!("Cannot continue. Bye!");
|
||||
return;
|
||||
}
|
||||
@ -101,7 +101,7 @@ pub fn main() {
|
||||
let result = engine.call_fn_raw(&mut scope, &ast, false, true, "init", Some(&mut states), []);
|
||||
|
||||
if let Err(err) = result {
|
||||
eprintln!("! {}", err)
|
||||
eprintln!("! {err}")
|
||||
}
|
||||
|
||||
// Create handler instance
|
||||
@ -152,7 +152,7 @@ pub fn main() {
|
||||
engine.call_fn_raw(scope, ast, false, true, event, this_ptr, [arg.into()]);
|
||||
|
||||
if let Err(err) = result {
|
||||
eprintln!("! {}", err)
|
||||
eprintln!("! {err}")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -67,7 +67,7 @@ pub fn main() {
|
||||
scope.push_constant("MY_CONSTANT", 42_i64);
|
||||
|
||||
// Compile the handler script.
|
||||
println!("> Loading script file: {}", path);
|
||||
println!("> Loading script file: {path}");
|
||||
|
||||
let ast = match engine.compile_file_with_scope(&mut scope, path.into()) {
|
||||
Ok(ast) => ast,
|
||||
@ -89,7 +89,7 @@ pub fn main() {
|
||||
let result = engine.call_fn_raw(&mut scope, &ast, false, false, "init", None, []);
|
||||
|
||||
if let Err(err) = result {
|
||||
eprintln!("! {}", err)
|
||||
eprintln!("! {err}")
|
||||
}
|
||||
|
||||
// Create handler instance
|
||||
@ -127,7 +127,7 @@ pub fn main() {
|
||||
let result = engine.call_fn::<()>(scope, ast, event, (arg.to_string(),));
|
||||
|
||||
if let Err(err) = result {
|
||||
eprintln!("! {}", err)
|
||||
eprintln!("! {err}")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -81,12 +81,12 @@ pub fn main() {
|
||||
scope.push("state", states);
|
||||
|
||||
// Compile the handler script.
|
||||
println!("> Loading script file: {}", path);
|
||||
println!("> Loading script file: {path}");
|
||||
|
||||
let ast = match engine.compile_file_with_scope(&mut scope, path.into()) {
|
||||
Ok(ast) => ast,
|
||||
Err(err) => {
|
||||
eprintln!("! Error: {}", err);
|
||||
eprintln!("! Error: {err}");
|
||||
println!("Cannot continue. Bye!");
|
||||
return;
|
||||
}
|
||||
@ -103,7 +103,7 @@ pub fn main() {
|
||||
let result = engine.call_fn::<()>(&mut scope, &ast, "init", ());
|
||||
|
||||
if let Err(err) = result {
|
||||
eprintln!("! {}", err)
|
||||
eprintln!("! {err}")
|
||||
}
|
||||
|
||||
// Create handler instance
|
||||
@ -141,7 +141,7 @@ pub fn main() {
|
||||
let result = engine.call_fn::<()>(scope, ast, event, (arg.to_string(),));
|
||||
|
||||
if let Err(err) = result {
|
||||
eprintln!("! {}", err)
|
||||
eprintln!("! {err}")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -9,7 +9,7 @@ fn main() -> Result<(), Box<EvalAltResult>> {
|
||||
|
||||
let result = engine.eval::<i64>("40 + 2")?;
|
||||
|
||||
println!("The Answer: {}", result); // prints 42
|
||||
println!("The Answer: {result}"); // prints 42
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
@ -13,7 +13,7 @@ fn main() -> Result<(), Box<EvalAltResult>> {
|
||||
for _ in 0..10 {
|
||||
let result = engine.eval_with_scope::<i64>(&mut scope, "x += 1; x")?;
|
||||
|
||||
println!("result: {}", result);
|
||||
println!("result: {result}");
|
||||
}
|
||||
|
||||
println!("x = {}", scope.get_value::<i64>("x").unwrap());
|
||||
|
@ -36,13 +36,13 @@ fn main() {
|
||||
},
|
||||
};
|
||||
|
||||
println!("Source struct: {:#?}", x);
|
||||
println!("Source struct: {x:#?}");
|
||||
|
||||
// Convert the 'MyStruct' into a 'Dynamic'
|
||||
let map: Dynamic = to_dynamic(x).unwrap();
|
||||
|
||||
assert!(map.is::<Map>());
|
||||
println!("Serialized to Dynamic: {:#?}", map);
|
||||
println!("Serialized to Dynamic: {map:#?}");
|
||||
}
|
||||
|
||||
pub fn de() {
|
||||
@ -60,7 +60,7 @@ fn main() {
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
println!("Source Dynamic: {:#?}", result);
|
||||
println!("Source Dynamic: {result:#?}");
|
||||
|
||||
// Convert the 'Dynamic' object map into 'MyStruct'
|
||||
let x: MyStruct = from_dynamic(&result).unwrap();
|
||||
@ -77,7 +77,7 @@ fn main() {
|
||||
},
|
||||
}
|
||||
);
|
||||
println!("Deserialized to struct: {:#?}", x);
|
||||
println!("Deserialized to struct: {x:#?}");
|
||||
}
|
||||
|
||||
ser();
|
||||
|
@ -13,7 +13,7 @@ fn main() -> Result<(), Box<EvalAltResult>> {
|
||||
|
||||
let result = engine.eval::<i64>("add(40, 2)")?;
|
||||
|
||||
println!("Answer: {}", result); // prints 42
|
||||
println!("Answer: {result}"); // prints 42
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
@ -37,10 +37,10 @@ fn main() -> Result<(), Box<EvalAltResult>> {
|
||||
.register_fn("index_of", find_substring)
|
||||
// Register string functions using closures
|
||||
.register_fn("display", |label: &str, value: i64| {
|
||||
println!("{}: {}", label, value)
|
||||
println!("{label}: {value}")
|
||||
})
|
||||
.register_fn("display", |label: ImmutableString, value: &str| {
|
||||
println!(r#"{}: "{}""#, label, value) // Quote the input string
|
||||
println!(r#"{label}: "{value}""#) // Quote the input string
|
||||
});
|
||||
|
||||
let mut scope = Scope::new();
|
||||
|
@ -60,7 +60,7 @@ fn main() {
|
||||
let mut value: i64 = 0;
|
||||
|
||||
while value < 10 {
|
||||
println!("Value: {}", value);
|
||||
println!("Value: {value}");
|
||||
// Send value to script
|
||||
tx_master.send(value).unwrap();
|
||||
// Receive value from script
|
||||
|
@ -465,13 +465,13 @@ impl fmt::Debug for Expr {
|
||||
let mut display_pos = format!(" @ {:?}", self.start_position());
|
||||
|
||||
match self {
|
||||
Self::DynamicConstant(value, ..) => write!(f, "{:?}", value),
|
||||
Self::BoolConstant(value, ..) => write!(f, "{:?}", value),
|
||||
Self::IntegerConstant(value, ..) => write!(f, "{:?}", value),
|
||||
Self::DynamicConstant(value, ..) => write!(f, "{value:?}"),
|
||||
Self::BoolConstant(value, ..) => write!(f, "{value:?}"),
|
||||
Self::IntegerConstant(value, ..) => write!(f, "{value:?}"),
|
||||
#[cfg(not(feature = "no_float"))]
|
||||
Self::FloatConstant(value, ..) => write!(f, "{:?}", value),
|
||||
Self::CharConstant(value, ..) => write!(f, "{:?}", value),
|
||||
Self::StringConstant(value, ..) => write!(f, "{:?}", value),
|
||||
Self::FloatConstant(value, ..) => write!(f, "{value:?}"),
|
||||
Self::CharConstant(value, ..) => write!(f, "{value:?}"),
|
||||
Self::StringConstant(value, ..) => write!(f, "{value:?}"),
|
||||
Self::Unit(..) => f.write_str("()"),
|
||||
|
||||
Self::InterpolatedString(x, ..) => {
|
||||
@ -502,10 +502,10 @@ impl fmt::Debug for Expr {
|
||||
f.write_str(&x.3)?;
|
||||
#[cfg(not(feature = "no_module"))]
|
||||
if let Some(n) = x.1.index() {
|
||||
write!(f, " #{}", n)?;
|
||||
write!(f, " #{n}")?;
|
||||
}
|
||||
if let Some(n) = i.map_or_else(|| x.0, |n| NonZeroUsize::new(n.get() as usize)) {
|
||||
write!(f, " #{}", n)?;
|
||||
write!(f, " #{n}")?;
|
||||
}
|
||||
f.write_str(")")
|
||||
}
|
||||
|
@ -37,7 +37,7 @@ impl fmt::Debug for Namespace {
|
||||
}
|
||||
|
||||
if let Some(index) = self.index {
|
||||
write!(f, "{} -> ", index)?;
|
||||
write!(f, "{index} -> ")?;
|
||||
}
|
||||
|
||||
f.write_str(
|
||||
|
@ -185,8 +185,8 @@ impl fmt::Debug for RangeCase {
|
||||
#[inline(never)]
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
match self {
|
||||
Self::ExclusiveInt(r, n) => write!(f, "{}..{} => {}", r.start, r.end, n),
|
||||
Self::InclusiveInt(r, n) => write!(f, "{}..={} => {}", *r.start(), *r.end(), n),
|
||||
Self::ExclusiveInt(r, n) => write!(f, "{}..{} => {n}", r.start, r.end),
|
||||
Self::InclusiveInt(r, n) => write!(f, "{}..={} => {n}", *r.start(), *r.end()),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -75,7 +75,7 @@ fn print_current_source(
|
||||
}
|
||||
if !src.is_empty() {
|
||||
// Print just a line number for imported modules
|
||||
println!("{} @ {:?}", src, pos);
|
||||
println!("{src} @ {pos:?}");
|
||||
} else {
|
||||
// Print the current source line
|
||||
print_source(lines, pos, 0, window);
|
||||
@ -100,17 +100,16 @@ fn print_error(input: &str, mut err: EvalAltResult) {
|
||||
// Print error position
|
||||
if pos.is_none() {
|
||||
// No position
|
||||
println!("{}", err);
|
||||
println!("{err}");
|
||||
} else {
|
||||
// Specific position - print line text
|
||||
println!("{}{}", line_no, lines[pos.line().unwrap() - 1]);
|
||||
println!("{line_no}{}", lines[pos.line().unwrap() - 1]);
|
||||
|
||||
// Display position marker
|
||||
println!(
|
||||
"{0:>1$} {2}",
|
||||
"{0:>1$} {err}",
|
||||
"^",
|
||||
line_no.len() + pos.position().unwrap(),
|
||||
err
|
||||
);
|
||||
}
|
||||
}
|
||||
@ -247,11 +246,11 @@ fn debug_callback(
|
||||
BreakPoint::AtPosition { .. } => (),
|
||||
BreakPoint::AtFunctionName { ref name, .. }
|
||||
| BreakPoint::AtFunctionCall { ref name, .. } => {
|
||||
println!("! Call to function {}.", name)
|
||||
println!("! Call to function {name}.")
|
||||
}
|
||||
#[cfg(not(feature = "no_object"))]
|
||||
BreakPoint::AtProperty { ref name, .. } => {
|
||||
println!("! Property {} accessed.", name)
|
||||
println!("! Property {name} accessed.")
|
||||
}
|
||||
_ => unreachable!(),
|
||||
}
|
||||
@ -311,8 +310,8 @@ fn debug_callback(
|
||||
println!("{:?}", node);
|
||||
} else {
|
||||
match source {
|
||||
Some(source) => println!("{:?} {} @ {:?}", node, source, pos),
|
||||
None => println!("{:?} @ {:?}", node, pos),
|
||||
Some(source) => println!("{node:?} {source} @ {pos:?}"),
|
||||
None => println!("{node:?} @ {pos:?}"),
|
||||
}
|
||||
}
|
||||
println!();
|
||||
@ -327,7 +326,7 @@ fn debug_callback(
|
||||
["list" | "l", n] if n.parse::<usize>().is_ok() => {
|
||||
let num = n.parse::<usize>().unwrap();
|
||||
if num == 0 || num > lines.len() {
|
||||
eprintln!("\x1b[31mInvalid line: {}\x1b[39m", num);
|
||||
eprintln!("\x1b[31mInvalid line: {num}\x1b[39m");
|
||||
} else {
|
||||
let pos = Position::new(num as u16, 0);
|
||||
print_current_source(&mut context, source, pos, lines, (3, 6));
|
||||
@ -340,17 +339,17 @@ fn debug_callback(
|
||||
["next" | "n"] => break Ok(DebuggerCommand::Next),
|
||||
["scope"] => println!("{}", context.scope()),
|
||||
["print" | "p", "this"] => match context.this_ptr() {
|
||||
Some(value) => println!("=> {:?}", value),
|
||||
Some(value) => println!("=> {value:?}"),
|
||||
None => println!("`this` pointer is unbound."),
|
||||
},
|
||||
["print" | "p", var_name] => match context.scope().get_value::<Dynamic>(var_name) {
|
||||
Some(value) => println!("=> {:?}", value),
|
||||
None => eprintln!("Variable not found: {}", var_name),
|
||||
Some(value) => println!("=> {value:?}"),
|
||||
None => eprintln!("Variable not found: {var_name}"),
|
||||
},
|
||||
["print" | "p"] => {
|
||||
println!("{}", context.scope().clone_visible());
|
||||
if let Some(value) = context.this_ptr() {
|
||||
println!("this = {:?}", value);
|
||||
println!("this = {value:?}");
|
||||
}
|
||||
}
|
||||
#[cfg(not(feature = "no_module"))]
|
||||
@ -379,7 +378,7 @@ fn debug_callback(
|
||||
.iter()
|
||||
.rev()
|
||||
{
|
||||
println!("{}", frame)
|
||||
println!("{frame}")
|
||||
}
|
||||
}
|
||||
["info" | "i", "break" | "b"] => Iterator::for_each(
|
||||
@ -396,7 +395,7 @@ fn debug_callback(
|
||||
print!("{}", line_num);
|
||||
print_source(lines, *pos, line_num.len(), (0, 0));
|
||||
}
|
||||
_ => println!("[{}] {}", i + 1, bp),
|
||||
_ => println!("[{}] {bp}", i + 1),
|
||||
},
|
||||
),
|
||||
["enable" | "en", n] => {
|
||||
@ -414,12 +413,12 @@ fn debug_callback(
|
||||
.get_mut(n - 1)
|
||||
.unwrap()
|
||||
.enable(true);
|
||||
println!("Break-point #{} enabled.", n)
|
||||
println!("Break-point #{n} enabled.")
|
||||
} else {
|
||||
eprintln!("\x1b[31mInvalid break-point: {}\x1b[39m", n);
|
||||
eprintln!("\x1b[31mInvalid break-point: {n}\x1b[39m");
|
||||
}
|
||||
} else {
|
||||
eprintln!("\x1b[31mInvalid break-point: '{}'\x1b[39m", n);
|
||||
eprintln!("\x1b[31mInvalid break-point: '{n}'\x1b[39m");
|
||||
}
|
||||
}
|
||||
["disable" | "dis", n] => {
|
||||
@ -437,12 +436,12 @@ fn debug_callback(
|
||||
.get_mut(n - 1)
|
||||
.unwrap()
|
||||
.enable(false);
|
||||
println!("Break-point #{} disabled.", n)
|
||||
println!("Break-point #{n} disabled.")
|
||||
} else {
|
||||
eprintln!("\x1b[31mInvalid break-point: {}\x1b[39m", n);
|
||||
eprintln!("\x1b[31mInvalid break-point: {n}\x1b[39m");
|
||||
}
|
||||
} else {
|
||||
eprintln!("\x1b[31mInvalid break-point: '{}'\x1b[39m", n);
|
||||
eprintln!("\x1b[31mInvalid break-point: '{n}'\x1b[39m");
|
||||
}
|
||||
}
|
||||
["delete" | "d", n] => {
|
||||
@ -458,12 +457,12 @@ fn debug_callback(
|
||||
.debugger
|
||||
.break_points_mut()
|
||||
.remove(n - 1);
|
||||
println!("Break-point #{} deleted.", n)
|
||||
println!("Break-point #{n} deleted.")
|
||||
} else {
|
||||
eprintln!("\x1b[31mInvalid break-point: {}\x1b[39m", n);
|
||||
eprintln!("\x1b[31mInvalid break-point: {n}\x1b[39m");
|
||||
}
|
||||
} else {
|
||||
eprintln!("\x1b[31mInvalid break-point: '{}'\x1b[39m", n);
|
||||
eprintln!("\x1b[31mInvalid break-point: '{n}'\x1b[39m");
|
||||
}
|
||||
}
|
||||
["delete" | "d"] => {
|
||||
@ -481,14 +480,14 @@ fn debug_callback(
|
||||
args,
|
||||
enabled: true,
|
||||
};
|
||||
println!("Break-point added for {}", bp);
|
||||
println!("Break-point added for {bp}");
|
||||
context
|
||||
.global_runtime_state_mut()
|
||||
.debugger
|
||||
.break_points_mut()
|
||||
.push(bp);
|
||||
} else {
|
||||
eprintln!("\x1b[31mInvalid number of arguments: '{}'\x1b[39m", args);
|
||||
eprintln!("\x1b[31mInvalid number of arguments: '{args}'\x1b[39m");
|
||||
}
|
||||
}
|
||||
// Property name
|
||||
@ -498,7 +497,7 @@ fn debug_callback(
|
||||
name: param[1..].into(),
|
||||
enabled: true,
|
||||
};
|
||||
println!("Break-point added for {}", bp);
|
||||
println!("Break-point added for {bp}");
|
||||
context
|
||||
.global_runtime_state_mut()
|
||||
.debugger
|
||||
@ -521,14 +520,14 @@ fn debug_callback(
|
||||
pos: Position::new(n as u16, 0),
|
||||
enabled: true,
|
||||
};
|
||||
println!("Break-point added {}", bp);
|
||||
println!("Break-point added {bp}");
|
||||
context
|
||||
.global_runtime_state_mut()
|
||||
.debugger
|
||||
.break_points_mut()
|
||||
.push(bp);
|
||||
} else {
|
||||
eprintln!("\x1b[31mInvalid line number: '{}'\x1b[39m", n);
|
||||
eprintln!("\x1b[31mInvalid line number: '{n}'\x1b[39m");
|
||||
}
|
||||
}
|
||||
// Function name parameter
|
||||
@ -537,7 +536,7 @@ fn debug_callback(
|
||||
name: param.trim().into(),
|
||||
enabled: true,
|
||||
};
|
||||
println!("Break-point added for {}", bp);
|
||||
println!("Break-point added for {bp}");
|
||||
context
|
||||
.global_runtime_state_mut()
|
||||
.debugger
|
||||
@ -551,7 +550,7 @@ fn debug_callback(
|
||||
pos,
|
||||
enabled: true,
|
||||
};
|
||||
println!("Break-point added {}", bp);
|
||||
println!("Break-point added {bp}");
|
||||
context
|
||||
.global_runtime_state_mut()
|
||||
.debugger
|
||||
@ -588,7 +587,7 @@ fn debug_callback(
|
||||
|
||||
fn main() {
|
||||
let title = format!("Rhai Debugger (version {})", env!("CARGO_PKG_VERSION"));
|
||||
println!("{}", title);
|
||||
println!("{title}");
|
||||
println!("{0:=<1$}", "", title.len());
|
||||
|
||||
// Initialize scripting engine
|
||||
|
@ -26,17 +26,16 @@ fn print_error(input: &str, mut err: EvalAltResult) {
|
||||
// Print error position
|
||||
if pos.is_none() {
|
||||
// No position
|
||||
println!("{}", err);
|
||||
println!("{err}");
|
||||
} else {
|
||||
// Specific position - print line text
|
||||
println!("{}{}", line_no, lines[pos.line().unwrap() - 1]);
|
||||
println!("{line_no}{}", lines[pos.line().unwrap() - 1]);
|
||||
|
||||
// Display position marker
|
||||
println!(
|
||||
"{0:>1$} {2}",
|
||||
"{0:>1$} {err}",
|
||||
"^",
|
||||
line_no.len() + pos.position().unwrap(),
|
||||
err
|
||||
);
|
||||
}
|
||||
}
|
||||
@ -119,7 +118,7 @@ fn load_script_files(engine: &mut Engine) {
|
||||
for filename in env::args().skip(1) {
|
||||
let filename = match Path::new(&filename).canonicalize() {
|
||||
Err(err) => {
|
||||
eprintln!("Error script file path: {}\n{}", filename, err);
|
||||
eprintln!("Error script file path: {filename}\n{err}");
|
||||
exit(1);
|
||||
}
|
||||
Ok(f) => {
|
||||
@ -164,7 +163,7 @@ fn load_script_files(engine: &mut Engine) {
|
||||
let filename = filename.to_string_lossy();
|
||||
|
||||
eprintln!("{:=<1$}", "", filename.len());
|
||||
eprintln!("{}", filename);
|
||||
eprintln!("{filename}");
|
||||
eprintln!("{:=<1$}", "", filename.len());
|
||||
eprintln!();
|
||||
|
||||
@ -277,13 +276,13 @@ mod sample_functions {
|
||||
#[rhai_fn(name = "test")]
|
||||
pub fn test2(x: &mut INT, y: INT, z: &str) {
|
||||
*x += y + (z.len() as INT);
|
||||
println!("{} {} {}", x, y, z);
|
||||
println!("{x} {y} {z}");
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let title = format!("Rhai REPL tool (version {})", env!("CARGO_PKG_VERSION"));
|
||||
println!("{}", title);
|
||||
println!("{title}");
|
||||
println!("{0:=<1$}", "", title.len());
|
||||
|
||||
#[cfg(not(feature = "no_optimize"))]
|
||||
@ -338,11 +337,11 @@ fn main() {
|
||||
history_offset += 1;
|
||||
}
|
||||
if input.contains('\n') {
|
||||
println!("[{}] ~~~~", replacement_index);
|
||||
println!("{}", input);
|
||||
println!("[{replacement_index}] ~~~~");
|
||||
println!("{input}");
|
||||
println!("~~~~");
|
||||
} else {
|
||||
println!("[{}] {}", replacement_index, input);
|
||||
println!("[{replacement_index}] {input}");
|
||||
}
|
||||
replacement_index = 0;
|
||||
} else {
|
||||
@ -374,7 +373,7 @@ fn main() {
|
||||
Err(ReadlineError::Interrupted) | Err(ReadlineError::Eof) => break 'main_loop,
|
||||
|
||||
Err(err) => {
|
||||
eprintln!("Error: {:?}", err);
|
||||
eprintln!("Error: {err:?}");
|
||||
break 'main_loop;
|
||||
}
|
||||
}
|
||||
@ -401,12 +400,12 @@ fn main() {
|
||||
"history" => {
|
||||
for (i, h) in rl.history().iter().enumerate() {
|
||||
match &h.split('\n').collect::<Vec<_>>()[..] {
|
||||
[line] => println!("[{}] {}", history_offset + i, line),
|
||||
[line] => println!("[{}] {line}", history_offset + i),
|
||||
lines => {
|
||||
for (x, line) in lines.iter().enumerate() {
|
||||
let number = format!("[{}]", history_offset + i);
|
||||
if x == 0 {
|
||||
println!("{} {}", number, line.trim_end());
|
||||
println!("{number} {}", line.trim_end());
|
||||
} else {
|
||||
println!("{0:>1$} {2}", "", number.len(), line.trim_end());
|
||||
}
|
||||
@ -439,30 +438,30 @@ fn main() {
|
||||
continue;
|
||||
}
|
||||
"scope" => {
|
||||
println!("{}", scope);
|
||||
println!("{scope}");
|
||||
continue;
|
||||
}
|
||||
#[cfg(not(feature = "no_optimize"))]
|
||||
"astu" => {
|
||||
// print the last un-optimized AST
|
||||
println!("{:#?}\n", ast_u);
|
||||
println!("{ast_u:#?}\n");
|
||||
continue;
|
||||
}
|
||||
"ast" => {
|
||||
// print the last AST
|
||||
println!("{:#?}\n", ast);
|
||||
println!("{ast:#?}\n");
|
||||
continue;
|
||||
}
|
||||
#[cfg(feature = "metadata")]
|
||||
"functions" => {
|
||||
// print a list of all registered functions
|
||||
for f in engine.gen_fn_signatures(false) {
|
||||
println!("{}", f)
|
||||
println!("{f}")
|
||||
}
|
||||
|
||||
#[cfg(not(feature = "no_function"))]
|
||||
for f in main_ast.iter_functions() {
|
||||
println!("{}", f)
|
||||
println!("{f}")
|
||||
}
|
||||
|
||||
println!();
|
||||
@ -505,7 +504,7 @@ fn main() {
|
||||
replacement = Some(line.clone());
|
||||
replacement_index = history_offset + (rl.history().len() - 1 - n);
|
||||
}
|
||||
None => eprintln!("History line not found: {}", text),
|
||||
None => eprintln!("History line not found: {text}"),
|
||||
}
|
||||
continue;
|
||||
}
|
||||
@ -561,7 +560,7 @@ fn main() {
|
||||
engine.eval_ast_with_scope::<Dynamic>(&mut scope, &main_ast)
|
||||
}) {
|
||||
Ok(result) if !result.is::<()>() => {
|
||||
println!("=> {:?}", result);
|
||||
println!("=> {result:?}");
|
||||
println!();
|
||||
}
|
||||
Ok(_) => (),
|
||||
|
@ -7,12 +7,11 @@ fn eprint_error(input: &str, mut err: EvalAltResult) {
|
||||
let line = pos.line().unwrap();
|
||||
let line_no = format!("{line}: ");
|
||||
|
||||
eprintln!("{}{}", line_no, lines[line - 1]);
|
||||
eprintln!("{line_no}{}", lines[line - 1]);
|
||||
eprintln!(
|
||||
"{:>1$} {2}",
|
||||
"{:>1$} {err_msg}",
|
||||
"^",
|
||||
line_no.len() + pos.position().unwrap(),
|
||||
err_msg
|
||||
);
|
||||
eprintln!();
|
||||
}
|
||||
@ -24,7 +23,7 @@ fn eprint_error(input: &str, mut err: EvalAltResult) {
|
||||
|
||||
if pos.is_none() {
|
||||
// No position
|
||||
eprintln!("{}", err);
|
||||
eprintln!("{err}");
|
||||
} else {
|
||||
// Specific position
|
||||
eprint_line(&lines, pos, &err.to_string())
|
||||
@ -37,7 +36,7 @@ fn main() {
|
||||
for filename in env::args().skip(1) {
|
||||
let filename = match Path::new(&filename).canonicalize() {
|
||||
Err(err) => {
|
||||
eprintln!("Error script file path: {}\n{}", filename, err);
|
||||
eprintln!("Error script file path: {filename}\n{err}");
|
||||
exit(1);
|
||||
}
|
||||
Ok(f) => match f.strip_prefix(std::env::current_dir().unwrap().canonicalize().unwrap())
|
||||
@ -94,7 +93,7 @@ fn main() {
|
||||
let filename = filename.to_string_lossy();
|
||||
|
||||
eprintln!("{:=<1$}", "", filename.len());
|
||||
eprintln!("{}", filename);
|
||||
eprintln!("{filename}");
|
||||
eprintln!("{:=<1$}", "", filename.len());
|
||||
eprintln!();
|
||||
|
||||
|
@ -85,7 +85,7 @@ pub const OP_INCLUSIVE_RANGE: &str = Token::InclusiveRange.literal_syntax();
|
||||
///
|
||||
/// let result = engine.eval::<i64>("40 + 2")?;
|
||||
///
|
||||
/// println!("Answer: {}", result); // prints 42
|
||||
/// println!("Answer: {result}"); // prints 42
|
||||
/// # Ok(())
|
||||
/// # }
|
||||
/// ```
|
||||
@ -236,18 +236,12 @@ impl Engine {
|
||||
#[cfg(not(feature = "no_std"))]
|
||||
#[cfg(not(target_family = "wasm"))]
|
||||
{
|
||||
engine.print = Box::new(|s| println!("{}", s));
|
||||
engine.debug = Box::new(|s, source, pos| {
|
||||
source.map_or_else(
|
||||
|| {
|
||||
if pos.is_none() {
|
||||
println!("{s}");
|
||||
} else {
|
||||
println!("{pos:?} | {s}");
|
||||
}
|
||||
},
|
||||
|source| println!("{source} @ {pos:?} | {s}"),
|
||||
)
|
||||
engine.print = Box::new(|s| println!("{s}"));
|
||||
engine.debug = Box::new(|s, source, pos| match (source, pos) {
|
||||
(Some(source), crate::Position::NONE) => println!("{source} | {s}"),
|
||||
(Some(source), pos) => println!("{source} @ {pos:?} | {s}"),
|
||||
(None, crate::Position::NONE) => println!("{s}"),
|
||||
(None, pos) => println!("{pos:?} | {s}"),
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -148,35 +148,30 @@ impl fmt::Display for BreakPoint {
|
||||
pos,
|
||||
enabled,
|
||||
} => {
|
||||
if source.is_empty() {
|
||||
write!(f, "@ {:?}", pos)?;
|
||||
} else {
|
||||
write!(f, "{} @ {:?}", source, pos)?;
|
||||
if !source.is_empty() {
|
||||
write!(f, "{source} ")?;
|
||||
}
|
||||
write!(f, "@ {pos:?}")?;
|
||||
if !*enabled {
|
||||
f.write_str(" (disabled)")?;
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
Self::AtFunctionName {
|
||||
name: fn_name,
|
||||
enabled,
|
||||
} => {
|
||||
write!(f, "{} (...)", fn_name)?;
|
||||
Self::AtFunctionName { name, enabled } => {
|
||||
write!(f, "{name} (...)")?;
|
||||
if !*enabled {
|
||||
f.write_str(" (disabled)")?;
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
Self::AtFunctionCall {
|
||||
name: fn_name,
|
||||
name,
|
||||
args,
|
||||
enabled,
|
||||
} => {
|
||||
write!(
|
||||
f,
|
||||
"{} ({})",
|
||||
fn_name,
|
||||
"{name} ({})",
|
||||
repeat("_").take(*args).collect::<Vec<_>>().join(", ")
|
||||
)?;
|
||||
if !*enabled {
|
||||
@ -185,11 +180,8 @@ impl fmt::Display for BreakPoint {
|
||||
Ok(())
|
||||
}
|
||||
#[cfg(not(feature = "no_object"))]
|
||||
Self::AtProperty {
|
||||
name: prop,
|
||||
enabled,
|
||||
} => {
|
||||
write!(f, ".{}", prop)?;
|
||||
Self::AtProperty { name, enabled } => {
|
||||
write!(f, ".{name}")?;
|
||||
if !*enabled {
|
||||
f.write_str(" (disabled)")?;
|
||||
}
|
||||
@ -251,11 +243,10 @@ impl fmt::Display for CallStackFrame {
|
||||
fp.finish()?;
|
||||
|
||||
if !self.pos.is_none() {
|
||||
if self.source.is_empty() {
|
||||
write!(f, " @ {:?}", self.pos)?;
|
||||
} else {
|
||||
write!(f, ": {} @ {:?}", self.source, self.pos)?;
|
||||
if !self.source.is_empty() {
|
||||
write!(f, ": {}", self.source)?;
|
||||
}
|
||||
write!(f, " @ {:?}", self.pos)?;
|
||||
}
|
||||
|
||||
Ok(())
|
||||
|
@ -31,10 +31,10 @@ impl fmt::Debug for CallableFunction {
|
||||
#[inline(never)]
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
match self {
|
||||
Self::Pure(..) => write!(f, "NativePureFunction"),
|
||||
Self::Method(..) => write!(f, "NativeMethod"),
|
||||
Self::Iterator(..) => write!(f, "NativeIterator"),
|
||||
Self::Plugin(..) => write!(f, "PluginFunction"),
|
||||
Self::Pure(..) => f.write_str("NativePureFunction"),
|
||||
Self::Method(..) => f.write_str("NativeMethod"),
|
||||
Self::Iterator(..) => f.write_str("NativeIterator"),
|
||||
Self::Plugin(..) => f.write_str("PluginFunction"),
|
||||
|
||||
#[cfg(not(feature = "no_function"))]
|
||||
Self::Script(fn_def) => fmt::Debug::fmt(fn_def, f),
|
||||
@ -45,10 +45,10 @@ impl fmt::Debug for CallableFunction {
|
||||
impl fmt::Display for CallableFunction {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
match self {
|
||||
Self::Pure(..) => write!(f, "NativePureFunction"),
|
||||
Self::Method(..) => write!(f, "NativeMethod"),
|
||||
Self::Iterator(..) => write!(f, "NativeIterator"),
|
||||
Self::Plugin(..) => write!(f, "PluginFunction"),
|
||||
Self::Pure(..) => f.write_str("NativePureFunction"),
|
||||
Self::Method(..) => f.write_str("NativeMethod"),
|
||||
Self::Iterator(..) => f.write_str("NativeIterator"),
|
||||
Self::Plugin(..) => f.write_str("PluginFunction"),
|
||||
|
||||
#[cfg(not(feature = "no_function"))]
|
||||
Self::Script(s) => fmt::Display::fmt(s, f),
|
||||
|
@ -416,7 +416,7 @@ impl Hash for Dynamic {
|
||||
impl fmt::Display for Dynamic {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
match self.0 {
|
||||
Union::Unit(..) => write!(f, ""),
|
||||
Union::Unit(..) => Ok(()),
|
||||
Union::Bool(ref v, ..) => fmt::Display::fmt(v, f),
|
||||
Union::Str(ref v, ..) => fmt::Display::fmt(v, f),
|
||||
Union::Char(ref v, ..) => fmt::Display::fmt(v, f),
|
||||
@ -527,7 +527,7 @@ impl fmt::Debug for Dynamic {
|
||||
if i > 0 && i % 8 == 0 {
|
||||
f.write_str(" ")?;
|
||||
}
|
||||
write!(f, "{:02x}", v)
|
||||
write!(f, "{v:02x}")
|
||||
})?;
|
||||
f.write_str("]")
|
||||
}
|
||||
|
@ -38,11 +38,11 @@ impl Error for LexError {}
|
||||
impl fmt::Display for LexError {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
match self {
|
||||
Self::UnexpectedInput(s) => write!(f, "Unexpected '{}'", s),
|
||||
Self::MalformedEscapeSequence(s) => write!(f, "Invalid escape sequence: '{}'", s),
|
||||
Self::MalformedNumber(s) => write!(f, "Invalid number: '{}'", s),
|
||||
Self::MalformedChar(s) => write!(f, "Invalid character: '{}'", s),
|
||||
Self::MalformedIdentifier(s) => write!(f, "Variable name is not proper: '{}'", s),
|
||||
Self::UnexpectedInput(s) => write!(f, "Unexpected '{s}'"),
|
||||
Self::MalformedEscapeSequence(s) => write!(f, "Invalid escape sequence: '{s}'"),
|
||||
Self::MalformedNumber(s) => write!(f, "Invalid number: '{s}'"),
|
||||
Self::MalformedChar(s) => write!(f, "Invalid character: '{s}'"),
|
||||
Self::MalformedIdentifier(s) => write!(f, "Variable name is not proper: '{s}'"),
|
||||
Self::UnterminatedString => f.write_str("Open string is not terminated"),
|
||||
Self::StringTooLong(max) => write!(
|
||||
f,
|
||||
@ -50,7 +50,7 @@ impl fmt::Display for LexError {
|
||||
max
|
||||
),
|
||||
Self::ImproperSymbol(s, d) if d.is_empty() => {
|
||||
write!(f, "Invalid symbol encountered: '{}'", s)
|
||||
write!(f, "Invalid symbol encountered: '{s}'")
|
||||
}
|
||||
Self::ImproperSymbol(.., d) => f.write_str(d),
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user