JulianSchmid / etherparse

A rust library for parsing ethernet & ethernet using protocols.
Apache License 2.0
299 stars 53 forks source link

Support partial default initialization with `Ipv4Header` & `TcpHeader` #50

Closed JulianSchmid closed 8 months ago

JulianSchmid commented 1 year ago

It would be nice if one could simply write:

let header = TcpHeader{
    source_port: 123,
    ns: true,
    ..Default::default()
};

But this currently causes a compile time error as both Ipv4Header as well as TcpHeader contain private fields. In both of structs cases these private fields contain a buffer for options as well as a length for how much of the buffer is filled.

We can get around this limitation by moving the buffers into their own types and making them public.

robs-zeynet commented 1 year ago

I agree that your proposal here is Better, but hopefully it doesn't block my workaround proposal I just pushed here:

https://github.com/JulianSchmid/etherparse/pull/66

Hope you're well!

JulianSchmid commented 1 year ago

Hi @robs-zeynet , support for Ipv4Header & TcpHeader default initialization have been merged to master already and also should be part of 0.14.0 .

JulianSchmid commented 1 year ago

I originally also wanted to include IpAuthHeader & Ipv6RawExtHeader as part of this issue. But in interest of getting a release out of the door I moved it into a separate issue: https://github.com/JulianSchmid/etherparse/issues/67

JulianSchmid commented 8 months ago

Implemented in https://github.com/JulianSchmid/etherparse/releases/tag/v0.14.0