Debian Codegraph @

src/json_schema_impls/nonzero.rs

raw symbols SCIP
1 use crate::_alloc_prelude::*;
2 use crate::{JsonSchema, Schema, SchemaGenerator};
3 use alloc::borrow::Cow;
4 use core::num::*;
5
6 macro_rules! nonzero_signed_impl {
7 ($type:ty => $primitive:ty) => {
8 impl JsonSchema for $type {
9 inline_schema!();
10
11 fn schema_name() -> Cow<'static, str> {
12 stringify!($type).into()
13 }
14
15 fn schema_id() -> Cow<'static, str> {
16 stringify!(std::num::$type).into()
17 }
18
19 fn json_schema(generator: &mut SchemaGenerator) -> Schema {
20 let mut schema = <$primitive>::json_schema(generator);
21 schema.insert("not".to_owned(), serde_json::json!({
22 "const": 0
23 }));
24 schema
25 }
26 }
27 };
28 }
29
30 nonzero_signed_impl!(NonZeroI8 => i8);
31 nonzero_signed_impl!(NonZeroI16 => i16);
32 nonzero_signed_impl!(NonZeroI32 => i32);
33 nonzero_signed_impl!(NonZeroI64 => i64);
34 nonzero_signed_impl!(NonZeroI128 => i128);
35 nonzero_signed_impl!(NonZeroIsize => isize);
36
37 macro_rules! nonzero_unsigned_impl {
38 ($type:ty => $primitive:ty) => {
39 impl JsonSchema for $type {
40 inline_schema!();
41
42 fn schema_name() -> Cow<'static, str> {
43 stringify!($type).into()
44 }
45
46 fn schema_id() -> Cow<'static, str> {
47 stringify!(std::num::$type).into()
48 }
49
50 fn json_schema(generator: &mut SchemaGenerator) -> Schema {
51 let mut schema = <$primitive>::json_schema(generator);
52 schema.insert("minimum".to_owned(), 1.into());
53 schema
54 }
55 }
56 };
57 }
58
59 nonzero_unsigned_impl!(NonZeroU8 => u8);
60 nonzero_unsigned_impl!(NonZeroU16 => u16);
61 nonzero_unsigned_impl!(NonZeroU32 => u32);
62 nonzero_unsigned_impl!(NonZeroU64 => u64);
63 nonzero_unsigned_impl!(NonZeroU128 => u128);
64 nonzero_unsigned_impl!(NonZeroUsize => usize);