Group use of std under one root.

This commit is contained in:
Stephen Chung 2020-03-10 10:07:44 +08:00
parent bae9946291
commit feaad4e0da
4 changed files with 24 additions and 22 deletions

View File

@ -1,7 +1,9 @@
//! Helper module which defines the `Any` trait to to allow dynamic value handling. //! Helper module which defines the `Any` trait to to allow dynamic value handling.
use std::any::{type_name, TypeId}; use std::{
use std::fmt; any::{type_name, TypeId},
fmt,
};
/// An raw value of any type. /// An raw value of any type.
pub type Variant = dyn Any; pub type Variant = dyn Any;

View File

@ -8,8 +8,12 @@ use crate::fn_register::RegisterFn;
use crate::parser::{lex, parse, Position, AST}; use crate::parser::{lex, parse, Position, AST};
use crate::result::EvalAltResult; use crate::result::EvalAltResult;
use crate::scope::Scope; use crate::scope::Scope;
use std::any::{type_name, TypeId}; use std::{
use std::sync::Arc; any::{type_name, TypeId},
fs::File,
io::prelude::*,
sync::Arc,
};
impl<'e> Engine<'e> { impl<'e> Engine<'e> {
pub(crate) fn register_fn_raw( pub(crate) fn register_fn_raw(
@ -102,9 +106,6 @@ impl<'e> Engine<'e> {
/// Compile a file into an AST. /// Compile a file into an AST.
pub fn compile_file(&self, filename: &str) -> Result<AST, EvalAltResult> { pub fn compile_file(&self, filename: &str) -> Result<AST, EvalAltResult> {
use std::fs::File;
use std::io::prelude::*;
let mut f = File::open(filename) let mut f = File::open(filename)
.map_err(|err| EvalAltResult::ErrorReadingScriptFile(filename.into(), err))?; .map_err(|err| EvalAltResult::ErrorReadingScriptFile(filename.into(), err))?;
@ -117,9 +118,6 @@ impl<'e> Engine<'e> {
/// Evaluate a file. /// Evaluate a file.
pub fn eval_file<T: Any + Clone>(&mut self, filename: &str) -> Result<T, EvalAltResult> { pub fn eval_file<T: Any + Clone>(&mut self, filename: &str) -> Result<T, EvalAltResult> {
use std::fs::File;
use std::io::prelude::*;
let mut f = File::open(filename) let mut f = File::open(filename)
.map_err(|err| EvalAltResult::ErrorReadingScriptFile(filename.into(), err))?; .map_err(|err| EvalAltResult::ErrorReadingScriptFile(filename.into(), err))?;
@ -208,9 +206,6 @@ impl<'e> Engine<'e> {
/// Evaluate a file, but throw away the result and only return error (if any). /// Evaluate a file, but throw away the result and only return error (if any).
/// Useful for when you don't need the result, but still need to keep track of possible errors. /// Useful for when you don't need the result, but still need to keep track of possible errors.
pub fn consume_file(&mut self, filename: &str) -> Result<(), EvalAltResult> { pub fn consume_file(&mut self, filename: &str) -> Result<(), EvalAltResult> {
use std::fs::File;
use std::io::prelude::*;
let mut f = File::open(filename) let mut f = File::open(filename)
.map_err(|err| EvalAltResult::ErrorReadingScriptFile(filename.into(), err))?; .map_err(|err| EvalAltResult::ErrorReadingScriptFile(filename.into(), err))?;

View File

@ -4,9 +4,12 @@
use crate::any::Any; use crate::any::Any;
use crate::engine::{Array, Engine}; use crate::engine::{Array, Engine};
use crate::fn_register::RegisterFn; use crate::fn_register::RegisterFn;
use std::fmt::{Debug, Display}; use std::{
use std::ops::{Add, BitAnd, BitOr, BitXor, Div, Mul, Neg, Range, Rem, Sub}; fmt::{Debug, Display},
use std::{i32, i64, u32}; i32, i64,
ops::{Add, BitAnd, BitOr, BitXor, Div, Mul, Neg, Range, Rem, Sub},
u32,
};
#[cfg(feature = "unchecked")] #[cfg(feature = "unchecked")]
use std::ops::{Shl, Shr}; use std::ops::{Shl, Shr};

View File

@ -4,12 +4,14 @@ use crate::any::{Any, AnyExt, Dynamic, Variant};
use crate::parser::{Expr, FnDef, Position, Stmt}; use crate::parser::{Expr, FnDef, Position, Stmt};
use crate::result::EvalAltResult; use crate::result::EvalAltResult;
use crate::scope::Scope; use crate::scope::Scope;
use std::any::{type_name, TypeId}; use std::{
use std::borrow::Cow; any::{type_name, TypeId},
use std::cmp::{PartialEq, PartialOrd}; borrow::Cow,
use std::collections::HashMap; cmp::{PartialEq, PartialOrd},
use std::iter::once; collections::HashMap,
use std::sync::Arc; iter::once,
sync::Arc,
};
/// An dynamic array of `Dynamic` values. /// An dynamic array of `Dynamic` values.
pub type Array = Vec<Dynamic>; pub type Array = Vec<Dynamic>;