MCPcopy Create free account
hub / github.com/dgrunwald/rust-cpython / str_from_ptr

Method str_from_ptr

src/objects/module.rs:57–70  ·  view source on GitHub ↗
(&'a self, py: Python, ptr: *const c_char)

Source from the content-addressed store, hash-verified

55 }
56
57 unsafe fn str_from_ptr<'a>(&'a self, py: Python, ptr: *const c_char) -> PyResult<&'a str> {
58 if ptr.is_null() {
59 Err(PyErr::fetch(py))
60 } else {
61 let slice = CStr::from_ptr(ptr).to_bytes();
62 match std::str::from_utf8(slice) {
63 Ok(s) => Ok(s),
64 Err(e) => Err(PyErr::from_instance(
65 py,
66 exc::UnicodeDecodeError::new_utf8(py, slice, e)?,
67 )),
68 }
69 }
70 }
71
72 /// Gets the module name.
73 ///

Callers 2

nameMethod · 0.80
filenameMethod · 0.80

Calls

no outgoing calls

Tested by

no test coverage detected