pub struct PyContext {
    pub variables: PyVar,
}
Expand description

Represents a context for executing Python code.

Fields§

§variables: PyVar

Stores Python variables and their values.

Implementations§

source§

impl PyContext

source

pub fn new() -> PyContext

Constructs a new empty PyContext.

source

pub fn run(&self, input: &str)

Executes Python code provided as input.

Arguments
  • input - A string containing the Python code to execute.
source

pub fn run_file(&self, file: &str) -> Result<(), PyErr>

Executes Python code from a file specified by file.

Arguments
  • file - The path to the file containing Python code.
Errors

Returns an error if there is an issue reading the file or executing Python code.

source

pub fn get<T: FromStr>(&self, input: &str) -> Result<T, <T as FromStr>::Err>

Retrieves the value of a Python variable identified by input.

Arguments
  • input - The name of the Python variable to retrieve.
Errors

Returns an error if parsing of the variable value fails.

Trait Implementations§

source§

impl Default for PyContext

source§

fn default() -> Self

Constructs a new PyContext with default values.

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

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

source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
source§

impl<T> Ungil for Twhere T: Send,