MCPcopy Index your code
hub / github.com/RustPython/RustPython / make_stdout_object

Function make_stdout_object

crates/wasm/src/wasm_builtins.rs:19–45  ·  view source on GitHub ↗
(
    vm: &VirtualMachine,
    write_f: impl Fn(&str, &VirtualMachine) -> PyResult<()> + 'static,
)

Source from the content-addressed store, hash-verified

17}
18
19pub fn make_stdout_object(
20 vm: &VirtualMachine,
21 write_f: impl Fn(&str, &VirtualMachine) -> PyResult<()> + 'static,
22) -> PyObjectRef {
23 let ctx = &vm.ctx;
24 // there's not really any point to storing this class so that there's a consistent type object,
25 // we just want a half-decent repr() output
26 let cls = PyRef::leak(py_class!(
27 ctx,
28 "JSStdout",
29 vm.ctx.types.object_type.to_owned(),
30 {}
31 ));
32 let write_method = vm.new_method(
33 "write",
34 cls,
35 move |_self: PyObjectRef, data: PyStrRef, vm: &VirtualMachine| -> PyResult<()> {
36 write_f(data.expect_str(), vm)
37 },
38 );
39 let flush_method = vm.new_method("flush", cls, |_self: PyObjectRef| {});
40 extend_class!(ctx, cls, {
41 "write" => write_method,
42 "flush" => flush_method,
43 });
44 ctx.new_base_object(cls.to_owned(), None)
45}

Callers 1

set_stdoutMethod · 0.85

Calls 5

leakFunction · 0.85
expect_strMethod · 0.80
new_base_objectMethod · 0.80
new_methodMethod · 0.45
to_ownedMethod · 0.45

Tested by

no test coverage detected