Skip to main content

PythonOptions

Struct PythonOptions 

Source
pub struct PythonOptions {
    pub python_namespace: String,
    pub python_path: Vec<String>,
    pub imports: BTreeMap<String, HashSet<String>>,
    pub stdpython: String,
    pub with_std_python: bool,
    pub allow_unsafe: bool,
    pub async_runtime: AsyncRuntime,
    pub lossy_warnings: bool,
    pub optional_names: Rc<HashSet<String>>,
    pub clone_str_attribute_returns: bool,
    pub local_types: Rc<HashMap<String, String>>,
    pub no_std: bool,
}
Expand description

The global context for Python compilation.

Fields§

§python_namespace: String

Python imports are mapped into a given namespace that can be changed.

§python_path: Vec<String>

The default path we will search for Python modules.

§imports: BTreeMap<String, HashSet<String>>

Collects all of the things we need to compile imports[module][asnames]

§stdpython: String§with_std_python: bool§allow_unsafe: bool§async_runtime: AsyncRuntime

The async runtime to use for async Python code

§lossy_warnings: bool

Emit #[deprecated] notes on generated items whose conversion was lossy (dropped parameter defaults, ignored return annotations, …). On by default: silent semantic divergence from the Python source is exactly what these warnings exist to surface. Tools may disable this to suppress the warnings at the user’s explicit request.

§optional_names: Rc<HashSet<String>>

Names in the CURRENT scope that hold an Option (assigned None on some path, or annotated Optional): non-None stores into them wrap in Some. Set per scope by the function/module generators.

§clone_str_attribute_returns: bool

Whether the CURRENT function’s return annotation is str: returning an attribute chain then clones the String field out of the shared receiver. Python strings are immutable, so the clone reproduces Python’s aliasing semantics exactly. Set per function.

§local_types: Rc<HashMap<String, String>>

Statically-known types of names in the CURRENT scope (parameter annotations and literal assignments), as canonical Python type names (“int”, “float”, “str”, “bool”). Set per function; consumed by isinstance(), which lowers to a constant.

§no_std: bool

Target stdpython’s no_std (alloc) tier. Python constructs that need the OS — print/input/open, imports of os/datetime/random/…, and __main__ entry points — fail loudly at conversion time instead of surfacing as resolution errors when the generated crate builds.

Implementations§

Source§

impl PythonOptions

Source

pub fn with_tokio() -> Self

Create PythonOptions with tokio runtime (default)

Source

pub fn with_async_std() -> Self

Create PythonOptions with async-std runtime

Source

pub fn with_smol() -> Self

Create PythonOptions with smol runtime

Source

pub fn with_custom_runtime( attribute: impl Into<String>, import: impl Into<String>, ) -> Self

Create PythonOptions with a custom async runtime

Source

pub fn set_async_runtime(&mut self, runtime: AsyncRuntime) -> &mut Self

Set the async runtime for these options

Trait Implementations§

Source§

impl Clone for PythonOptions

Source§

fn clone(&self) -> PythonOptions

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for PythonOptions

Source§

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

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

impl Default for PythonOptions

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> ErrorContext for T
where T: Debug,

Source§

fn with_context(&self, operation: &str) -> String

Generate a standardized error message with context.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

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

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more