-
Notifications
You must be signed in to change notification settings - Fork 132
Expand file tree
/
Copy pathbuiltins_alloc.rs
More file actions
75 lines (65 loc) · 2.22 KB
/
builtins_alloc.rs
File metadata and controls
75 lines (65 loc) · 2.22 KB
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
//! Implementations of the [`Schema`] trait for `alloc` types
use crate::{
schema::{DataModelType, NamedType},
Schema,
};
extern crate alloc;
#[cfg_attr(docsrs, doc(cfg(any(feature = "alloc", feature = "use-std"))))]
impl<T: Schema> Schema for alloc::vec::Vec<T> {
const SCHEMA: &'static NamedType = &NamedType {
name: "Vec<T>",
ty: &DataModelType::Seq(T::SCHEMA),
};
}
#[cfg_attr(docsrs, doc(cfg(any(feature = "alloc", feature = "use-std"))))]
impl Schema for alloc::string::String {
const SCHEMA: &'static NamedType = &NamedType {
name: "String",
ty: &DataModelType::String,
};
}
#[cfg_attr(docsrs, doc(cfg(any(feature = "alloc", feature = "use-std"))))]
impl<K: Schema, V: Schema> Schema for alloc::collections::BTreeMap<K, V> {
const SCHEMA: &'static NamedType = &NamedType {
name: "BTreeMap<K, V>",
ty: &DataModelType::Map {
key: K::SCHEMA,
val: V::SCHEMA,
},
};
}
#[cfg_attr(docsrs, doc(cfg(any(feature = "alloc", feature = "use-std"))))]
impl<K: Schema> Schema for alloc::collections::BTreeSet<K> {
const SCHEMA: &'static NamedType = &NamedType {
name: "BTreeSet<K>",
ty: &DataModelType::Seq(K::SCHEMA),
};
}
#[cfg_attr(docsrs, doc(cfg(any(feature = "alloc", feature = "use-std"))))]
impl<T: Schema> Schema for alloc::collections::VecDeque<T> {
const SCHEMA: &'static NamedType = &NamedType {
name: "VecDeque<T>",
ty: &DataModelType::Seq(T::SCHEMA),
};
}
#[cfg_attr(docsrs, doc(cfg(any(feature = "alloc", feature = "use-std"))))]
impl<T: Schema> Schema for alloc::boxed::Box<T> {
const SCHEMA: &'static NamedType = &NamedType {
name: "Box<T>",
ty: T::SCHEMA.ty,
};
}
#[cfg_attr(docsrs, doc(cfg(any(feature = "alloc", feature = "use-std"))))]
impl<T: ?Sized + Schema + alloc::borrow::ToOwned> Schema for alloc::borrow::Cow<'_, T> {
const SCHEMA: &'static NamedType = &NamedType {
name: "Cow<'_, T>",
ty: T::SCHEMA.ty,
};
}
#[cfg_attr(docsrs, doc(cfg(any(feature = "alloc", feature = "use-std"))))]
impl<T: Schema> Schema for alloc::rc::Rc<T> {
const SCHEMA: &'static NamedType = &NamedType {
name: "Rc<T>",
ty: T::SCHEMA.ty,
};
}