de-vri-es / serial2-rs

Cross platform serial ports for Rust
Other
41 stars 10 forks source link

Feature Request: implement serde::Serialize and serde::Deserialize for configuration enums #11

Closed ajmcquilkin closed 7 months ago

ajmcquilkin commented 1 year ago

Thanks for your work on the repo! I'm using serial2 on a Tauri application, and I'm looking to allow users to configure a serial port over a JSON API. I would be looking to allow users to set the following fields via this API:

I'm imagining this could be possible via a serde feature on the crate. Happy to contribute to this if this isn't something the project has time to implement.

DanielJoyce commented 10 months ago

Serde also lets you define a surrogate of the struct, and use that to define serialization.

de-vri-es commented 9 months ago

Note that this is not easily possible with the current design: the Settings struct wraps a full termios struct on Unix and a DBC struct on Windows.

This contains a lot of un-exposed and platform specific settings. So it's basically not possible to make a Settings object out of thin air without having an actual serial port opened.

The idea behind this was to allow more easily exposing platform specific settings in the future.

de-vri-es commented 7 months ago

Support for serde was added to CharSize, StopBits, Parity and FlowControl with PR #19 and released in v0.2.9 (thanks @avocadochicken !).

Thats the best we can do since Settings itselfs wraps a raw OS settings object.

I hope this helps with your use case! You will need to enable the serde feature to use it.