Skip to content

Commit ead86b9

Browse files
authored
Merge pull request #233 from michael-p/schema-for-cow
Implement `Schema` for `Cow`
2 parents a83c294 + e64f767 commit ead86b9

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

source/postcard-schema/src/impls/builtins_alloc.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,25 +4,35 @@ use crate::{schema::DataModelType, Schema};
44

55
extern crate alloc;
66

7+
#[cfg_attr(docsrs, doc(cfg(any(feature = "alloc", feature = "use-std"))))]
78
impl<T: Schema> Schema for alloc::vec::Vec<T> {
89
const SCHEMA: &'static DataModelType = &DataModelType::Seq(T::SCHEMA);
910
}
1011

12+
#[cfg_attr(docsrs, doc(cfg(any(feature = "alloc", feature = "use-std"))))]
1113
impl Schema for alloc::string::String {
1214
const SCHEMA: &'static DataModelType = &DataModelType::String;
1315
}
1416

17+
#[cfg_attr(docsrs, doc(cfg(any(feature = "alloc", feature = "use-std"))))]
1518
impl<K: Schema, V: Schema> Schema for alloc::collections::BTreeMap<K, V> {
1619
const SCHEMA: &'static DataModelType = &DataModelType::Map {
1720
key: K::SCHEMA,
1821
val: V::SCHEMA,
1922
};
2023
}
2124

25+
#[cfg_attr(docsrs, doc(cfg(any(feature = "alloc", feature = "use-std"))))]
2226
impl<K: Schema> Schema for alloc::collections::BTreeSet<K> {
2327
const SCHEMA: &'static DataModelType = &DataModelType::Seq(K::SCHEMA);
2428
}
2529

30+
#[cfg_attr(docsrs, doc(cfg(any(feature = "alloc", feature = "use-std"))))]
2631
impl<T: Schema> Schema for alloc::boxed::Box<T> {
2732
const SCHEMA: &'static DataModelType = T::SCHEMA;
2833
}
34+
35+
#[cfg_attr(docsrs, doc(cfg(any(feature = "alloc", feature = "use-std"))))]
36+
impl<T: ?Sized + Schema + alloc::borrow::ToOwned> Schema for alloc::borrow::Cow<'_, T> {
37+
const SCHEMA: &'static DataModelType = T::SCHEMA;
38+
}

source/postcard-schema/src/impls/builtins_std.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,3 +47,8 @@ impl<K: Schema> Schema for std::collections::BTreeSet<K> {
4747
impl<T: Schema> Schema for std::boxed::Box<T> {
4848
const SCHEMA: &'static DataModelType = T::SCHEMA;
4949
}
50+
51+
#[cfg_attr(docsrs, doc(cfg(any(feature = "alloc", feature = "use-std"))))]
52+
impl<T: ?Sized + Schema + std::borrow::ToOwned> Schema for std::borrow::Cow<'_, T> {
53+
const SCHEMA: &'static DataModelType = T::SCHEMA;
54+
}

0 commit comments

Comments
 (0)