1use crate::PtrConst;
2
3#[derive(Clone, Copy, PartialEq, Eq, Hash, Debug)]
5#[repr(C)]
6#[non_exhaustive]
7pub struct ScalarDef {
8 pub affinity: ScalarAffinity,
11}
12
13impl ScalarDef {
14 pub const fn builder() -> ScalarDefBuilder {
16 ScalarDefBuilder::new()
17 }
18}
19
20#[derive(Default)]
22pub struct ScalarDefBuilder {
23 affinity: Option<ScalarAffinity>,
24}
25
26impl ScalarDefBuilder {
27 #[allow(clippy::new_without_default)]
29 pub const fn new() -> Self {
30 Self { affinity: None }
31 }
32
33 pub const fn affinity(mut self, affinity: ScalarAffinity) -> Self {
35 self.affinity = Some(affinity);
36 self
37 }
38
39 pub const fn build(self) -> ScalarDef {
41 ScalarDef {
42 affinity: self.affinity.unwrap(),
43 }
44 }
45}
46
47#[derive(Clone, Copy, PartialEq, Eq, Hash, Debug)]
50#[repr(C)]
51#[non_exhaustive]
52pub enum ScalarAffinity {
53 Number(NumberAffinity),
55 ComplexNumber(ComplexNumberAffinity),
57 String(StringAffinity),
59 Boolean(BoolAffinity),
61 Empty(EmptyAffinity),
63 SocketAddr(SocketAddrAffinity),
65 IpAddr(IpAddrAffinity),
67 UUID(UuidAffinity),
69 Time(TimeAffinity),
71 Opaque(OpaqueAffinity),
73 Other(OtherAffinity),
75 Char(CharAffinity),
77 Path(PathAffinity),
79}
80
81impl ScalarAffinity {
82 pub const fn number() -> NumberAffinityBuilder {
84 NumberAffinityBuilder::new()
85 }
86
87 pub const fn complex_number() -> ComplexNumberAffinityBuilder {
89 ComplexNumberAffinityBuilder::new()
90 }
91
92 pub const fn string() -> StringAffinityBuilder {
94 StringAffinityBuilder::new()
95 }
96
97 pub const fn boolean() -> BoolAffinityBuilder {
99 BoolAffinityBuilder::new()
100 }
101
102 pub const fn empty() -> EmptyAffinityBuilder {
104 EmptyAffinityBuilder::new()
105 }
106
107 pub const fn socket_addr() -> SocketAddrAffinityBuilder {
109 SocketAddrAffinityBuilder::new()
110 }
111
112 pub const fn ip_addr() -> IpAddrAffinityBuilder {
114 IpAddrAffinityBuilder::new()
115 }
116
117 pub const fn uuid() -> UuidAffinityBuilder {
119 UuidAffinityBuilder::new()
120 }
121
122 pub const fn time() -> TimeAffinityBuilder {
124 TimeAffinityBuilder::new()
125 }
126
127 pub const fn opaque() -> OpaqueAffinityBuilder {
129 OpaqueAffinityBuilder::new()
130 }
131
132 pub const fn other() -> OtherAffinityBuilder {
134 OtherAffinityBuilder::new()
135 }
136
137 pub const fn char() -> CharAffinityBuilder {
139 CharAffinityBuilder::new()
140 }
141
142 pub const fn path() -> PathAffinityBuilder {
144 PathAffinityBuilder::new()
145 }
146}
147
148#[derive(Clone, Copy, PartialEq, Eq, Hash, Debug)]
154#[repr(C)]
155#[non_exhaustive]
156pub struct NumberAffinity {
157 pub bits: NumberBits,
159
160 pub min: PtrConst<'static>,
162
163 pub max: PtrConst<'static>,
165
166 pub positive_infinity: Option<PtrConst<'static>>,
168
169 pub negative_infinity: Option<PtrConst<'static>>,
171
172 pub nan_sample: Option<PtrConst<'static>>,
175
176 pub positive_zero: Option<PtrConst<'static>>,
178
179 pub negative_zero: Option<PtrConst<'static>>,
181
182 pub epsilon: Option<PtrConst<'static>>,
185}
186
187#[derive(Clone, Copy, PartialEq, Eq, Hash, Debug)]
189#[repr(C)]
190pub enum Signedness {
191 Signed,
193 Unsigned,
195}
196
197#[derive(Clone, Copy, PartialEq, Eq, Hash, Debug)]
199#[repr(C)]
200#[non_exhaustive]
201pub enum NumberBits {
202 Integer {
204 bits: usize,
206 sign: Signedness,
208 },
209 Float {
211 sign_bits: usize,
213 exponent_bits: usize,
215 mantissa_bits: usize,
217 has_explicit_first_mantissa_bit: bool,
222 },
223 Fixed {
225 sign_bits: usize,
227 integer_bits: usize,
229 fraction_bits: usize,
231 },
232 Decimal {
234 sign_bits: usize,
236 integer_bits: usize,
238 scale_bits: usize,
240 },
241}
242
243impl NumberAffinity {
244 pub const fn builder() -> NumberAffinityBuilder {
246 NumberAffinityBuilder::new()
247 }
248}
249
250#[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 #[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 pub const fn integer(mut self, bits: usize, sign: Signedness) -> Self {
283 self.limits = Some(NumberBits::Integer { bits, sign });
284 self
285 }
286
287 pub const fn signed_integer(self, bits: usize) -> Self {
289 self.integer(bits, Signedness::Signed)
290 }
291
292 pub const fn unsigned_integer(self, bits: usize) -> Self {
294 self.integer(bits, Signedness::Unsigned)
295 }
296
297 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 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 pub const fn min(mut self, min: PtrConst<'static>) -> Self {
331 self.min = Some(min);
332 self
333 }
334
335 pub const fn max(mut self, max: PtrConst<'static>) -> Self {
337 self.max = Some(max);
338 self
339 }
340
341 pub const fn positive_infinity(mut self, value: PtrConst<'static>) -> Self {
343 self.positive_infinity = Some(value);
344 self
345 }
346
347 pub const fn negative_infinity(mut self, value: PtrConst<'static>) -> Self {
349 self.negative_infinity = Some(value);
350 self
351 }
352
353 pub const fn nan_sample(mut self, value: PtrConst<'static>) -> Self {
355 self.nan_sample = Some(value);
356 self
357 }
358
359 pub const fn positive_zero(mut self, value: PtrConst<'static>) -> Self {
361 self.positive_zero = Some(value);
362 self
363 }
364
365 pub const fn negative_zero(mut self, value: PtrConst<'static>) -> Self {
367 self.negative_zero = Some(value);
368 self
369 }
370
371 pub const fn epsilon(mut self, value: PtrConst<'static>) -> Self {
373 self.epsilon = Some(value);
374 self
375 }
376
377 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#[derive(Clone, Copy, PartialEq, Eq, Hash, Debug)]
395#[repr(C)]
396#[non_exhaustive]
397pub struct ComplexNumberAffinity {
398 inner: ComplexNumberAffinityInner,
400}
401
402#[derive(Clone, Copy, PartialEq, Eq, Hash, Debug)]
403#[repr(C)]
404#[non_exhaustive]
405enum ComplexNumberAffinityInner {
406 Cartesian {
408 component: NumberAffinity,
411 },
412 Polar {
414 absolute: NumberAffinity,
416 bearing: NumberAffinity,
418 },
419}
420
421impl ComplexNumberAffinity {
422 pub const fn builder() -> ComplexNumberAffinityBuilder {
424 ComplexNumberAffinityBuilder::new()
425 }
426}
427
428#[repr(C)]
430pub struct ComplexNumberAffinityBuilder {
431 inner: ComplexNumberAffinityBuilderInner,
432}
433
434#[repr(C)]
435enum ComplexNumberAffinityBuilderInner {
436 Undefined,
437 Cartesian {
438 component: NumberAffinity,
441 },
442 Polar {
443 absolute: NumberAffinity,
444 bearing: NumberAffinity,
445 },
446}
447
448impl ComplexNumberAffinityBuilder {
449 #[allow(clippy::new_without_default)]
451 pub const fn new() -> Self {
452 Self {
453 inner: ComplexNumberAffinityBuilderInner::Undefined,
454 }
455 }
456
457 pub const fn cartesian(self, component: NumberAffinity) -> Self {
459 Self {
460 inner: ComplexNumberAffinityBuilderInner::Cartesian { component },
461 }
462 }
463
464 pub const fn polar(self, absolute: NumberAffinity, bearing: NumberAffinity) -> Self {
466 Self {
467 inner: ComplexNumberAffinityBuilderInner::Polar { absolute, bearing },
468 }
469 }
470
471 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#[derive(Clone, Copy, PartialEq, Eq, Hash, Debug)]
486#[repr(C)]
487#[non_exhaustive]
488pub struct StringAffinity {
489 pub max_inline_length: Option<usize>,
491}
492
493impl StringAffinity {
494 pub const fn builder() -> StringAffinityBuilder {
496 StringAffinityBuilder::new()
497 }
498}
499
500#[repr(C)]
502pub struct StringAffinityBuilder {
503 max_inline_length: Option<usize>,
504}
505
506impl StringAffinityBuilder {
507 #[allow(clippy::new_without_default)]
509 pub const fn new() -> Self {
510 Self {
511 max_inline_length: None,
512 }
513 }
514
515 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 pub const fn build(self) -> ScalarAffinity {
523 ScalarAffinity::String(StringAffinity {
524 max_inline_length: self.max_inline_length,
525 })
526 }
527}
528
529#[derive(Clone, Copy, PartialEq, Eq, Hash, Debug)]
531#[repr(C)]
532#[non_exhaustive]
533pub struct BoolAffinity {}
534
535impl BoolAffinity {
536 pub const fn builder() -> BoolAffinityBuilder {
538 BoolAffinityBuilder::new()
539 }
540}
541
542#[repr(C)]
544pub struct BoolAffinityBuilder {}
545
546impl BoolAffinityBuilder {
547 #[allow(clippy::new_without_default)]
549 pub const fn new() -> Self {
550 Self {}
551 }
552
553 pub const fn build(self) -> ScalarAffinity {
555 ScalarAffinity::Boolean(BoolAffinity {})
556 }
557}
558
559#[derive(Clone, Copy, PartialEq, Eq, Hash, Debug)]
561#[repr(C)]
562#[non_exhaustive]
563pub struct EmptyAffinity {}
564
565impl EmptyAffinity {
566 pub const fn builder() -> EmptyAffinityBuilder {
568 EmptyAffinityBuilder::new()
569 }
570}
571
572#[repr(C)]
574pub struct EmptyAffinityBuilder {}
575
576impl EmptyAffinityBuilder {
577 #[allow(clippy::new_without_default)]
579 pub const fn new() -> Self {
580 Self {}
581 }
582
583 pub const fn build(self) -> ScalarAffinity {
585 ScalarAffinity::Empty(EmptyAffinity {})
586 }
587}
588
589#[derive(Clone, Copy, PartialEq, Eq, Hash, Debug)]
591#[repr(C)]
592#[non_exhaustive]
593pub struct SocketAddrAffinity {}
594
595impl SocketAddrAffinity {
596 pub const fn builder() -> SocketAddrAffinityBuilder {
598 SocketAddrAffinityBuilder::new()
599 }
600}
601
602#[repr(C)]
604pub struct SocketAddrAffinityBuilder {}
605
606impl SocketAddrAffinityBuilder {
607 #[allow(clippy::new_without_default)]
609 pub const fn new() -> Self {
610 Self {}
611 }
612
613 pub const fn build(self) -> ScalarAffinity {
615 ScalarAffinity::SocketAddr(SocketAddrAffinity {})
616 }
617}
618
619#[derive(Clone, Copy, PartialEq, Eq, Hash, Debug)]
621#[repr(C)]
622#[non_exhaustive]
623pub struct IpAddrAffinity {}
624
625impl IpAddrAffinity {
626 pub const fn builder() -> IpAddrAffinityBuilder {
628 IpAddrAffinityBuilder::new()
629 }
630}
631
632#[repr(C)]
634pub struct IpAddrAffinityBuilder {}
635
636impl IpAddrAffinityBuilder {
637 #[allow(clippy::new_without_default)]
639 pub const fn new() -> Self {
640 Self {}
641 }
642
643 pub const fn build(self) -> ScalarAffinity {
645 ScalarAffinity::IpAddr(IpAddrAffinity {})
646 }
647}
648
649#[derive(Clone, Copy, PartialEq, Eq, Hash, Debug)]
651#[repr(C)]
652#[non_exhaustive]
653pub struct UuidAffinity {}
654
655impl UuidAffinity {
656 pub const fn builder() -> UuidAffinityBuilder {
658 UuidAffinityBuilder::new()
659 }
660}
661
662#[repr(C)]
664pub struct UuidAffinityBuilder {}
665
666impl UuidAffinityBuilder {
667 #[allow(clippy::new_without_default)]
669 pub const fn new() -> Self {
670 Self {}
671 }
672
673 pub const fn build(self) -> ScalarAffinity {
675 ScalarAffinity::UUID(UuidAffinity {})
676 }
677}
678
679#[derive(Clone, Copy, PartialEq, Eq, Hash, Debug)]
681#[repr(C)]
682#[non_exhaustive]
683pub struct TimeAffinity {
684 epoch: Option<PtrConst<'static>>,
688
689 min: Option<PtrConst<'static>>,
691
692 max: Option<PtrConst<'static>>,
694
695 granularity: Option<PtrConst<'static>>,
700
701 interval_elements: Option<&'static [PtrConst<'static>]>,
715
716 timezone_granularity: Option<PtrConst<'static>>,
721}
722
723impl TimeAffinity {
724 pub const fn builder() -> TimeAffinityBuilder {
726 TimeAffinityBuilder::new()
727 }
728}
729
730#[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 #[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 pub const fn epoch(mut self, epoch: PtrConst<'static>) -> Self {
757 self.epoch = Some(epoch);
758 self
759 }
760
761 pub const fn min(mut self, min: PtrConst<'static>) -> Self {
763 self.min = Some(min);
764 self
765 }
766
767 pub const fn max(mut self, max: PtrConst<'static>) -> Self {
769 self.max = Some(max);
770 self
771 }
772
773 pub const fn granularity(mut self, granularity: PtrConst<'static>) -> Self {
775 self.granularity = Some(granularity);
776 self
777 }
778
779 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 pub const fn timezone_granularity(mut self, timezone_granularity: PtrConst<'static>) -> Self {
790 self.timezone_granularity = Some(timezone_granularity);
791 self
792 }
793
794 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#[derive(Clone, Copy, PartialEq, Eq, Hash, Debug)]
809#[repr(C)]
810#[non_exhaustive]
811pub struct OpaqueAffinity {}
812
813impl OpaqueAffinity {
814 pub const fn builder() -> OpaqueAffinityBuilder {
816 OpaqueAffinityBuilder::new()
817 }
818}
819
820#[repr(C)]
822pub struct OpaqueAffinityBuilder {}
823
824impl OpaqueAffinityBuilder {
825 #[allow(clippy::new_without_default)]
827 pub const fn new() -> Self {
828 Self {}
829 }
830
831 pub const fn build(self) -> ScalarAffinity {
833 ScalarAffinity::Opaque(OpaqueAffinity {})
834 }
835}
836
837#[derive(Clone, Copy, PartialEq, Eq, Hash, Debug)]
839#[repr(C)]
840#[non_exhaustive]
841pub struct OtherAffinity {}
842
843impl OtherAffinity {
844 pub const fn builder() -> OtherAffinityBuilder {
846 OtherAffinityBuilder::new()
847 }
848}
849
850#[repr(C)]
852pub struct OtherAffinityBuilder {}
853
854impl OtherAffinityBuilder {
855 #[allow(clippy::new_without_default)]
857 pub const fn new() -> Self {
858 Self {}
859 }
860
861 pub const fn build(self) -> ScalarAffinity {
863 ScalarAffinity::Other(OtherAffinity {})
864 }
865}
866
867#[derive(Clone, Copy, PartialEq, Eq, Hash, Debug)]
869#[repr(C)]
870#[non_exhaustive]
871pub struct CharAffinity {}
872
873impl CharAffinity {
874 pub const fn builder() -> CharAffinityBuilder {
876 CharAffinityBuilder::new()
877 }
878}
879
880#[repr(C)]
882pub struct CharAffinityBuilder {}
883
884impl CharAffinityBuilder {
885 #[allow(clippy::new_without_default)]
887 pub const fn new() -> Self {
888 Self {}
889 }
890
891 pub const fn build(self) -> ScalarAffinity {
893 ScalarAffinity::Char(CharAffinity {})
894 }
895}
896
897#[derive(Clone, Copy, PartialEq, Eq, Hash, Debug)]
899#[repr(C)]
900#[non_exhaustive]
901pub struct PathAffinity {}
902
903impl PathAffinity {
904 pub const fn builder() -> PathAffinityBuilder {
906 PathAffinityBuilder::new()
907 }
908}
909
910#[repr(C)]
912pub struct PathAffinityBuilder {}
913
914impl PathAffinityBuilder {
915 #[allow(clippy::new_without_default)]
917 pub const fn new() -> Self {
918 Self {}
919 }
920
921 pub const fn build(self) -> ScalarAffinity {
923 ScalarAffinity::Path(PathAffinity {})
924 }
925}