Struct cpython::Python[][src]

pub struct Python<'p>(_);
Expand description

Marker type that indicates that the GIL is currently held.

The ‘Python’ struct is a zero-size marker struct that is required for most Python operations. This is used to indicate that the operation accesses/modifies the Python interpreter state, and thus can only be called if the Python interpreter is initialized and the Python global interpreter lock (GIL) is acquired. The lifetime 'p represents the lifetime of the Python interpreter.

You can imagine the GIL to be a giant Mutex<PythonInterpreterState>. The type Python<'p> then acts like a reference &'p PythonInterpreterState.

Implementations

Retrieve Python instance under the assumption that the GIL is already acquired at this point, and stays acquired for the lifetime 'p.

Because the output lifetime 'p is not connected to any input parameter, care must be taken that the compiler infers an appropriate lifetime for 'p when calling this function.

Acquires the global interpreter lock, which allows access to the Python runtime.

If the Python runtime is not already initialized, this function will initialize it. See prepare_freethreaded_python() for details.

Temporarily releases the GIL, thus allowing other Python threads to run.

Evaluates a Python expression in the given context and returns the result.

If globals is None, it defaults to Python module __main__. If locals is None, it defaults to the value of globals.

Executes one or more Python statements in the given context.

If globals is None, it defaults to Python module __main__. If locals is None, it defaults to the value of globals.

Gets the Python builtin value None.

Gets the Python builtin value True.

Gets the Python builtin value False.

Gets the Python builtin value NotImplemented.

Gets the Python type object for type T.

Import the Python module with the specified name.

Trait Implementations

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

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

Performs the conversion.

Performs the conversion.

The resulting type after obtaining ownership.

Creates owned data from borrowed data, usually by cloning. Read more

🔬 This is a nightly-only experimental API. (toowned_clone_into)

recently added

Uses borrowed data to replace owned data, usually by cloning. Read more

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.