Debian Codegraph @

src/json_schema_impls/bytes1.rs

raw symbols SCIP
1 use crate::_alloc_prelude::*;
2 use crate::generate::Contract;
3 use crate::{JsonSchema, Schema};
4 use alloc::borrow::Cow;
5 use serde_json::Value;
6
7 impl JsonSchema for bytes1::Bytes {
8 fn schema_name() -> Cow<'static, str> {
9 "Bytes".into()
10 }
11
12 fn schema_id() -> Cow<'static, str> {
13 "bytes::Bytes".into()
14 }
15
16 fn json_schema(generator: &mut crate::SchemaGenerator) -> crate::Schema {
17 let ty = match generator.contract() {
18 Contract::Deserialize => Value::Array(vec!["array".into(), "string".into()]),
19 Contract::Serialize => "array".into(),
20 };
21
22 let mut result = Schema::default();
23 result.insert("type".to_owned(), ty);
24 result.insert("items".to_owned(), generator.subschema_for::<u8>().into());
25 result
26 }
27 }
28
29 forward_impl!(bytes1::BytesMut => bytes1::Bytes);