sql_fun_sqlast/sem/
cast.rs1#[derive(Debug, Clone)]
3pub struct CastDefinition {
4 cast_context: CastContext,
5}
6
7#[derive(Debug, Clone, Copy, PartialEq)]
9pub enum CastContext {
10 ImplicitPrefeerd,
12 Implicit,
14 Assignment,
16 Explicit,
18 NoConversion,
20}
21
22impl CastDefinition {
23 #[must_use]
25 pub fn new(cc: CastContext) -> Self {
26 Self { cast_context: cc }
27 }
28
29 #[must_use]
31 pub fn use_in_explicit(&self) -> bool {
32 self.cast_context.use_in_explicit()
33 }
34
35 #[must_use]
37 pub fn use_in_implicit(&self) -> bool {
38 self.cast_context.use_in_implicit()
39 }
40
41 #[must_use]
43 pub fn context(&self) -> CastContext {
44 self.cast_context
45 }
46
47 #[must_use]
49 pub fn is_implicit_preferred(&self) -> bool {
50 self.cast_context.is_implicit_preferred()
51 }
52
53 #[must_use]
55 pub fn is_no_coversion(&self) -> bool {
56 self.cast_context.is_no_coversion()
57 }
58}
59
60impl CastContext {
61 #[must_use]
63 pub fn use_in_explicit(&self) -> bool {
64 true
65 }
66
67 #[must_use]
69 pub fn use_in_implicit(&self) -> bool {
70 matches!(
71 self,
72 Self::Implicit | Self::ImplicitPrefeerd | Self::NoConversion
73 )
74 }
75
76 #[must_use]
78 pub fn use_in_assignment(&self) -> bool {
79 matches!(
80 self,
81 Self::Implicit | Self::ImplicitPrefeerd | Self::Assignment | Self::NoConversion
82 )
83 }
84
85 #[must_use]
87 pub fn overload_priority_score(&self) -> i32 {
88 match self {
89 Self::NoConversion => 10,
90 Self::ImplicitPrefeerd => 9,
91 Self::Implicit => 5,
92 _ => 0,
94 }
95 }
96
97 #[must_use]
99 pub fn is_implicit(&self) -> bool {
100 matches!(self, Self::Implicit | Self::ImplicitPrefeerd)
101 }
102
103 #[must_use]
105 pub fn is_implicit_preferred(&self) -> bool {
106 matches!(self, Self::ImplicitPrefeerd)
107 }
108
109 #[must_use]
111 pub fn is_no_coversion(&self) -> bool {
112 matches!(self, Self::NoConversion)
113 }
114}