• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

facet-rs / facet / 14570645698

21 Apr 2025 08:57AM UTC coverage: 46.087% (-1.7%) from 47.789%
14570645698

push

github

Veykril
Implement `Facet` for (subset of) function pointers

42 of 551 new or added lines in 6 files covered. (7.62%)

1 existing line in 1 file now uncovered.

5848 of 12689 relevant lines covered (46.09%)

55.67 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

11.43
/facet-core/src/types/function.rs
1
use crate::Shape;
2

3
/// Common fields for function pointer types
4
#[derive(Clone, Copy, PartialEq, Eq, Hash, Debug)]
5
#[repr(C)]
6
#[non_exhaustive]
7
pub struct FunctionPointerDef {
8
    /// The calling abi of the function pointer
9
    pub abi: FunctionAbi,
10

11
    /// All parameter types, in declaration order
12
    pub parameters: &'static [fn() -> &'static Shape],
13

14
    /// The return type
15
    pub return_type: fn() -> &'static Shape,
16
}
17

18
/// The calling ABI of a function pointer
19
#[derive(Clone, Copy, PartialEq, Eq, Hash, Debug, Default)]
20
#[repr(C)]
21
#[non_exhaustive]
22
pub enum FunctionAbi {
23
    /// C ABI
24
    C,
25

26
    /// Rust ABI
27
    #[default]
28
    Rust,
29

30
    /// An unknown ABI
31
    Unknown,
32
}
33
impl FunctionAbi {
34
    /// Returns the string in `extern "abi-string"` if not [`FunctionAbi::Unknown`].
35
    pub fn as_abi_str(&self) -> Option<&str> {
2✔
36
        match self {
2✔
37
            FunctionAbi::C => Some("C"),
2✔
NEW
38
            FunctionAbi::Rust => Some("Rust"),
×
NEW
39
            FunctionAbi::Unknown => None,
×
40
        }
41
    }
2✔
42
}
43

44
impl FunctionPointerDef {
45
    /// Returns a builder for FunctionPointerDef
NEW
46
    pub const fn builder() -> FunctionPointerDefBuilder {
×
NEW
47
        FunctionPointerDefBuilder::new()
×
NEW
48
    }
×
49
}
50

51
/// Builder for FunctionPointerDef
52
pub struct FunctionPointerDefBuilder {
53
    abi: Option<FunctionAbi>,
54
    parameters: &'static [fn() -> &'static Shape],
55
    return_type: Option<fn() -> &'static Shape>,
56
}
57

58
impl FunctionPointerDefBuilder {
59
    /// Creates a new FunctionPointerDefBuilder
60
    #[allow(clippy::new_without_default)]
NEW
61
    pub const fn new() -> Self {
×
NEW
62
        Self {
×
NEW
63
            parameters: &[],
×
NEW
64
            abi: None,
×
NEW
65
            return_type: None,
×
NEW
66
        }
×
NEW
67
    }
×
68

69
    /// Sets the abi for the FunctionPointerDef
NEW
70
    pub const fn abi(mut self, abi: FunctionAbi) -> Self {
×
NEW
71
        self.abi = Some(abi);
×
NEW
72
        self
×
NEW
73
    }
×
74

75
    /// Sets the parameters for the FunctionPointerDef
NEW
76
    pub const fn parameter_types(mut self, parameters: &'static [fn() -> &'static Shape]) -> Self {
×
NEW
77
        self.parameters = parameters;
×
NEW
78
        self
×
NEW
79
    }
×
80

81
    /// Sets the return type for the FunctionPointerDef
NEW
82
    pub const fn return_type(mut self, ty: fn() -> &'static Shape) -> Self {
×
NEW
83
        self.return_type = Some(ty);
×
NEW
84
        self
×
NEW
85
    }
×
86

87
    /// Builds the FunctionPointerDef
NEW
88
    pub const fn build(self) -> FunctionPointerDef {
×
NEW
89
        FunctionPointerDef {
×
NEW
90
            parameters: self.parameters,
×
NEW
91
            return_type: self.return_type.unwrap(),
×
NEW
92
            abi: self.abi.unwrap(),
×
NEW
93
        }
×
NEW
94
    }
×
95
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc