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

Method truncate

crates/vm/src/stdlib/_io.rs:1683–1698  ·  view source on GitHub ↗
(
            zelf: PyRef<Self>,
            pos: OptionalOption<PyObjectRef>,
            vm: &VirtualMachine,
        )

Source from the content-addressed store, hash-verified

1681
1682 #[pymethod]
1683 fn truncate(
1684 zelf: PyRef<Self>,
1685 pos: OptionalOption<PyObjectRef>,
1686 vm: &VirtualMachine,
1687 ) -> PyResult {
1688 let pos = pos.flatten().to_pyobject(vm);
1689 let mut data = zelf.lock(vm)?;
1690 data.check_init(vm)?;
1691 if !data.writable() {
1692 return Err(new_unsupported_operation(vm, "truncate".to_owned()));
1693 }
1694 data.flush_rewind(vm)?;
1695 let res = vm.call_method(data.raw.as_ref().unwrap(), "truncate", (pos,))?;
1696 let _ = data.raw_tell(vm);
1697 Ok(res)
1698 }
1699 #[pymethod]
1700 fn detach(zelf: PyRef<Self>, vm: &VirtualMachine) -> PyResult {
1701 vm.call_method(zelf.as_object(), "flush", ())?;

Callers

nothing calls this directly

Implementers 1

_io.rscrates/vm/src/stdlib/_io.rs

Calls 13

check_initMethod · 0.80
flush_rewindMethod · 0.80
raw_tellMethod · 0.80
ErrClass · 0.50
to_pyobjectMethod · 0.45
flattenMethod · 0.45
lockMethod · 0.45
writableMethod · 0.45
to_ownedMethod · 0.45
call_methodMethod · 0.45
unwrapMethod · 0.45

Tested by

no test coverage detected