Struct BytecodeCompiler

Source
pub struct BytecodeCompiler { /* private fields */ }
Expand description

An entity to perform Python bytecode compilation.

Implementations§

Source§

impl BytecodeCompiler

Source

pub fn new( python: &Path, script_dir: impl AsRef<Path>, ) -> Result<BytecodeCompiler>

Create a bytecode compiler using a Python executable.

A Python process will be started and it will start executing a Python source file embedded in this crate. That process interacts with this object via a pipe, which is used to send bytecode compilation requests and receive the compiled bytecode. The process is terminated when this object is dropped.

A Python script is written to the directory passed. This should ideally be a temporary directory. The file name is deterministic, so it isn’t safe for multiple callers to simultaneously pass the same directory. The temporary file is deleted before this function returns. Ideally this function would use a proper temporary file internally. The reason this isn’t done is to avoid an extra crate dependency.

Trait Implementations§

Source§

impl Debug for BytecodeCompiler

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Drop for BytecodeCompiler

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

impl PythonBytecodeCompiler for BytecodeCompiler

Source§

fn get_magic_number(&self) -> u32

Obtain the magic number to use in the bytecode header.
Source§

fn compile( self: &mut BytecodeCompiler, source: &[u8], filename: &str, optimize: BytecodeOptimizationLevel, output_mode: CompileMode, ) -> Result<Vec<u8>>

Compile Python source into bytecode with an optimization level.

Auto Trait Implementations§

Blanket Implementations§

Source§

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

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

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

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where 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 T
where 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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

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

Source§

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 T
where U: TryFrom<T>,

Source§

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.