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

Method fromunicode

crates/stdlib/src/array.rs:819–835  ·  view source on GitHub ↗
(zelf: &Py<Self>, obj: PyObjectRef, vm: &VirtualMachine)

Source from the content-addressed store, hash-verified

817
818 #[pymethod]
819 fn fromunicode(zelf: &Py<Self>, obj: PyObjectRef, vm: &VirtualMachine) -> PyResult<()> {
820 let wtf8: &Wtf8 = obj.try_to_value(vm).map_err(|_| {
821 vm.new_type_error(format!(
822 "fromunicode() argument must be str, not {}",
823 obj.class().name()
824 ))
825 })?;
826 if zelf.read().typecode() != 'u' {
827 return Err(
828 vm.new_value_error("fromunicode() may only be called on unicode type arrays")
829 );
830 }
831 let mut w = zelf.try_resizable(vm)?;
832 let bytes = Self::_unicode_to_wchar_bytes(wtf8, w.itemsize());
833 w.frombytes_move(bytes);
834 Ok(())
835 }
836
837 #[pymethod]
838 fn tounicode(&self, vm: &VirtualMachine) -> PyResult<Wtf8Buf> {

Callers 1

test_unicodeMethod · 0.80

Calls 6

try_to_valueMethod · 0.80
typecodeMethod · 0.80
try_resizableMethod · 0.80
ErrClass · 0.50
readMethod · 0.45
itemsizeMethod · 0.45

Tested by 1

test_unicodeMethod · 0.64