facet_core/types/
scalar.rs

1use crate::PtrConst;
2
3/// Definition for scalar types
4#[derive(Clone, Copy, PartialEq, Eq, Hash, Debug)]
5#[repr(C)]
6#[non_exhaustive]
7pub struct ScalarDef {
8    /// Affinity of the scalar — is spiritually more like a number, more like a string, something else?
9    /// example: an IPv4 address is both. good luck.
10    pub affinity: ScalarAffinity,
11}
12
13impl ScalarDef {
14    /// Returns a builder for ScalarDef
15    pub const fn builder() -> ScalarDefBuilder {
16        ScalarDefBuilder::new()
17    }
18}
19
20/// Builder for ScalarDef
21#[derive(Default)]
22pub struct ScalarDefBuilder {
23    affinity: Option<ScalarAffinity>,
24}
25
26impl ScalarDefBuilder {
27    /// Creates a new ScalarDefBuilder
28    #[allow(clippy::new_without_default)]
29    pub const fn new() -> Self {
30        Self { affinity: None }
31    }
32
33    /// Sets the affinity for the ScalarDef
34    pub const fn affinity(mut self, affinity: ScalarAffinity) -> Self {
35        self.affinity = Some(affinity);
36        self
37    }
38
39    /// Builds the ScalarDef
40    pub const fn build(self) -> ScalarDef {
41        ScalarDef {
42            affinity: self.affinity.unwrap(),
43        }
44    }
45}
46
47/// Scalar affinity: what a scalar spiritually is: a number, a string, a bool, something else
48/// entirely?
49#[derive(Clone, Copy, PartialEq, Eq, Hash, Debug)]
50#[repr(C)]
51#[non_exhaustive]
52pub enum ScalarAffinity {
53    /// Number-like scalar affinity
54    Number(NumberAffinity),
55    /// Complex-Number-like scalar affinity
56    ComplexNumber(ComplexNumberAffinity),
57    /// String-like scalar affinity
58    String(StringAffinity),
59    /// Boolean scalar affinity
60    Boolean(BoolAffinity),
61    /// Empty scalar affinity
62    Empty(EmptyAffinity),
63    /// Socket address scalar affinity
64    SocketAddr(SocketAddrAffinity),
65    /// Ip Address scalar affinity
66    IpAddr(IpAddrAffinity),
67    /// UUID or UUID-like identifier, containing 16 bytes of information
68    UUID(UuidAffinity),
69    /// Timestamp or Datetime-like scalar affinity
70    Time(TimeAffinity),
71    /// Something you're not supposed to look inside of
72    Opaque(OpaqueAffinity),
73    /// Other scalar affinity
74    Other(OtherAffinity),
75    /// Character scalar affinity
76    Char(CharAffinity),
77    /// Path scalar affinity (file/disk paths)
78    Path(PathAffinity),
79}
80
81impl ScalarAffinity {
82    /// Returns a NumberAffinityBuilder
83    pub const fn number() -> NumberAffinityBuilder {
84        NumberAffinityBuilder::new()
85    }
86
87    /// Returns a ComplexNumberAffinityBuilder
88    pub const fn complex_number() -> ComplexNumberAffinityBuilder {
89        ComplexNumberAffinityBuilder::new()
90    }
91
92    /// Returns a StringAffinityBuilder
93    pub const fn string() -> StringAffinityBuilder {
94        StringAffinityBuilder::new()
95    }
96
97    /// Returns a BoolAffinityBuilder
98    pub const fn boolean() -> BoolAffinityBuilder {
99        BoolAffinityBuilder::new()
100    }
101
102    /// Returns an EmptyAffinityBuilder
103    pub const fn empty() -> EmptyAffinityBuilder {
104        EmptyAffinityBuilder::new()
105    }
106
107    /// Returns a SocketAddrAffinityBuilder
108    pub const fn socket_addr() -> SocketAddrAffinityBuilder {
109        SocketAddrAffinityBuilder::new()
110    }
111
112    /// Returns an IpAddrAffinityBuilder
113    pub const fn ip_addr() -> IpAddrAffinityBuilder {
114        IpAddrAffinityBuilder::new()
115    }
116
117    /// Returns an UuidAffinityBuilder
118    pub const fn uuid() -> UuidAffinityBuilder {
119        UuidAffinityBuilder::new()
120    }
121
122    /// Returns an TimeAffinityBuilder
123    pub const fn time() -> TimeAffinityBuilder {
124        TimeAffinityBuilder::new()
125    }
126
127    /// Returns an OpaqueAffinityBuilder
128    pub const fn opaque() -> OpaqueAffinityBuilder {
129        OpaqueAffinityBuilder::new()
130    }
131
132    /// Returns an OtherAffinityBuilder
133    pub const fn other() -> OtherAffinityBuilder {
134        OtherAffinityBuilder::new()
135    }
136
137    /// Returns a CharAffinityBuilder
138    pub const fn char() -> CharAffinityBuilder {
139        CharAffinityBuilder::new()
140    }
141
142    /// Returns a PathAffinityBuilder
143    pub const fn path() -> PathAffinityBuilder {
144        PathAffinityBuilder::new()
145    }
146}
147
148//////////////////////////////////////////////////////////////////////////////////////////
149// Affinities
150//////////////////////////////////////////////////////////////////////////////////////////
151
152/// Definition for number-like scalar affinities
153#[derive(Clone, Copy, PartialEq, Eq, Hash, Debug)]
154#[repr(C)]
155#[non_exhaustive]
156pub struct NumberAffinity {
157    /// Bit representation of numbers
158    pub bits: NumberBits,
159
160    /// Minimum representable value
161    pub min: PtrConst<'static>,
162
163    /// Maximum representable value
164    pub max: PtrConst<'static>,
165
166    /// Positive infinity representable value
167    pub positive_infinity: Option<PtrConst<'static>>,
168
169    /// Negative infinity representable value
170    pub negative_infinity: Option<PtrConst<'static>>,
171
172    /// Example NaN (Not a Number) value.
173    /// Why sample? Because there are many NaN values, and we need to provide a representative one.
174    pub nan_sample: Option<PtrConst<'static>>,
175
176    /// Positive zero representation. If there's only one zero, only set this one.
177    pub positive_zero: Option<PtrConst<'static>>,
178
179    /// Negative zero representation
180    pub negative_zero: Option<PtrConst<'static>>,
181
182    /// "Machine epsilon" (<https://en.wikipedia.org/wiki/Machine_epsilon>), AKA relative
183    /// approximation error, if relevant
184    pub epsilon: Option<PtrConst<'static>>,
185}
186
187/// Represents whether a numeric type is signed or unsigned
188#[derive(Clone, Copy, PartialEq, Eq, Hash, Debug)]
189#[repr(C)]
190pub enum Signedness {
191    /// Signed numeric type
192    Signed,
193    /// Unsigned numeric type
194    Unsigned,
195}
196
197/// Bit representation of numbers
198#[derive(Clone, Copy, PartialEq, Eq, Hash, Debug)]
199#[repr(C)]
200#[non_exhaustive]
201pub enum NumberBits {
202    /// Integer number limits with specified number of bits
203    Integer {
204        /// Number of bits in the integer representation
205        bits: usize,
206        /// Whether the integer is signed or unsigned
207        sign: Signedness,
208    },
209    /// Floating-point number limits with specified sign, exponent and mantissa bits
210    Float {
211        /// Number of bits used for the sign (typically 1)
212        sign_bits: usize,
213        /// Number of bits used for the exponent
214        exponent_bits: usize,
215        /// Number of bits used for the mantissa (fraction part)
216        mantissa_bits: usize,
217        /// Floating-point numbers that are large enough to not be "in subnormal mode"
218        /// have their mantissa represent a number between 1 (included) and 2 (excluded)
219        /// This indicates whether the representation of the mantissa has the significant digit
220        /// (always 1) explicitly written out
221        has_explicit_first_mantissa_bit: bool,
222    },
223    /// Fixed-point number limits with specified integer and fractional bits
224    Fixed {
225        /// Number of bits used for the sign (typically 0 or 1)
226        sign_bits: usize,
227        /// Number of bits used for the integer part
228        integer_bits: usize,
229        /// Number of bits used for the fractional part
230        fraction_bits: usize,
231    },
232    /// Decimal number limits with unsized-integer, scaling, and sign bits
233    Decimal {
234        /// Number of bits used for the sign (typically 0 or 1)
235        sign_bits: usize,
236        /// Number of bits used for the integer part
237        integer_bits: usize,
238        /// Number of bits used for the scale part
239        scale_bits: usize,
240    },
241}
242
243impl NumberAffinity {
244    /// Returns a builder for NumberAffinity
245    pub const fn builder() -> NumberAffinityBuilder {
246        NumberAffinityBuilder::new()
247    }
248}
249
250/// Builder for NumberAffinity
251#[repr(C)]
252pub struct NumberAffinityBuilder {
253    limits: Option<NumberBits>,
254    min: Option<PtrConst<'static>>,
255    max: Option<PtrConst<'static>>,
256    positive_infinity: Option<PtrConst<'static>>,
257    negative_infinity: Option<PtrConst<'static>>,
258    nan_sample: Option<PtrConst<'static>>,
259    positive_zero: Option<PtrConst<'static>>,
260    negative_zero: Option<PtrConst<'static>>,
261    epsilon: Option<PtrConst<'static>>,
262}
263
264impl NumberAffinityBuilder {
265    /// Creates a new NumberAffinityBuilder
266    #[allow(clippy::new_without_default)]
267    pub const fn new() -> Self {
268        Self {
269            limits: None,
270            min: None,
271            max: None,
272            positive_infinity: None,
273            negative_infinity: None,
274            nan_sample: None,
275            positive_zero: None,
276            negative_zero: None,
277            epsilon: None,
278        }
279    }
280
281    /// Sets the number limits as integer with specified bits and sign
282    pub const fn integer(mut self, bits: usize, sign: Signedness) -> Self {
283        self.limits = Some(NumberBits::Integer { bits, sign });
284        self
285    }
286
287    /// Sets the number limits as signed integer with specified bits
288    pub const fn signed_integer(self, bits: usize) -> Self {
289        self.integer(bits, Signedness::Signed)
290    }
291
292    /// Sets the number limits as unsigned integer with specified bits
293    pub const fn unsigned_integer(self, bits: usize) -> Self {
294        self.integer(bits, Signedness::Unsigned)
295    }
296
297    /// Sets the number limits as float with specified bits
298    pub const fn float(
299        mut self,
300        sign_bits: usize,
301        exponent_bits: usize,
302        mantissa_bits: usize,
303        has_explicit_first_mantissa_bit: bool,
304    ) -> Self {
305        self.limits = Some(NumberBits::Float {
306            sign_bits,
307            exponent_bits,
308            mantissa_bits,
309            has_explicit_first_mantissa_bit,
310        });
311        self
312    }
313
314    /// Sets the number limits as fixed-point with specified bits
315    pub const fn fixed(
316        mut self,
317        sign_bits: usize,
318        integer_bits: usize,
319        fraction_bits: usize,
320    ) -> Self {
321        self.limits = Some(NumberBits::Fixed {
322            sign_bits,
323            integer_bits,
324            fraction_bits,
325        });
326        self
327    }
328
329    /// Sets the min value for the NumberAffinity
330    pub const fn min(mut self, min: PtrConst<'static>) -> Self {
331        self.min = Some(min);
332        self
333    }
334
335    /// Sets the max value for the NumberAffinity
336    pub const fn max(mut self, max: PtrConst<'static>) -> Self {
337        self.max = Some(max);
338        self
339    }
340
341    /// Sets the positive infinity value for the NumberAffinity
342    pub const fn positive_infinity(mut self, value: PtrConst<'static>) -> Self {
343        self.positive_infinity = Some(value);
344        self
345    }
346
347    /// Sets the negative infinity value for the NumberAffinity
348    pub const fn negative_infinity(mut self, value: PtrConst<'static>) -> Self {
349        self.negative_infinity = Some(value);
350        self
351    }
352
353    /// Sets the NaN sample value for the NumberAffinity
354    pub const fn nan_sample(mut self, value: PtrConst<'static>) -> Self {
355        self.nan_sample = Some(value);
356        self
357    }
358
359    /// Sets the positive zero value for the NumberAffinity
360    pub const fn positive_zero(mut self, value: PtrConst<'static>) -> Self {
361        self.positive_zero = Some(value);
362        self
363    }
364
365    /// Sets the negative zero value for the NumberAffinity
366    pub const fn negative_zero(mut self, value: PtrConst<'static>) -> Self {
367        self.negative_zero = Some(value);
368        self
369    }
370
371    /// Sets the relative uncertainty for the NumberAffinity
372    pub const fn epsilon(mut self, value: PtrConst<'static>) -> Self {
373        self.epsilon = Some(value);
374        self
375    }
376
377    /// Builds the ScalarAffinity
378    pub const fn build(self) -> ScalarAffinity {
379        ScalarAffinity::Number(NumberAffinity {
380            bits: self.limits.unwrap(),
381            min: self.min.unwrap(),
382            max: self.max.unwrap(),
383            positive_infinity: self.positive_infinity,
384            negative_infinity: self.negative_infinity,
385            nan_sample: self.nan_sample,
386            positive_zero: self.positive_zero,
387            negative_zero: self.negative_zero,
388            epsilon: self.epsilon,
389        })
390    }
391}
392
393/// Definition for string-like scalar affinities
394#[derive(Clone, Copy, PartialEq, Eq, Hash, Debug)]
395#[repr(C)]
396#[non_exhaustive]
397pub struct ComplexNumberAffinity {
398    /// hiding the actual enum in a non-pub element
399    inner: ComplexNumberAffinityInner,
400}
401
402#[derive(Clone, Copy, PartialEq, Eq, Hash, Debug)]
403#[repr(C)]
404#[non_exhaustive]
405enum ComplexNumberAffinityInner {
406    /// represented as a+ib
407    Cartesian {
408        /// the underlying number affinity for both components
409        /// (assuming they are the same seems reasonable)
410        component: NumberAffinity,
411    },
412    /// represented as a*exp(ib)
413    Polar {
414        /// the number affinity for the absolute value
415        absolute: NumberAffinity,
416        /// the number affinity for the ...angle? bearing?
417        bearing: NumberAffinity,
418    },
419}
420
421impl ComplexNumberAffinity {
422    /// Returns a builder for ComplexNumberAffinity
423    pub const fn builder() -> ComplexNumberAffinityBuilder {
424        ComplexNumberAffinityBuilder::new()
425    }
426}
427
428/// Builder for ComplexNumberAffinity
429#[repr(C)]
430pub struct ComplexNumberAffinityBuilder {
431    inner: ComplexNumberAffinityBuilderInner,
432}
433
434#[repr(C)]
435enum ComplexNumberAffinityBuilderInner {
436    Undefined,
437    Cartesian {
438        // note: this could have been a NumberAffinityBuilder,
439        // but we want to be able to set this up from existing Number types
440        component: NumberAffinity,
441    },
442    Polar {
443        absolute: NumberAffinity,
444        bearing: NumberAffinity,
445    },
446}
447
448impl ComplexNumberAffinityBuilder {
449    /// Creates a new ComplexNumberAffinityBuilder
450    #[allow(clippy::new_without_default)]
451    pub const fn new() -> Self {
452        Self {
453            inner: ComplexNumberAffinityBuilderInner::Undefined,
454        }
455    }
456
457    /// sets the coordinates system to be cartesian
458    pub const fn cartesian(self, component: NumberAffinity) -> Self {
459        Self {
460            inner: ComplexNumberAffinityBuilderInner::Cartesian { component },
461        }
462    }
463
464    /// sets the coordinates system to be polar
465    pub const fn polar(self, absolute: NumberAffinity, bearing: NumberAffinity) -> Self {
466        Self {
467            inner: ComplexNumberAffinityBuilderInner::Polar { absolute, bearing },
468        }
469    }
470
471    /// Builds the ScalarAffinity
472    pub const fn build(self) -> ScalarAffinity {
473        use ComplexNumberAffinityBuilderInner as Inner;
474        use ComplexNumberAffinityInner as AffInner;
475        let inner = match self.inner {
476            Inner::Undefined => panic!(),
477            Inner::Cartesian { component } => AffInner::Cartesian { component },
478            Inner::Polar { absolute, bearing } => AffInner::Polar { absolute, bearing },
479        };
480        ScalarAffinity::ComplexNumber(ComplexNumberAffinity { inner })
481    }
482}
483
484/// Definition for string-like scalar affinities
485#[derive(Clone, Copy, PartialEq, Eq, Hash, Debug)]
486#[repr(C)]
487#[non_exhaustive]
488pub struct StringAffinity {
489    /// Maximum inline length
490    pub max_inline_length: Option<usize>,
491}
492
493impl StringAffinity {
494    /// Returns a builder for StringAffinity
495    pub const fn builder() -> StringAffinityBuilder {
496        StringAffinityBuilder::new()
497    }
498}
499
500/// Builder for StringAffinity
501#[repr(C)]
502pub struct StringAffinityBuilder {
503    max_inline_length: Option<usize>,
504}
505
506impl StringAffinityBuilder {
507    /// Creates a new StringAffinityBuilder
508    #[allow(clippy::new_without_default)]
509    pub const fn new() -> Self {
510        Self {
511            max_inline_length: None,
512        }
513    }
514
515    /// Sets the max_inline_length for the StringAffinity
516    pub const fn max_inline_length(mut self, max_inline_length: usize) -> Self {
517        self.max_inline_length = Some(max_inline_length);
518        self
519    }
520
521    /// Builds the ScalarAffinity
522    pub const fn build(self) -> ScalarAffinity {
523        ScalarAffinity::String(StringAffinity {
524            max_inline_length: self.max_inline_length,
525        })
526    }
527}
528
529/// Definition for boolean scalar affinities
530#[derive(Clone, Copy, PartialEq, Eq, Hash, Debug)]
531#[repr(C)]
532#[non_exhaustive]
533pub struct BoolAffinity {}
534
535impl BoolAffinity {
536    /// Returns a builder for BoolAffinity
537    pub const fn builder() -> BoolAffinityBuilder {
538        BoolAffinityBuilder::new()
539    }
540}
541
542/// Builder for BoolAffinity
543#[repr(C)]
544pub struct BoolAffinityBuilder {}
545
546impl BoolAffinityBuilder {
547    /// Creates a new BoolAffinityBuilder
548    #[allow(clippy::new_without_default)]
549    pub const fn new() -> Self {
550        Self {}
551    }
552
553    /// Builds the ScalarAffinity
554    pub const fn build(self) -> ScalarAffinity {
555        ScalarAffinity::Boolean(BoolAffinity {})
556    }
557}
558
559/// Definition for empty scalar affinities
560#[derive(Clone, Copy, PartialEq, Eq, Hash, Debug)]
561#[repr(C)]
562#[non_exhaustive]
563pub struct EmptyAffinity {}
564
565impl EmptyAffinity {
566    /// Returns a builder for EmptyAffinity
567    pub const fn builder() -> EmptyAffinityBuilder {
568        EmptyAffinityBuilder::new()
569    }
570}
571
572/// Builder for EmptyAffinity
573#[repr(C)]
574pub struct EmptyAffinityBuilder {}
575
576impl EmptyAffinityBuilder {
577    /// Creates a new EmptyAffinityBuilder
578    #[allow(clippy::new_without_default)]
579    pub const fn new() -> Self {
580        Self {}
581    }
582
583    /// Builds the ScalarAffinity
584    pub const fn build(self) -> ScalarAffinity {
585        ScalarAffinity::Empty(EmptyAffinity {})
586    }
587}
588
589/// Definition for socket address scalar affinities
590#[derive(Clone, Copy, PartialEq, Eq, Hash, Debug)]
591#[repr(C)]
592#[non_exhaustive]
593pub struct SocketAddrAffinity {}
594
595impl SocketAddrAffinity {
596    /// Returns a builder for SocketAddrAffinity
597    pub const fn builder() -> SocketAddrAffinityBuilder {
598        SocketAddrAffinityBuilder::new()
599    }
600}
601
602/// Builder for SocketAddrAffinity
603#[repr(C)]
604pub struct SocketAddrAffinityBuilder {}
605
606impl SocketAddrAffinityBuilder {
607    /// Creates a new SocketAddrAffinityBuilder
608    #[allow(clippy::new_without_default)]
609    pub const fn new() -> Self {
610        Self {}
611    }
612
613    /// Builds the ScalarAffinity
614    pub const fn build(self) -> ScalarAffinity {
615        ScalarAffinity::SocketAddr(SocketAddrAffinity {})
616    }
617}
618
619/// Definition for IP address scalar affinities
620#[derive(Clone, Copy, PartialEq, Eq, Hash, Debug)]
621#[repr(C)]
622#[non_exhaustive]
623pub struct IpAddrAffinity {}
624
625impl IpAddrAffinity {
626    /// Returns a builder for IpAddrAffinity
627    pub const fn builder() -> IpAddrAffinityBuilder {
628        IpAddrAffinityBuilder::new()
629    }
630}
631
632/// Builder for IpAddrAffinity
633#[repr(C)]
634pub struct IpAddrAffinityBuilder {}
635
636impl IpAddrAffinityBuilder {
637    /// Creates a new IpAddrAffinityBuilder
638    #[allow(clippy::new_without_default)]
639    pub const fn new() -> Self {
640        Self {}
641    }
642
643    /// Builds the ScalarAffinity
644    pub const fn build(self) -> ScalarAffinity {
645        ScalarAffinity::IpAddr(IpAddrAffinity {})
646    }
647}
648
649/// Definition for UUID and UUID-like scalar affinities
650#[derive(Clone, Copy, PartialEq, Eq, Hash, Debug)]
651#[repr(C)]
652#[non_exhaustive]
653pub struct UuidAffinity {}
654
655impl UuidAffinity {
656    /// Returns a builder for UuidAffinity
657    pub const fn builder() -> UuidAffinityBuilder {
658        UuidAffinityBuilder::new()
659    }
660}
661
662/// Builder for UuidAffinity
663#[repr(C)]
664pub struct UuidAffinityBuilder {}
665
666impl UuidAffinityBuilder {
667    /// Creates a new UuidAffinityBuilder
668    #[allow(clippy::new_without_default)]
669    pub const fn new() -> Self {
670        Self {}
671    }
672
673    /// Builds the ScalarAffinity
674    pub const fn build(self) -> ScalarAffinity {
675        ScalarAffinity::UUID(UuidAffinity {})
676    }
677}
678
679/// Definition for Datetime/Timestamp scalar affinities
680#[derive(Clone, Copy, PartialEq, Eq, Hash, Debug)]
681#[repr(C)]
682#[non_exhaustive]
683pub struct TimeAffinity {
684    /// What serves as the reference, or "time zero"
685    /// for implementations that don't depend on an epoch in the traditionnal sense,
686    /// the first moment of year 1AD can be used
687    epoch: Option<PtrConst<'static>>,
688
689    /// The first moment representable
690    min: Option<PtrConst<'static>>,
691
692    /// The last moment representable
693    max: Option<PtrConst<'static>>,
694
695    /// The moment immediately after the epoch,
696    /// serving as a proxy for the smallest interval of time representable
697    /// (do use None if this interval depends on when in time the interval occurs, e.g. if someone
698    /// ever decides to store a timestamp on floating-point numbers)
699    granularity: Option<PtrConst<'static>>,
700
701    // TODO: the following solution leaves a LOT to desire.
702    // Some examples of things where this breaks:
703    // - leap years, day length in daylight savings, leap seconds
704    // - datetime objects that seamlessly switch from Julian to Gregorian calendar
705    //   - even worse if this transition is based on when a given country did, if there even is
706    //   something that does this
707    // - datetime objects that allow you to specify both individual Gregorian months and ISO 8601
708    //   weeks (but of course not at the same time, which is the whole difficulty)
709    /// For DateTime types made of interval elements some of which are optional
710    /// (for instance, letting you say "the 1st of March" without specifying year, hours, etc.)
711    /// Specify how long the interval elements (hour, minute, etc.) are
712    /// (all represented as moments separated from the epoch by said intervals)
713    /// the intervals MUST be of increasing length. (TODO bikeshedding for this line)
714    interval_elements: Option<&'static [PtrConst<'static>]>,
715
716    /// the minimum interval between timezone-local times which correspond to the same global time
717    /// (planet-local time? I mean duh that's what global means right?)
718    /// store a copy of the epoch for a lack of timezone support, and None for "it's more
719    /// complicated than that".
720    timezone_granularity: Option<PtrConst<'static>>,
721}
722
723impl TimeAffinity {
724    /// Returns a builder for TimeAffinity
725    pub const fn builder() -> TimeAffinityBuilder {
726        TimeAffinityBuilder::new()
727    }
728}
729
730/// Builder for UuidAffinity
731#[repr(C)]
732pub struct TimeAffinityBuilder {
733    epoch: Option<PtrConst<'static>>,
734    min: Option<PtrConst<'static>>,
735    max: Option<PtrConst<'static>>,
736    granularity: Option<PtrConst<'static>>,
737    interval_elements: Option<&'static [PtrConst<'static>]>,
738    timezone_granularity: Option<PtrConst<'static>>,
739}
740
741impl TimeAffinityBuilder {
742    /// Creates a new UuidAffinityBuilder
743    #[allow(clippy::new_without_default)]
744    pub const fn new() -> Self {
745        Self {
746            epoch: None,
747            min: None,
748            max: None,
749            granularity: None,
750            interval_elements: None,
751            timezone_granularity: None,
752        }
753    }
754
755    /// Sets the epoch for the TimeAffinity
756    pub const fn epoch(mut self, epoch: PtrConst<'static>) -> Self {
757        self.epoch = Some(epoch);
758        self
759    }
760
761    /// Sets the min value for the TimeAffinity
762    pub const fn min(mut self, min: PtrConst<'static>) -> Self {
763        self.min = Some(min);
764        self
765    }
766
767    /// Sets the max value for the TimeAffinity
768    pub const fn max(mut self, max: PtrConst<'static>) -> Self {
769        self.max = Some(max);
770        self
771    }
772
773    /// Sets the granularity for the TimeAffinity
774    pub const fn granularity(mut self, granularity: PtrConst<'static>) -> Self {
775        self.granularity = Some(granularity);
776        self
777    }
778
779    /// Sets the interval elements for the TimeAffinity
780    pub const fn interval_elements(
781        mut self,
782        interval_elements: &'static [PtrConst<'static>],
783    ) -> Self {
784        self.interval_elements = Some(interval_elements);
785        self
786    }
787
788    /// Sets the timezone granularity for the TimeAffinity
789    pub const fn timezone_granularity(mut self, timezone_granularity: PtrConst<'static>) -> Self {
790        self.timezone_granularity = Some(timezone_granularity);
791        self
792    }
793
794    /// Builds the ScalarAffinity
795    pub const fn build(self) -> ScalarAffinity {
796        ScalarAffinity::Time(TimeAffinity {
797            epoch: self.epoch,
798            min: self.min,
799            max: self.max,
800            granularity: self.granularity,
801            interval_elements: self.interval_elements,
802            timezone_granularity: self.timezone_granularity,
803        })
804    }
805}
806
807/// Definition for opaque scalar affinities
808#[derive(Clone, Copy, PartialEq, Eq, Hash, Debug)]
809#[repr(C)]
810#[non_exhaustive]
811pub struct OpaqueAffinity {}
812
813impl OpaqueAffinity {
814    /// Returns a builder for OpaqueAffinity
815    pub const fn builder() -> OpaqueAffinityBuilder {
816        OpaqueAffinityBuilder::new()
817    }
818}
819
820/// Builder for OpaqueAffinity
821#[repr(C)]
822pub struct OpaqueAffinityBuilder {}
823
824impl OpaqueAffinityBuilder {
825    /// Creates a new OpaqueAffinityBuilder
826    #[allow(clippy::new_without_default)]
827    pub const fn new() -> Self {
828        Self {}
829    }
830
831    /// Builds the ScalarAffinity
832    pub const fn build(self) -> ScalarAffinity {
833        ScalarAffinity::Opaque(OpaqueAffinity {})
834    }
835}
836
837/// Definition for other scalar affinities
838#[derive(Clone, Copy, PartialEq, Eq, Hash, Debug)]
839#[repr(C)]
840#[non_exhaustive]
841pub struct OtherAffinity {}
842
843impl OtherAffinity {
844    /// Returns a builder for OtherAffinity
845    pub const fn builder() -> OtherAffinityBuilder {
846        OtherAffinityBuilder::new()
847    }
848}
849
850/// Builder for OtherAffinity
851#[repr(C)]
852pub struct OtherAffinityBuilder {}
853
854impl OtherAffinityBuilder {
855    /// Creates a new OtherAffinityBuilder
856    #[allow(clippy::new_without_default)]
857    pub const fn new() -> Self {
858        Self {}
859    }
860
861    /// Builds the ScalarAffinity
862    pub const fn build(self) -> ScalarAffinity {
863        ScalarAffinity::Other(OtherAffinity {})
864    }
865}
866
867/// Definition for character scalar affinities
868#[derive(Clone, Copy, PartialEq, Eq, Hash, Debug)]
869#[repr(C)]
870#[non_exhaustive]
871pub struct CharAffinity {}
872
873impl CharAffinity {
874    /// Returns a builder for CharAffinity
875    pub const fn builder() -> CharAffinityBuilder {
876        CharAffinityBuilder::new()
877    }
878}
879
880/// Builder for CharAffinity
881#[repr(C)]
882pub struct CharAffinityBuilder {}
883
884impl CharAffinityBuilder {
885    /// Creates a new CharAffinityBuilder
886    #[allow(clippy::new_without_default)]
887    pub const fn new() -> Self {
888        Self {}
889    }
890
891    /// Builds the ScalarAffinity
892    pub const fn build(self) -> ScalarAffinity {
893        ScalarAffinity::Char(CharAffinity {})
894    }
895}
896
897/// Definition for path scalar affinities
898#[derive(Clone, Copy, PartialEq, Eq, Hash, Debug)]
899#[repr(C)]
900#[non_exhaustive]
901pub struct PathAffinity {}
902
903impl PathAffinity {
904    /// Returns a builder for PathAffinity
905    pub const fn builder() -> PathAffinityBuilder {
906        PathAffinityBuilder::new()
907    }
908}
909
910/// Builder for PathAffinity
911#[repr(C)]
912pub struct PathAffinityBuilder {}
913
914impl PathAffinityBuilder {
915    /// Creates a new PathAffinityBuilder
916    #[allow(clippy::new_without_default)]
917    pub const fn new() -> Self {
918        Self {}
919    }
920
921    /// Builds the ScalarAffinity
922    pub const fn build(self) -> ScalarAffinity {
923        ScalarAffinity::Path(PathAffinity {})
924    }
925}