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
use crate;
use Value;
/// The core Standard Schema trait for runtime validation.
///
/// This trait corresponds to the `StandardSchemaV1` interface in the TypeScript spec.
/// Implementing types can validate arbitrary JSON values and produce typed output.
///
/// # Type Parameters
///
/// * `Input` - The expected input type (for type inference, not runtime checked)
/// * `Output` - The validated output type
///
/// # Example
///
/// ```rust
/// use valrs::{Valrs, ValidationResult};
/// use serde_json::Value;
///
/// struct PositiveInt(i64);
///
/// impl Valrs for PositiveInt {
/// type Input = i64;
/// type Output = PositiveInt;
///
/// fn validate(value: &Value) -> ValidationResult<Self::Output> {
/// match value.as_i64() {
/// Some(n) if n > 0 => ValidationResult::success(PositiveInt(n)),
/// Some(_) => ValidationResult::failure("Must be positive"),
/// None => ValidationResult::failure("Expected integer"),
/// }
/// }
/// }
/// ```
/// Extended trait for schemas that can generate JSON Schema.
///
/// This trait corresponds to the `StandardJSONSchemaV1` interface in the TypeScript spec.
/// Implementing types can convert their schema to JSON Schema format.
///
/// # Supported Targets
///
/// * `Draft202012` - JSON Schema Draft 2020-12
/// * `Draft07` - JSON Schema Draft 07
/// * `OpenApi30` - OpenAPI 3.0 compatible schema