Skip to content

Commit 92a6bfb

Browse files
caspermeijnsirhcel
authored andcommitted
feat: Add integration with schemars
Integrate with `schemars`, which allows to generate a JSON schema for a `serde` generated JSON file. A v1 of `schemars` is in the works, but that will take some months. It seems the derive API will not change.
1 parent c5b1304 commit 92a6bfb

File tree

2 files changed

+9
-0
lines changed

2 files changed

+9
-0
lines changed

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ features = [
4747
cfg-if = "1.0.0"
4848
scopeguard = "1.1"
4949
serde = { version = "1.0", features = ["derive"], optional = true }
50+
schemars = { package = "schemars", version = "0.8", features = ["derive"], optional = true }
5051

5152
[dev-dependencies]
5253
assert_hex = "0.4.1"

src/lib.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,7 @@ impl From<Error> for io::Error {
139139
/// Number of bits per character
140140
#[derive(Debug, Copy, Clone, PartialEq, Eq)]
141141
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
142+
#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
142143
pub enum DataBits {
143144
/// 5 bits per character
144145
Five,
@@ -200,6 +201,7 @@ impl TryFrom<u8> for DataBits {
200201
/// transmitted.
201202
#[derive(Debug, Copy, Clone, PartialEq, Eq)]
202203
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
204+
#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
203205
pub enum Parity {
204206
/// No parity bit.
205207
None,
@@ -226,6 +228,7 @@ impl fmt::Display for Parity {
226228
/// Stop bits are transmitted after every character.
227229
#[derive(Debug, Copy, Clone, PartialEq, Eq)]
228230
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
231+
#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
229232
pub enum StopBits {
230233
/// One stop bit.
231234
One,
@@ -267,6 +270,7 @@ impl TryFrom<u8> for StopBits {
267270
/// Flow control modes
268271
#[derive(Debug, Copy, Clone, PartialEq, Eq)]
269272
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
273+
#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
270274
pub enum FlowControl {
271275
/// No flow control.
272276
None,
@@ -306,6 +310,7 @@ impl FromStr for FlowControl {
306310
/// [`clear`]: trait.SerialPort.html#tymethod.clear
307311
#[derive(Debug, Copy, Clone, PartialEq, Eq)]
308312
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
313+
#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
309314
pub enum ClearBuffer {
310315
/// Specify to clear data received but not read
311316
Input,
@@ -799,6 +804,7 @@ impl fmt::Debug for dyn SerialPort {
799804
/// Contains all possible USB information about a `SerialPort`
800805
#[derive(Clone, PartialEq, Eq)]
801806
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
807+
#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
802808
pub struct UsbPortInfo {
803809
/// Vendor ID
804810
pub vid: u16,
@@ -840,6 +846,7 @@ impl std::fmt::Debug for UsbPortInfo {
840846
/// The physical type of a `SerialPort`
841847
#[derive(Debug, Clone, PartialEq, Eq)]
842848
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
849+
#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
843850
pub enum SerialPortType {
844851
/// The serial port is connected via USB
845852
UsbPort(UsbPortInfo),
@@ -854,6 +861,7 @@ pub enum SerialPortType {
854861
/// A device-independent implementation of serial port information
855862
#[derive(Debug, Clone, PartialEq, Eq)]
856863
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
864+
#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
857865
pub struct SerialPortInfo {
858866
/// The short name of the serial port
859867
pub port_name: String,

0 commit comments

Comments
 (0)