Comments (3)
Recursive update seems like a good thing to add. Anyway, here is the "requires Clone + Copy and is really just a hack" code you can use:
#[derive(Debug, PartialEq, DekuRead, DekuWrite, Clone, Copy)]
struct IpAddr {
#[deku(update = "9")]
a: u8,
b: u8,
c: u8,
d: u8,
}
#[derive(Debug, PartialEq, DekuRead, DekuWrite)]
struct Container {
#[deku(update = "{ let mut a = self.ip_addr; a.update()?; a }")]
ip_addr: IpAddr,
}
from deku.
This works for this case, however I also have a Vec in the relevant structure, and for this to work it is required for IpAddr implement Clone and Copy, but Vec doesn't implement Copy, so it can't work. Is there a way to bypass it?
What I did was to simply implement my own update function on Container that calls the IpAddr update. Not sure why the update through Deku requires IpAddr to implement Copy when my own function doesn't (maybe because it accepts &mut self)
from deku.
deku
emits the following for updating, for my example:
impl DekuUpdate for Container {
fn update(&mut self) -> core::result::Result<(), ::deku::DekuError> {
use core::convert::TryInto;
self
.ip_addr = ({
let mut a = self.ip_addr;
a.update()?;
a
})
.try_into()?;
Ok(())
}
}
There isn't a reason that deku couldn't in the future support emitting this:
impl DekuUpdate for Container {
fn update(&mut self) -> core::result::Result<(), ::deku::DekuError> {
self.ip_addr.update()?;
Ok(())
}
}
Maybe allow an empty update
for this behavior? I'll admit I don't use the update
attribute much.
#[derive(Debug, PartialEq, DekuRead, DekuWrite)]
struct Container {
#[deku(update)]
ip_addr: IpAddr,
}
from deku.
Related Issues (20)
- Replacing indices with references during parsing.
- Under / over-sized buffer parsing HOT 5
- Enable MIRI testing
- Help passing context around HOT 1
- Revisit enum id & type
- How to properly debug Deku input data? HOT 4
- Seemingly nonsensical vector count/read_size error HOT 2
- Conditional DekuWrite HOT 3
- Error: Parse("Too much data") using custom readers HOT 1
- Cant "count" from Some(field) directly - need as_ref().unwrap() HOT 1
- Passing a struct in ctx creates opaque error HOT 7
- Doc request: update for structs
- How to access enum-struct members? HOT 4
- Assert for tuple enum HOT 1
- Working with elements of Vec<StructUsingDeku> to get sum of their byte-sizes HOT 4
- Weird parsing with `bool` and non-aligned data. HOT 4
- Is there a way to pad by a variable number of bytes? HOT 3
- Roll a release? HOT 12
- Performance of `read_all` and `count` HOT 2
- Ability to ignore excess bytes HOT 1
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 deku.