Skip to content

Commit 28f6686

Browse files
committed
new: Add Cow.
1 parent c9c9ff6 commit 28f6686

3 files changed

Lines changed: 15 additions & 0 deletions

File tree

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# Changelog
22

3+
## Unreleased
4+
5+
#### 🚀 Updates
6+
7+
- Implement `Schematic` for `Cow`.
8+
39
## 0.19.5
410

511
#### 🚀 Updates

crates/schematic/tests/schematic_test.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#![allow(dead_code, deprecated)]
22

33
use schematic::Schematic;
4+
use std::borrow::Cow;
45
use std::collections::HashMap;
56

67
#[derive(Schematic)]
@@ -12,6 +13,7 @@ struct Basic<'a> {
1213
struct Multiple<'a, 'b> {
1314
pub name: &'a str,
1415
pub age: &'b u32,
16+
pub other: Cow<'a, str>,
1517
}
1618

1719
#[derive(Schematic)]

crates/types/src/lib.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ pub use structs::*;
2727
pub use tuples::*;
2828
pub use unions::*;
2929

30+
use std::borrow::Cow;
3031
use std::rc::Rc;
3132
use std::sync::Arc;
3233

@@ -83,6 +84,12 @@ impl<T: Schematic> Schematic for Arc<T> {
8384
}
8485
}
8586

87+
impl<T: Schematic + ToOwned + ?Sized> Schematic for Cow<'_, T> {
88+
fn build_schema(schema: SchemaBuilder) -> Schema {
89+
T::build_schema(schema)
90+
}
91+
}
92+
8693
impl<T: Schematic> Schematic for Option<T> {
8794
fn build_schema(mut schema: SchemaBuilder) -> Schema {
8895
schema.union(UnionType::new_any([schema.infer::<T>(), Schema::null()]))

0 commit comments

Comments
 (0)