pub struct GILProtected<T> { /* private fields */ }
Expand description

Mutex-like wrapper object for data that is protected by the Python GIL.

Example

use std::cell::Cell;
use cpython::{Python, GILProtected};

let data = GILProtected::new(Cell::new(0));

{
    let gil_guard = Python::acquire_gil();
    let cell = data.get(gil_guard.python());
    cell.set(cell.get() + 1);
}

Implementations

Creates a new instance of GILProtected.

Returns a shared reference to the data stored in the GILProtected.

Requires a Python instance as proof that the GIL is acquired.

Consumes the GILProtected, returning the wrapped value.

Trait Implementations

Because GILProtected ensures that the contained data is only accessed while the GIL is acquired, it can implement Sync even if the contained data does not.

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.