Module rustypy::pytypes::pystring [] [src]

An analog of a Python String.

To return to Python you must use as_ptr method and return a raw pointer. You can create them using the from trait method, from both &str and String.

Safety

When passed from Python you can convert from PyString to an owned string (from_ptr_into_string method) or to a &str slice (to_str method), or to a PyString reference (from_ptr method). Those operations are unsafe as they require dereferencing a raw pointer.

Examples

use rustypy::PyString;
let pystr = PyString::from("Hello world!");

// prepare to return to Python:
let ptr = pystr.as_ptr();
// convert from raw pointer to an owned String
let rust_string = unsafe { PyString::from_ptr_to_string(ptr) };

Structs

PyString

An analog of a Python string.