Skip to main content

geam_core/plan/host/
function.rs

1use crate::host::HostParameter;
2use crate::plan::{FunctionTemplateId, FunctionTemplateSignature, FunctionType, TypeScheme};
3use ecow::EcoString;
4
5#[derive(Debug, Clone, PartialEq, Eq)]
6pub struct HostFunctionTemplate {
7    signature: FunctionTemplateSignature,
8    package: EcoString,
9    site: crate::plan::HostCallSite,
10    layout: Box<[HostParameter]>,
11    parameters: Box<[crate::host::HostTypeDescriptor]>,
12    return_: crate::host::HostTypeDescriptor,
13    custom_schemas: Box<[crate::host::HostCustomTypeSchema]>,
14    external_schemas: Box<[crate::host::HostExternalTypeSchema]>,
15    type_: FunctionType,
16}
17
18impl HostFunctionTemplate {
19    pub(crate) fn from_schema(
20        signature: FunctionTemplateSignature,
21        package: EcoString,
22        site: crate::plan::HostCallSite,
23        schema: crate::host::HostFunctionSchema,
24    ) -> Self {
25        Self {
26            signature,
27            package,
28            site,
29            layout: schema.layout().to_vec().into_boxed_slice(),
30            parameters: schema.parameters().to_vec().into_boxed_slice(),
31            return_: schema.return_type().clone(),
32            custom_schemas: schema.custom_schemas().to_vec().into_boxed_slice(),
33            external_schemas: schema.external_schemas().to_vec().into_boxed_slice(),
34            type_: schema.type_().clone(),
35        }
36    }
37
38    pub fn id(&self) -> FunctionTemplateId {
39        self.signature.id()
40    }
41
42    pub fn package(&self) -> &EcoString {
43        &self.package
44    }
45
46    pub fn module(&self) -> &EcoString {
47        self.site.module()
48    }
49
50    pub fn name(&self) -> &EcoString {
51        self.site.function()
52    }
53
54    pub(crate) fn site(&self) -> &crate::plan::HostCallSite {
55        &self.site
56    }
57
58    pub(crate) fn layout(&self) -> &[HostParameter] {
59        &self.layout
60    }
61
62    pub(crate) fn parameters(&self) -> &[crate::host::HostTypeDescriptor] {
63        &self.parameters
64    }
65
66    pub(crate) fn return_type(&self) -> &crate::host::HostTypeDescriptor {
67        &self.return_
68    }
69
70    pub(crate) fn custom_schemas(&self) -> &[crate::host::HostCustomTypeSchema] {
71        &self.custom_schemas
72    }
73
74    pub(crate) fn external_schemas(&self) -> &[crate::host::HostExternalTypeSchema] {
75        &self.external_schemas
76    }
77
78    pub fn scheme(&self) -> &TypeScheme {
79        self.signature.scheme()
80    }
81
82    pub fn type_(&self) -> &FunctionType {
83        &self.type_
84    }
85
86    pub(crate) fn signature(&self) -> &FunctionTemplateSignature {
87        &self.signature
88    }
89}