elicitation 0.8.0

Conversational elicitation of strongly-typed Rust values via MCP
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
//! Float contract types.

use super::ValidationError;
use crate::{ElicitCommunicator, ElicitResult, Elicitation, Prompt};
use elicitation_macros::instrumented_impl;
use schemars::JsonSchema;
use serde::{Deserialize, Serialize};

// ============================================================================
// Macro: Default Wrapper Generation for Float Types
// ============================================================================

/// Generate a Default wrapper for a float primitive type.
///
/// This macro creates an unconstrained wrapper type that:
/// - Has Serialize, Deserialize, and JsonSchema derives
/// - Is marked as elicit-safe for rmcp
/// - Uses serde deserialization instead of manual parsing
/// - Provides new/get/into_inner methods
/// - Implements Prompt and Elicitation traits
macro_rules! impl_float_default_wrapper {
    ($primitive:ty, $wrapper:ident) => {
        #[doc = concat!("Default wrapper for ", stringify!($primitive), " (unconstrained).")]
        ///
        /// Used internally for MCP elicitation of primitive float values.
        /// Provides JsonSchema for client-side validation.
        #[derive(Debug, Clone, Copy, PartialEq, Serialize, Deserialize, JsonSchema)]
        #[schemars(description = concat!(stringify!($primitive), " value"))]
        pub struct $wrapper(
            #[schemars(description = "Float value")]
            $primitive
        );

        rmcp::elicit_safe!($wrapper);

        impl $wrapper {
            /// Creates a new wrapper.
            pub fn new(value: $primitive) -> Self {
                Self(value)
            }

            /// Gets the inner value.
            pub fn get(&self) -> $primitive {
                self.0
            }

            /// Unwraps to the inner value.
            pub fn into_inner(self) -> $primitive {
                self.0
            }
        }

        paste::paste! {
            crate::default_style!($wrapper => [<$wrapper Style>]);

            impl Prompt for $wrapper {
                fn prompt() -> Option<&'static str> {
                    Some("Please enter a number:")
                }
            }

            impl Elicitation for $wrapper {
                type Style = [<$wrapper Style>];

                #[tracing::instrument(skip(communicator))]
                async fn elicit<C: ElicitCommunicator>(communicator: &C) -> ElicitResult<Self> {
                    let prompt = Self::prompt().unwrap();
                    tracing::debug!(concat!("Eliciting ", stringify!($wrapper), " with server-side send_prompt"));

                    // Use send_prompt for server-side compatibility
                    let response = communicator.send_prompt(prompt).await?;

                    // Parse response as float
                    let value: $primitive = response.trim().parse().map_err(|e| {
                        crate::ElicitError::new(crate::ElicitErrorKind::ParseError(
                            format!("Failed to parse {}: {}", stringify!($primitive), e),
                        ))
                    })?;

                    Ok(Self::new(value))
                }
            }
        }
    };
}

// ============================================================================
// Verification Types (Constrained)
// ============================================================================

// F32Positive (f32 > 0.0 and finite)
/// Contract type for positive f32 values (> 0.0).
///
/// Validates on construction, then can unwrap to stdlib f32 via `into_inner()`.
#[derive(Debug, Clone, Copy, PartialEq, PartialOrd)]
pub struct F32Positive(f32);

#[cfg_attr(not(kani), instrumented_impl)]
impl F32Positive {
    /// Constructs a positive f32 value.
    ///
    /// # Errors
    ///
    /// Returns `ValidationError::NotFinite` if value is NaN or infinite.
    /// Returns `ValidationError::FloatNotPositive` if value <= 0.0.
    pub fn new(value: f32) -> Result<Self, ValidationError> {
        #[cfg(kani)]
        {
            // Under Kani: symbolic validation (trust stdlib float handling)
            let is_finite: bool = kani::any();
            let is_positive: bool = kani::any();

            if !is_finite {
                Err(ValidationError::NotFinite(String::new()))
            } else if is_positive {
                Ok(Self(value))
            } else {
                Err(ValidationError::FloatNotPositive(value as f64))
            }
        }
        #[cfg(not(kani))]
        {
            // Production: actual validation
            if !value.is_finite() {
                Err(ValidationError::NotFinite(format!("{}", value)))
            } else if value > 0.0 {
                Ok(Self(value))
            } else {
                Err(ValidationError::FloatNotPositive(value as f64))
            }
        }
    }

    /// Gets the wrapped value.
    pub fn get(&self) -> f32 {
        self.0
    }

    /// Unwraps to stdlib f32 (trenchcoat off).
    pub fn into_inner(self) -> f32 {
        self.0
    }
}

crate::default_style!(F32Positive => F32PositiveStyle);

impl Prompt for F32Positive {
    fn prompt() -> Option<&'static str> {
        Some("Please enter a positive number (> 0.0):")
    }
}

impl Elicitation for F32Positive {
    type Style = F32PositiveStyle;

    #[tracing::instrument(skip(communicator), fields(type_name = "F32Positive"))]
    async fn elicit<C: ElicitCommunicator>(communicator: &C) -> ElicitResult<Self> {
        tracing::debug!("Eliciting F32Positive (positive f32 value)");

        loop {
            let value = f32::elicit(communicator).await?;

            match Self::new(value) {
                Ok(positive) => {
                    tracing::debug!(value, "Valid F32Positive constructed");
                    return Ok(positive);
                }
                Err(e) => {
                    tracing::warn!(value, error = %e, "Invalid F32Positive, re-prompting");
                }
            }
        }
    }
}

// F32NonNegative (f32 >= 0.0 and finite)
/// Contract type for non-negative f32 values (>= 0.0).
///
/// Validates on construction, then can unwrap to stdlib f32 via `into_inner()`.
#[derive(Debug, Clone, Copy, PartialEq, PartialOrd)]
pub struct F32NonNegative(f32);

#[cfg_attr(not(kani), instrumented_impl)]
impl F32NonNegative {
    /// Constructs a non-negative f32 value.
    ///
    /// # Errors
    ///
    /// Returns `ValidationError::NotFinite` if value is NaN or infinite.
    /// Returns `ValidationError::FloatNegative` if value < 0.0.
    pub fn new(value: f32) -> Result<Self, ValidationError> {
        #[cfg(kani)]
        {
            // Under Kani: symbolic validation (trust stdlib float handling)
            let is_finite: bool = kani::any();
            let is_non_negative: bool = kani::any();

            if !is_finite {
                Err(ValidationError::NotFinite(String::new()))
            } else if is_non_negative {
                Ok(Self(value))
            } else {
                Err(ValidationError::FloatNegative(value as f64))
            }
        }
        #[cfg(not(kani))]
        {
            // Production: actual validation
            if !value.is_finite() {
                Err(ValidationError::NotFinite(format!("{}", value)))
            } else if value >= 0.0 {
                Ok(Self(value))
            } else {
                Err(ValidationError::FloatNegative(value as f64))
            }
        }
    }

    /// Gets the wrapped value.
    pub fn get(&self) -> f32 {
        self.0
    }

    /// Unwraps to stdlib f32 (trenchcoat off).
    pub fn into_inner(self) -> f32 {
        self.0
    }
}

crate::default_style!(F32NonNegative => F32NonNegativeStyle);

impl Prompt for F32NonNegative {
    fn prompt() -> Option<&'static str> {
        Some("Please enter a non-negative number (>= 0.0):")
    }
}

impl Elicitation for F32NonNegative {
    type Style = F32NonNegativeStyle;

    #[tracing::instrument(skip(communicator), fields(type_name = "F32NonNegative"))]
    async fn elicit<C: ElicitCommunicator>(communicator: &C) -> ElicitResult<Self> {
        tracing::debug!("Eliciting F32NonNegative (non-negative f32 value)");

        loop {
            let value = f32::elicit(communicator).await?;

            match Self::new(value) {
                Ok(non_negative) => {
                    tracing::debug!(value, "Valid F32NonNegative constructed");
                    return Ok(non_negative);
                }
                Err(e) => {
                    tracing::warn!(value, error = %e, "Invalid F32NonNegative, re-prompting");
                }
            }
        }
    }
}

// F32Finite (finite f32, not NaN or infinite)
/// Contract type for finite f32 values (not NaN or infinite).
///
/// Validates on construction, then can unwrap to stdlib f32 via `into_inner()`.
#[derive(Debug, Clone, Copy, PartialEq, PartialOrd)]
pub struct F32Finite(f32);

#[cfg_attr(not(kani), instrumented_impl)]
impl F32Finite {
    /// Constructs a finite f32 value.
    ///
    /// # Errors
    ///
    /// Returns `ValidationError::NotFinite` if value is NaN or infinite.
    pub fn new(value: f32) -> Result<Self, ValidationError> {
        #[cfg(kani)]
        {
            // Under Kani: symbolic validation (trust stdlib float handling)
            let is_finite: bool = kani::any();
            if is_finite {
                Ok(Self(value))
            } else {
                // Can't format symbolic float - use empty string
                Err(ValidationError::NotFinite(String::new()))
            }
        }
        #[cfg(not(kani))]
        {
            // Production: actual validation
            if value.is_finite() {
                Ok(Self(value))
            } else {
                Err(ValidationError::NotFinite(format!("{}", value)))
            }
        }
    }

    /// Gets the wrapped value.
    pub fn get(&self) -> f32 {
        self.0
    }

    /// Unwraps to stdlib f32 (trenchcoat off).
    pub fn into_inner(self) -> f32 {
        self.0
    }
}

crate::default_style!(F32Finite => F32FiniteStyle);

impl Prompt for F32Finite {
    fn prompt() -> Option<&'static str> {
        Some("Please enter a finite number (not NaN or infinite):")
    }
}

impl Elicitation for F32Finite {
    type Style = F32FiniteStyle;

    #[tracing::instrument(skip(communicator), fields(type_name = "F32Finite"))]
    async fn elicit<C: ElicitCommunicator>(communicator: &C) -> ElicitResult<Self> {
        tracing::debug!("Eliciting F32Finite (finite f32 value)");

        loop {
            let value = f32::elicit(communicator).await?;

            match Self::new(value) {
                Ok(finite) => {
                    tracing::debug!(value, "Valid F32Finite constructed");
                    return Ok(finite);
                }
                Err(e) => {
                    tracing::warn!(value, error = %e, "Invalid F32Finite, re-prompting");
                }
            }
        }
    }
}

// F64Positive (f64 > 0.0 and finite)
/// Contract type for positive f64 values (> 0.0).
///
/// Validates on construction, then can unwrap to stdlib f64 via `into_inner()`.
#[derive(Debug, Clone, Copy, PartialEq, PartialOrd)]
pub struct F64Positive(f64);

#[cfg_attr(not(kani), instrumented_impl)]
impl F64Positive {
    /// Constructs a positive f64 value.
    ///
    /// # Errors
    ///
    /// Returns `ValidationError::NotFinite` if value is NaN or infinite.
    /// Returns `ValidationError::FloatNotPositive` if value <= 0.0.
    pub fn new(value: f64) -> Result<Self, ValidationError> {
        #[cfg(kani)]
        {
            // Under Kani: symbolic validation (trust stdlib float handling)
            let is_finite: bool = kani::any();
            let is_positive: bool = kani::any();

            if !is_finite {
                Err(ValidationError::NotFinite(String::new()))
            } else if is_positive {
                Ok(Self(value))
            } else {
                Err(ValidationError::FloatNotPositive(value))
            }
        }
        #[cfg(not(kani))]
        {
            // Production: actual validation
            if !value.is_finite() {
                Err(ValidationError::NotFinite(format!("{}", value)))
            } else if value > 0.0 {
                Ok(Self(value))
            } else {
                Err(ValidationError::FloatNotPositive(value))
            }
        }
    }

    /// Gets the wrapped value.
    pub fn get(&self) -> f64 {
        self.0
    }

    /// Unwraps to stdlib f64 (trenchcoat off).
    pub fn into_inner(self) -> f64 {
        self.0
    }
}

crate::default_style!(F64Positive => F64PositiveStyle);

impl Prompt for F64Positive {
    fn prompt() -> Option<&'static str> {
        Some("Please enter a positive number (> 0.0):")
    }
}

impl Elicitation for F64Positive {
    type Style = F64PositiveStyle;

    #[tracing::instrument(skip(communicator), fields(type_name = "F64Positive"))]
    async fn elicit<C: ElicitCommunicator>(communicator: &C) -> ElicitResult<Self> {
        tracing::debug!("Eliciting F64Positive (positive f64 value)");

        loop {
            let value = f64::elicit(communicator).await?;

            match Self::new(value) {
                Ok(positive) => {
                    tracing::debug!(value, "Valid F64Positive constructed");
                    return Ok(positive);
                }
                Err(e) => {
                    tracing::warn!(value, error = %e, "Invalid F64Positive, re-prompting");
                }
            }
        }
    }
}

// F64NonNegative (f64 >= 0.0 and finite)
/// Contract type for non-negative f64 values (>= 0.0).
///
/// Validates on construction, then can unwrap to stdlib f64 via `into_inner()`.
#[derive(Debug, Clone, Copy, PartialEq, PartialOrd)]
pub struct F64NonNegative(f64);

#[cfg_attr(not(kani), instrumented_impl)]
impl F64NonNegative {
    /// Constructs a non-negative f64 value.
    ///
    /// # Errors
    ///
    /// Returns `ValidationError::NotFinite` if value is NaN or infinite.
    /// Returns `ValidationError::FloatNegative` if value < 0.0.
    pub fn new(value: f64) -> Result<Self, ValidationError> {
        #[cfg(kani)]
        {
            // Under Kani: symbolic validation (trust stdlib float handling)
            let is_finite: bool = kani::any();
            let is_non_negative: bool = kani::any();

            if !is_finite {
                Err(ValidationError::NotFinite(String::new()))
            } else if is_non_negative {
                Ok(Self(value))
            } else {
                Err(ValidationError::FloatNegative(value))
            }
        }
        #[cfg(not(kani))]
        {
            // Production: actual validation
            if !value.is_finite() {
                Err(ValidationError::NotFinite(format!("{}", value)))
            } else if value >= 0.0 {
                Ok(Self(value))
            } else {
                Err(ValidationError::FloatNegative(value))
            }
        }
    }

    /// Gets the wrapped value.
    pub fn get(&self) -> f64 {
        self.0
    }

    /// Unwraps to stdlib f64 (trenchcoat off).
    pub fn into_inner(self) -> f64 {
        self.0
    }
}

crate::default_style!(F64NonNegative => F64NonNegativeStyle);

impl Prompt for F64NonNegative {
    fn prompt() -> Option<&'static str> {
        Some("Please enter a non-negative number (>= 0.0):")
    }
}

impl Elicitation for F64NonNegative {
    type Style = F64NonNegativeStyle;

    #[tracing::instrument(skip(communicator), fields(type_name = "F64NonNegative"))]
    async fn elicit<C: ElicitCommunicator>(communicator: &C) -> ElicitResult<Self> {
        tracing::debug!("Eliciting F64NonNegative (non-negative f64 value)");

        loop {
            let value = f64::elicit(communicator).await?;

            match Self::new(value) {
                Ok(non_negative) => {
                    tracing::debug!(value, "Valid F64NonNegative constructed");
                    return Ok(non_negative);
                }
                Err(e) => {
                    tracing::warn!(value, error = %e, "Invalid F64NonNegative, re-prompting");
                }
            }
        }
    }
}

// F64Finite (finite f64, not NaN or infinite)
/// Contract type for finite f64 values (not NaN or infinite).
///
/// Validates on construction, then can unwrap to stdlib f64 via `into_inner()`.
#[derive(Debug, Clone, Copy, PartialEq, PartialOrd)]
pub struct F64Finite(f64);

#[cfg_attr(not(kani), instrumented_impl)]
impl F64Finite {
    /// Constructs a finite f64 value.
    ///
    /// # Errors
    ///
    /// Returns `ValidationError::NotFinite` if value is NaN or infinite.
    pub fn new(value: f64) -> Result<Self, ValidationError> {
        if value.is_finite() {
            Ok(Self(value))
        } else {
            Err(ValidationError::NotFinite(format!("{}", value)))
        }
    }

    /// Gets the wrapped value.
    pub fn get(&self) -> f64 {
        self.0
    }

    /// Unwraps to stdlib f64 (trenchcoat off).
    pub fn into_inner(self) -> f64 {
        self.0
    }
}

crate::default_style!(F64Finite => F64FiniteStyle);

impl Prompt for F64Finite {
    fn prompt() -> Option<&'static str> {
        Some("Please enter a finite number (not NaN or infinite):")
    }
}

impl Elicitation for F64Finite {
    type Style = F64FiniteStyle;

    #[tracing::instrument(skip(communicator), fields(type_name = "F64Finite"))]
    async fn elicit<C: ElicitCommunicator>(communicator: &C) -> ElicitResult<Self> {
        tracing::debug!("Eliciting F64Finite (finite f64 value)");

        loop {
            let value = f64::elicit(communicator).await?;

            match Self::new(value) {
                Ok(finite) => {
                    tracing::debug!(value, "Valid F64Finite constructed");
                    return Ok(finite);
                }
                Err(e) => {
                    tracing::warn!(value, error = %e, "Invalid F64Finite, re-prompting");
                }
            }
        }
    }
}

// Tests
#[cfg(test)]
mod f32_positive_tests {
    use super::*;

    #[test]
    fn f32_positive_new_valid() {
        let result = F32Positive::new(1.5);
        assert!(result.is_ok());
        assert_eq!(result.unwrap().get(), 1.5);
    }

    #[test]
    fn f32_positive_new_zero_invalid() {
        let result = F32Positive::new(0.0);
        assert!(result.is_err());
    }

    #[test]
    fn f32_positive_new_negative_invalid() {
        let result = F32Positive::new(-1.5);
        assert!(result.is_err());
    }

    #[test]
    fn f32_positive_new_nan_invalid() {
        let result = F32Positive::new(f32::NAN);
        assert!(result.is_err());
    }

    #[test]
    fn f32_positive_new_infinity_invalid() {
        let result = F32Positive::new(f32::INFINITY);
        assert!(result.is_err());
    }

    #[test]
    fn f32_positive_into_inner() {
        let positive = F32Positive::new(42.5).unwrap();
        let value: f32 = positive.into_inner();
        assert_eq!(value, 42.5);
    }
}

#[cfg(test)]
mod f32_nonnegative_tests {
    use super::*;

    #[test]
    fn f32_nonnegative_new_valid_positive() {
        let result = F32NonNegative::new(1.5);
        assert!(result.is_ok());
        assert_eq!(result.unwrap().get(), 1.5);
    }

    #[test]
    fn f32_nonnegative_new_valid_zero() {
        let result = F32NonNegative::new(0.0);
        assert!(result.is_ok());
        assert_eq!(result.unwrap().get(), 0.0);
    }

    #[test]
    fn f32_nonnegative_new_negative_invalid() {
        let result = F32NonNegative::new(-1.5);
        assert!(result.is_err());
    }

    #[test]
    fn f32_nonnegative_new_nan_invalid() {
        let result = F32NonNegative::new(f32::NAN);
        assert!(result.is_err());
    }

    #[test]
    fn f32_nonnegative_into_inner() {
        let non_neg = F32NonNegative::new(10.5).unwrap();
        let value: f32 = non_neg.into_inner();
        assert_eq!(value, 10.5);
    }
}

#[cfg(test)]
mod f32_finite_tests {
    use super::*;

    #[test]
    fn f32_finite_new_valid_positive() {
        let result = F32Finite::new(1.5);
        assert!(result.is_ok());
        assert_eq!(result.unwrap().get(), 1.5);
    }

    #[test]
    fn f32_finite_new_valid_negative() {
        let result = F32Finite::new(-1.5);
        assert!(result.is_ok());
        assert_eq!(result.unwrap().get(), -1.5);
    }

    #[test]
    fn f32_finite_new_valid_zero() {
        let result = F32Finite::new(0.0);
        assert!(result.is_ok());
        assert_eq!(result.unwrap().get(), 0.0);
    }

    #[test]
    fn f32_finite_new_nan_invalid() {
        let result = F32Finite::new(f32::NAN);
        assert!(result.is_err());
    }

    #[test]
    fn f32_finite_new_infinity_invalid() {
        let result = F32Finite::new(f32::INFINITY);
        assert!(result.is_err());
    }

    #[test]
    fn f32_finite_new_neg_infinity_invalid() {
        let result = F32Finite::new(f32::NEG_INFINITY);
        assert!(result.is_err());
    }

    #[test]
    fn f32_finite_into_inner() {
        let finite = F32Finite::new(42.5).unwrap();
        let value: f32 = finite.into_inner();
        assert_eq!(value, 42.5);
    }
}

#[cfg(test)]
mod f64_positive_tests {
    use super::*;

    #[test]
    fn f64_positive_new_valid() {
        let result = F64Positive::new(1.5);
        assert!(result.is_ok());
        assert_eq!(result.unwrap().get(), 1.5);
    }

    #[test]
    fn f64_positive_new_zero_invalid() {
        let result = F64Positive::new(0.0);
        assert!(result.is_err());
    }

    #[test]
    fn f64_positive_new_negative_invalid() {
        let result = F64Positive::new(-1.5);
        assert!(result.is_err());
    }

    #[test]
    fn f64_positive_new_nan_invalid() {
        let result = F64Positive::new(f64::NAN);
        assert!(result.is_err());
    }

    #[test]
    fn f64_positive_new_infinity_invalid() {
        let result = F64Positive::new(f64::INFINITY);
        assert!(result.is_err());
    }

    #[test]
    fn f64_positive_into_inner() {
        let positive = F64Positive::new(42.5).unwrap();
        let value: f64 = positive.into_inner();
        assert_eq!(value, 42.5);
    }
}

#[cfg(test)]
mod f64_nonnegative_tests {
    use super::*;

    #[test]
    fn f64_nonnegative_new_valid_positive() {
        let result = F64NonNegative::new(1.5);
        assert!(result.is_ok());
        assert_eq!(result.unwrap().get(), 1.5);
    }

    #[test]
    fn f64_nonnegative_new_valid_zero() {
        let result = F64NonNegative::new(0.0);
        assert!(result.is_ok());
        assert_eq!(result.unwrap().get(), 0.0);
    }

    #[test]
    fn f64_nonnegative_new_negative_invalid() {
        let result = F64NonNegative::new(-1.5);
        assert!(result.is_err());
    }

    #[test]
    fn f64_nonnegative_new_nan_invalid() {
        let result = F64NonNegative::new(f64::NAN);
        assert!(result.is_err());
    }

    #[test]
    fn f64_nonnegative_into_inner() {
        let non_neg = F64NonNegative::new(10.5).unwrap();
        let value: f64 = non_neg.into_inner();
        assert_eq!(value, 10.5);
    }
}

#[cfg(test)]
mod f64_finite_tests {
    use super::*;

    #[test]
    fn f64_finite_new_valid_positive() {
        let result = F64Finite::new(1.5);
        assert!(result.is_ok());
        assert_eq!(result.unwrap().get(), 1.5);
    }

    #[test]
    fn f64_finite_new_valid_negative() {
        let result = F64Finite::new(-1.5);
        assert!(result.is_ok());
        assert_eq!(result.unwrap().get(), -1.5);
    }

    #[test]
    fn f64_finite_new_valid_zero() {
        let result = F64Finite::new(0.0);
        assert!(result.is_ok());
        assert_eq!(result.unwrap().get(), 0.0);
    }

    #[test]
    fn f64_finite_new_nan_invalid() {
        let result = F64Finite::new(f64::NAN);
        assert!(result.is_err());
    }

    #[test]
    fn f64_finite_new_infinity_invalid() {
        let result = F64Finite::new(f64::INFINITY);
        assert!(result.is_err());
    }

    #[test]
    fn f64_finite_new_neg_infinity_invalid() {
        let result = F64Finite::new(f64::NEG_INFINITY);
        assert!(result.is_err());
    }

    #[test]
    fn f64_finite_into_inner() {
        let finite = F64Finite::new(42.5).unwrap();
        let value: f64 = finite.into_inner();
        assert_eq!(value, 42.5);
    }
}

// ============================================================================
// Default Wrappers (for MCP elicitation of primitives)
// ============================================================================

// Generate Default wrappers for all float types
impl_float_default_wrapper!(f32, F32Default);
impl_float_default_wrapper!(f64, F64Default);