Skip to content

Commit

Permalink
Add Range structs to schema
Browse files Browse the repository at this point in the history
  • Loading branch information
ChocolateLoverRaj committed Dec 3, 2024
1 parent 109c223 commit 7c6fd97
Showing 1 changed file with 59 additions and 4 deletions.
63 changes: 59 additions & 4 deletions source/postcard-schema/src/impls/builtins_nostd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,15 @@
//! These implementations are always available
use crate::{
schema::{DataModelType, DataModelVariant, NamedType, NamedVariant},
schema::{DataModelType, DataModelVariant, NamedType, NamedValue, NamedVariant},
Schema,
};
use core::num::{
NonZeroI128, NonZeroI16, NonZeroI32, NonZeroI64, NonZeroI8, NonZeroU128, NonZeroU16,
NonZeroU32, NonZeroU64, NonZeroU8,
use core::{
num::{
NonZeroI128, NonZeroI16, NonZeroI32, NonZeroI64, NonZeroI8, NonZeroU128, NonZeroU16,
NonZeroU32, NonZeroU64, NonZeroU8,
},
ops::{Range, RangeFrom, RangeInclusive, RangeTo},
};

macro_rules! impl_schema {
Expand Down Expand Up @@ -100,3 +103,55 @@ impl<T: Schema, const N: usize> Schema for [T; N] {
ty: &DataModelType::Tuple(&[T::SCHEMA; N]),
};
}

impl<T: Schema> Schema for Range<T> {
const SCHEMA: &'static crate::schema::NamedType = &NamedType {
name: "Range<T>",
ty: &DataModelType::Struct(&[
&NamedValue {
name: "start",
ty: T::SCHEMA,
},
&NamedValue {
name: "end",
ty: T::SCHEMA,
},
]),
};
}

impl<T: Schema> Schema for RangeInclusive<T> {
const SCHEMA: &'static crate::schema::NamedType = &NamedType {
name: "RangeInclusive<T>",
ty: &DataModelType::Struct(&[
&NamedValue {
name: "start",
ty: T::SCHEMA,
},
&NamedValue {
name: "end",
ty: T::SCHEMA,
},
]),
};
}

impl<T: Schema> Schema for RangeFrom<T> {
const SCHEMA: &'static crate::schema::NamedType = &NamedType {
name: "RangeFrom<T>",
ty: &DataModelType::Struct(&[&NamedValue {
name: "start",
ty: T::SCHEMA,
}]),
};
}

impl<T: Schema> Schema for RangeTo<T> {
const SCHEMA: &'static crate::schema::NamedType = &NamedType {
name: "RangeTo<T>",
ty: &DataModelType::Struct(&[&NamedValue {
name: "end",
ty: T::SCHEMA,
}]),
};
}

0 comments on commit 7c6fd97

Please # to comment.