Comments (6)
It would also be possible to do this with
#[cfg_attr(
feature = "serde",
derive(serde::Serialize, serde::Deserialize),
serde(untagged)
)]
pub enum Register {
/// A single register.
Single {
/// Register information
info: RegisterInfo,
},
/// An array of registers.
Array {
/// Register information
info: RegisterInfo,
/// Array dim
dim: DimElement,
},
}
I wonder which one is the best
from svd.
It would also be possible to do this with
#[cfg_attr( feature = "serde", derive(serde::Serialize, serde::Deserialize), serde(untagged) )] pub enum Register { /// A single register. Single { /// Register information info: RegisterInfo, }, /// An array of registers. Array { /// Register information info: RegisterInfo, /// Array dim dim: DimElement, }, }I wonder which one is the best
Unfortunately the result is different from I expect.
Left - untagged, right - current
from svd.
I can take identical result with:
#[derive(Clone, Debug, PartialEq)]
#[cfg_attr(
feature = "serde",
derive(serde::Serialize, serde::Deserialize),
serde(untagged)
)]
pub enum Register {
/// A single register.
Single(RegisterInfo),
/// An array of registers.
Array(RegisterArray),
}
#[derive(Clone, Debug, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
/// ...
pub struct RegisterArray {
#[cfg_attr(feature = "serde", serde(flatten))]
/// ...
pub dim: DimElement,
#[cfg_attr(feature = "serde", serde(flatten))]
/// ...
pub info: RegisterInfo,
}
But does this make sense?
from svd.
Let's just merge #173 instead.
from svd.
The reason for the difference is the ordering, placing dim before info in the enum struct would solve that.
from svd.
Ah, my bad, I see the issue now. Too bad, I dont think there is a good way to solve this with current serde features
from svd.
Related Issues (20)
- Serde: custom (de)serializers
- should we support dataType?
- custom serializer for WriteConstraint
- deserialize bugs
- remove submodule, add & rework tests
- add expanding default_register_properties
- `svd-parser` doesn't extract `noNamespaceSchemaLocation` correctly
- dimIndexType support for [A-Z]-[A-Z] pattern HOT 2
- check <size> tag
- Unknown access variant 'read-write ' found HOT 7
- [svd_parser]: Tags that contain a XML comment are ignored.
- 0.15 roadmap HOT 1
- Check writeConstraint range
- M302: Size of Register must be 8, 16 or 32 Bits HOT 8
- allow `isDefault` to have optional `value` HOT 10
- do validation when parsing serde yaml/json HOT 3
- reject duplicate fields HOT 2
- svd-parser v0.14.3 fails to compile with svd-rs version v0.14.2 and v0.14.3 HOT 2
- Incorrect "out of range" values displayed with <enumeratedValue> HOT 10
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from svd.