krisprice / ipnet

IpNet, Ipv4Net, and Ipv6Net types and methods for Rust
Apache License 2.0
122 stars 26 forks source link

Please derive/implement Default trait #18

Closed imp closed 4 years ago

imp commented 4 years ago

The types in this crate are very useful and practical. The life of the consumers may be even easier if these types will be implementing Default trait. We are using these types as a part of a complex structures where Default is required. Right now it forces us to implement it manually instead of deriving.

krisprice commented 4 years ago

Hi @imp, is Default implemented for all the underlying traits already? If not what are you thinking the default should be, presumably 0/0 and ::/0?

imp commented 4 years ago

Yes, I believe zeroes should be fine. Anything else would be very much opinionated. Those who care will set it to whatever they need, those who don't care - well, just don't care.

And that's for structs, right? Not traits?

imp commented 4 years ago

Something like this - #19

krisprice commented 4 years ago

Thanks, my next question was going to be do you want to send me a pull request for it :-) Just for completeness, are you able to add some simple tests for your default implementation. Then I'll go ahead and merge it.

imp commented 4 years ago

Added tests.

imp commented 4 years ago

BTW, some files are with DOS EOL (CRLF), while others are UNIX (LF). This confuses editors and causes gratuitous reformatting.

> file src/*
src/ipext.rs:       ASCII text, with CRLF line terminators
src/ipnet.rs:       ASCII text, with CRLF line terminators
src/ipnet_serde.rs: c program text, ASCII text
src/lib.rs:         c program text, ASCII text
src/parser.rs:      ASCII text, with CRLF line terminators

Would you accept a PR to reformat all the files to LF line ending?

krisprice commented 4 years ago

Absolutely, your PRs are very much welcomed.

imp commented 4 years ago

Thanks! #19 has been updated.

krisprice commented 4 years ago

Merged into 2.3.0.