[][src]Struct pycall::PythonProgram

pub struct PythonProgram { /* fields omitted */ }

An instance of code generation unit. It really is just a file with dedicated APIs to write Python into it. Most importantly: it manages indentation for you.

Methods

impl PythonProgram[src]

Important traits for PythonProgram
pub fn new() -> PythonProgram[src]

Creates a named temp file to store the generated python program

pub fn save_as<P: AsRef<Path>>(&self, path: P) -> Result<u64, Error>[src]

pub fn run(&self) -> Result<Output, Error>[src]

Runs the program using python3

pub fn background_run(self) -> JoinGuard<Result<Output, Error>>[src]

Spawns a thread to run the program using python3. The returned JoinGuard ensures that the program will be ran to completion.

pub fn flush(&mut self) -> &mut Self[src]

Ensures that the internal file has been flushed. Typically not necessary.

pub fn indent(&mut self, n: isize) -> &mut Self[src]

Moves the indentation level by n. However, I recommend using the dedicated functions when possible/

pub fn end_block(&mut self) -> &mut Self[src]

Removes one indentation level from the cursor. You should call this whenever you're done with a scope.

pub fn define_variable<T: AsPythonLitteral + ?Sized>(
    &mut self,
    name: &str,
    value: &T
) -> &mut Self
[src]

Writes a line assigning value formatted as a python literal to name

pub fn import(&mut self, dependency: &str) -> &mut Self[src]

Writes an import statement for your dependency

pub fn import_as(&mut self, dependency: &str, rename: &str) -> &mut Self[src]

Writes an import statement for your dependency as rename

pub fn write_line(&mut self, line: &str) -> &mut Self[src]

Writes whatever line you passed it, indented at the proper level.

pub fn if(&mut self, condition: &str) -> &mut Self[src]

Writes an if, using your condition as a test, and increments indentation.

pub fn elif(&mut self, condition: &str) -> &mut Self[src]

Decrements indentation, writes an elif, using your condition as a test, and increments indentation.

pub fn else(&mut self) -> &mut Self[src]

Decrements indentation, writes an else, using your condition as a test, and increments indentation.

pub fn for(&mut self, range: &str) -> &mut Self[src]

Writes "for range:", and increments indentation.

pub fn while(&mut self, condition: &str) -> &mut Self[src]

Writes a while, using your condition as a test, and increments indentation.

Trait Implementations

impl Display for PythonProgram[src]

impl MatPlotLib for PythonProgram[src]

impl Write for PythonProgram[src]

Auto Trait Implementations

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> ToString for T where
    T: Display + ?Sized
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.

impl<V, T> VZip<V> for T where
    V: MultiLane<T>,