facet_core/types/def/
function.rs1use crate::Shape;
2
3#[derive(Clone, Copy, Debug)]
5#[repr(C)]
6pub struct FunctionPointerDef {
7 pub abi: FunctionAbi,
9
10 pub parameters: &'static [&'static Shape],
12
13 pub return_type: &'static Shape,
15}
16
17#[derive(Clone, Copy, PartialEq, Eq, Hash, Debug, Default)]
19#[repr(C)]
20pub enum FunctionAbi {
21 C,
23
24 #[default]
26 Rust,
27
28 Unknown,
30}
31impl FunctionAbi {
32 pub fn as_abi_str(&self) -> Option<&str> {
34 match self {
35 FunctionAbi::C => Some("C"),
36 FunctionAbi::Rust => Some("Rust"),
37 FunctionAbi::Unknown => None,
38 }
39 }
40}
41
42impl FunctionPointerDef {
43 pub const fn builder() -> FunctionPointerDefBuilder {
45 FunctionPointerDefBuilder::new()
46 }
47}
48
49pub struct FunctionPointerDefBuilder {
51 abi: Option<FunctionAbi>,
52 parameters: &'static [&'static Shape],
53 return_type: Option<&'static Shape>,
54}
55
56impl FunctionPointerDefBuilder {
57 #[allow(clippy::new_without_default)]
59 pub const fn new() -> Self {
60 Self {
61 parameters: &[],
62 abi: None,
63 return_type: None,
64 }
65 }
66
67 pub const fn abi(mut self, abi: FunctionAbi) -> Self {
69 self.abi = Some(abi);
70 self
71 }
72
73 pub const fn parameter_types(mut self, parameters: &'static [&'static Shape]) -> Self {
75 self.parameters = parameters;
76 self
77 }
78
79 pub const fn return_type(mut self, ty: &'static Shape) -> Self {
81 self.return_type = Some(ty);
82 self
83 }
84
85 pub const fn build(self) -> FunctionPointerDef {
87 FunctionPointerDef {
88 parameters: self.parameters,
89 return_type: self.return_type.unwrap(),
90 abi: self.abi.unwrap(),
91 }
92 }
93}