pub struct ForeignFunctionDef {Show 13 fields
pub language: String,
pub language_span: Span,
pub name: String,
pub name_span: Span,
pub doc_comment: Option<DocComment>,
pub type_params: Option<Vec<TypeParam>>,
pub params: Vec<FunctionParameter>,
pub return_type: Option<TypeAnnotation>,
pub body_text: String,
pub body_span: Span,
pub annotations: Vec<Annotation>,
pub is_async: bool,
pub native_abi: Option<NativeAbiBinding>,
}Expand description
A foreign function definition: fn <language> name(params) -> type { foreign_body }
The body is raw source text in the foreign language, not parsed as Shape.
Fields§
§language: StringThe language identifier (e.g., “python”, “julia”, “sql”)
language_span: Span§name: String§name_span: Span§doc_comment: Option<DocComment>§type_params: Option<Vec<TypeParam>>§params: Vec<FunctionParameter>§return_type: Option<TypeAnnotation>§body_text: StringThe raw dedented source text of the foreign function body.
body_span: SpanSpan of the body text in the original Shape source file.
annotations: Vec<Annotation>§is_async: bool§native_abi: Option<NativeAbiBinding>Native ABI metadata for extern "C" declarations.
When present, this foreign function is not compiled/invoked through a language runtime extension. The VM links and invokes it via the native C ABI path.
Implementations§
Source§impl ForeignFunctionDef
impl ForeignFunctionDef
Sourcepub fn returns_result(&self) -> bool
pub fn returns_result(&self) -> bool
Whether the declared return type is Result<T>.
Sourcepub fn is_native_abi(&self) -> bool
pub fn is_native_abi(&self) -> bool
Whether this function uses native ABI binding (e.g. extern "C").
Sourcepub fn validate_type_annotations(
&self,
dynamic_language: bool,
) -> Vec<(String, Span)>
pub fn validate_type_annotations( &self, dynamic_language: bool, ) -> Vec<(String, Span)>
Validate that all parameter and return types are explicitly annotated,
and that dynamic-language foreign functions declare Result<T> as their
return type.
Foreign function bodies are opaque — the type system cannot infer types
from them. This returns a list of (message, span) for each problem,
shared between the compiler and the LSP.
dynamic_language should be true for languages like Python, JS, Ruby
where every call can fail at runtime. Currently all foreign languages
are treated as dynamic (the ABI declares this via ErrorModel).
Trait Implementations§
Source§impl Clone for ForeignFunctionDef
impl Clone for ForeignFunctionDef
Source§fn clone(&self) -> ForeignFunctionDef
fn clone(&self) -> ForeignFunctionDef
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more