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

Method try_as_utf8

crates/vm/src/builtins/str.rs:560–565  ·  view source on GitHub ↗
(&'a self, vm: &VirtualMachine)

Source from the content-addressed store, hash-verified

558 }
559
560 pub fn try_as_utf8<'a>(&'a self, vm: &VirtualMachine) -> PyResult<&'a PyUtf8Str> {
561 // Check if the string contains surrogates
562 self.ensure_valid_utf8(vm)?;
563 // If no surrogates, we can safely cast to PyStr
564 Ok(unsafe { &*(self as *const _ as *const PyUtf8Str) })
565 }
566}
567
568impl Py<PyStr> {

Callers 3

bind_parameterMethod · 0.80
result_from_objectMethod · 0.80
expandtabsMethod · 0.80

Calls 1

ensure_valid_utf8Method · 0.80

Tested by

no test coverage detected