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

Method downcast_borrow_from

src/objects/string.rs:76–91  ·  view source on GitHub ↗
(
        py: Python<'p>,
        obj: &'a PyObject,
    )

Source from the content-addressed store, hash-verified

74
75 #[inline]
76 fn downcast_borrow_from<'a, 'p>(
77 py: Python<'p>,
78 obj: &'a PyObject,
79 ) -> Result<&'a PyString, PythonObjectDowncastError<'p>> {
80 unsafe {
81 if is_base_string(obj) {
82 Ok(std::mem::transmute(obj))
83 } else {
84 Err(crate::python::PythonObjectDowncastError::new(
85 py,
86 "PyString",
87 obj.get_type(py),
88 ))
89 }
90 }
91 }
92}
93
94#[cfg(feature = "python27-sys")]

Callers

nothing calls this directly

Calls 2

is_base_stringFunction · 0.85
get_typeMethod · 0.45

Tested by

no test coverage detected