Skip to content

Commit 7b23d0e

Browse files
committed
rust fmt
1 parent 9a86bbd commit 7b23d0e

File tree

3 files changed

+21
-17
lines changed

3 files changed

+21
-17
lines changed

vm/src/builtins.rs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,11 @@ use super::obj::objiter;
1414
use super::obj::objstr;
1515
use super::obj::objtype;
1616

17-
use super::stdlib::io::io_open;
1817
use super::pyobject::{
1918
AttributeProtocol, IdProtocol, PyContext, PyFuncArgs, PyObject, PyObjectKind, PyObjectRef,
20-
PyResult, Scope, TypeProtocol
19+
PyResult, Scope, TypeProtocol,
2120
};
21+
use super::stdlib::io::io_open;
2222

2323
use super::vm::VirtualMachine;
2424
use num_bigint::ToBigInt;
@@ -242,8 +242,7 @@ fn builtin_eval(vm: &mut VirtualMachine, args: PyFuncArgs) -> PyResult {
242242
let scope = PyObject {
243243
kind: PyObjectKind::Scope { scope: scope_inner },
244244
typ: None,
245-
}
246-
.into_ref();
245+
}.into_ref();
247246

248247
// Run the source:
249248
vm.run_code_obj(code_obj.clone(), scope)
@@ -290,8 +289,7 @@ fn builtin_exec(vm: &mut VirtualMachine, args: PyFuncArgs) -> PyResult {
290289
let scope = PyObject {
291290
kind: PyObjectKind::Scope { scope: scope_inner },
292291
typ: None,
293-
}
294-
.into_ref();
292+
}.into_ref();
295293

296294
// Run the code:
297295
vm.run_code_obj(code_obj, scope)

vm/src/obj/objbytearray.rs

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,13 @@ use super::super::pyobject::{
77
use super::objint;
88

99
use super::super::vm::VirtualMachine;
10-
use super::objbytes::get_value;
10+
// use super::objbytes::get_value;
1111
use super::objtype;
12+
use num_bigint::ToBigInt;
1213
use num_traits::ToPrimitive;
13-
use num_bigint::{ToBigInt};
14+
15+
use std::cell::Ref;
16+
use std::ops::Deref;
1417

1518
// Binary data support
1619

@@ -63,26 +66,20 @@ fn bytearray_new(vm: &mut VirtualMachine, args: PyFuncArgs) -> PyResult {
6366
} else {
6467
vec![]
6568
};
66-
6769
Ok(PyObject::new(
68-
PyObjectKind::Bytes { value: value },
70+
PyObjectKind::ByteArray { value: value },
6971
cls.clone(),
7072
))
7173
}
7274

7375
fn bytesarray_len(vm: &mut VirtualMachine, args: PyFuncArgs) -> PyResult {
74-
arg_check!(
75-
vm,
76-
args,
77-
required = [(a, Some(vm.ctx.bytearray_type()))]
78-
);
76+
arg_check!(vm, args, required = [(a, Some(vm.ctx.bytearray_type()))]);
7977

8078
let byte_vec = get_value(a).to_vec();
8179
let value = byte_vec.len().to_bigint();
8280
Ok(vm.ctx.new_int(value.unwrap()))
8381
}
8482

85-
8683
fn bytearray_eq(vm: &mut VirtualMachine, args: PyFuncArgs) -> PyResult {
8784
arg_check!(
8885
vm,
@@ -98,6 +95,15 @@ fn bytearray_eq(vm: &mut VirtualMachine, args: PyFuncArgs) -> PyResult {
9895
Ok(vm.ctx.new_bool(result))
9996
}
10097

98+
pub fn get_value<'a>(obj: &'a PyObjectRef) -> impl Deref<Target = Vec<u8>> + 'a {
99+
Ref::map(obj.borrow(), |py_obj| {
100+
if let PyObjectKind::ByteArray { ref value } = py_obj.kind {
101+
value
102+
} else {
103+
panic!("Inner error getting int {:?}", obj);
104+
}
105+
})
106+
}
101107
/*
102108
fn bytearray_getitem(vm: &mut VirtualMachine, args: PyFuncArgs) -> PyResult {
103109
arg_check!(

vm/src/stdlib/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,14 @@ pub mod io;
33
mod json;
44
mod keyword;
55
mod math;
6+
mod os;
67
mod pystruct;
78
mod random;
89
mod re;
910
mod time_module;
1011
mod tokenize;
1112
mod types;
1213
mod weakref;
13-
mod os;
1414
use std::collections::HashMap;
1515

1616
use super::pyobject::{PyContext, PyObjectRef};

0 commit comments

Comments
 (0)