pub struct FunctionDef {
pub name: String,
pub args: ParameterList,
pub body: Vec<Statement>,
pub decorator_list: Vec<ExprType>,
pub returns: Option<Box<ExprType>>,
}Fields§
§name: String§args: ParameterList§body: Vec<Statement>§decorator_list: Vec<ExprType>§returns: Option<Box<ExprType>>The function’s return annotation (-> int), if present.
Implementations§
Source§impl FunctionDef
impl FunctionDef
Sourcepub fn resolved_return_type(&self) -> Option<TokenStream>
pub fn resolved_return_type(&self) -> Option<TokenStream>
The return type the generated Rust function actually carries, if any.
Inference from the body comes first (it reflects the type the body
actually produces — e.g. a string literal is a &’static str even
under a -> str annotation); an explicit annotation with a known
Rust mapping is the fallback for bodies inference can’t see through.
Both require the body to return on every path: a fall-through path
yields (), which no concrete annotation can type. -> None and
unmappable annotations yield None.
Tools generating call-through code (e.g. PyO3 wrappers) must use this same method so their signatures match the generated function.
Sourcepub fn ignored_return_annotation(&self) -> Option<String>
pub fn ignored_return_annotation(&self) -> Option<String>
The Python-source text of a return annotation the generated function
does not honor: the body can fall through (implicitly returning
None), so the generated function returns () no matter what the
annotation claims. This frequently marks a bug in the Python source
— the author declared a return type but not every path returns one —
so it must be surfaced, not silently reproduced.
Sourcepub fn lossy_conversion_notes(&self) -> Vec<String>
pub fn lossy_conversion_notes(&self) -> Vec<String>
Human-readable notes for every lossy conversion this function’s signature underwent. These become the #[deprecated] note on the generated function, and conversion tools report them to the user.
Sourcepub fn dropped_default_parameters(&self) -> Vec<String>
pub fn dropped_default_parameters(&self) -> Vec<String>
Names of parameters whose Python default values cannot be carried into the generated Rust signature (Rust has no default arguments). Used to attach a call-site warning to the generated function and to let tools report the loss during conversion.
Sourcepub fn inferred_return_type(&self) -> Option<TokenStream>
pub fn inferred_return_type(&self) -> Option<TokenStream>
Infer a return type when the function is guaranteed to return on every control-flow path AND every return value in the body maps to the same simple type — either directly (a constant or f-string) or via a local variable assigned a constant. Partial/conditional returns (which implicitly return None on the fall-through path), mixed types, and uninferable values all yield None so the function stays unannotated, as before.
Trait Implementations§
Source§impl Clone for FunctionDef
impl Clone for FunctionDef
Source§fn clone(&self) -> FunctionDef
fn clone(&self) -> FunctionDef
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more