schemars/json_schema_impls/
ffi.rs
1use crate::gen::SchemaGenerator;
2use crate::schema::*;
3use crate::JsonSchema;
4use std::borrow::Cow;
5use std::ffi::{CStr, CString, OsStr, OsString};
6
7impl JsonSchema for OsString {
8 fn schema_name() -> String {
9 "OsString".to_owned()
10 }
11
12 fn schema_id() -> Cow<'static, str> {
13 Cow::Borrowed("std::ffi::OsString")
14 }
15
16 fn json_schema(gen: &mut SchemaGenerator) -> Schema {
17 let mut unix_schema = SchemaObject {
18 instance_type: Some(InstanceType::Object.into()),
19 ..Default::default()
20 };
21 let obj = unix_schema.object();
22 obj.required.insert("Unix".to_owned());
23 obj.properties
24 .insert("Unix".to_owned(), <Vec<u8>>::json_schema(gen));
25
26 let mut win_schema = SchemaObject {
27 instance_type: Some(InstanceType::Object.into()),
28 ..Default::default()
29 };
30 let obj = win_schema.object();
31 obj.required.insert("Windows".to_owned());
32 obj.properties
33 .insert("Windows".to_owned(), <Vec<u16>>::json_schema(gen));
34
35 let mut schema = SchemaObject::default();
36 schema.subschemas().one_of = Some(vec![unix_schema.into(), win_schema.into()]);
37 schema.into()
38 }
39}
40
41forward_impl!(OsStr => OsString);
42
43forward_impl!(CString => Vec<u8>);
44forward_impl!(CStr => Vec<u8>);