Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RFC: Add std::net::MacAddr48 to std::net #2082

Closed
wants to merge 6 commits into from
Closed

RFC: Add std::net::MacAddr48 to std::net #2082

wants to merge 6 commits into from

Conversation

stephanbuys
Copy link

Having worked with networking code in Rust for a couple of months now, I was inspired to write this RFC after encountering yet another implementation of MAC addresses in diesel.rs :-)

This RFC proposes that a datatype MacAddr48 be added to the standard library so that this common type of networking data can be handled easily and predictably between crates.

Rendered

@scottmcm scottmcm added the T-libs-api Relevant to the library API team, which will review and decide on the RFC. label Jul 27, 2017
# Detailed design
[design]: #detailed-design

It is proposed that the existing `crate` `eui48` be used (http://crate.io/eui48) as a basis for this RFC, thus the code below is copied directly from that implementation.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed, thanks for pointing it out.

@joshtriplett
Copy link
Member

The alternative of

Promote of bless a standard crate for MAC addresses and spread the word to the large crates (such as diesel, libpnet, etc) and attempt to convince them to use it.
seems quite compelling, and I'm not sure a type for this is wildly more "findable" in the standard library than in a crate. Have you attempted to get these large crates to consolidate around an existing crate and its type? What's the advantage of putting this in the standard library?

Also, there exist both EUI-48 and EUI-64 addresses; does it make sense to have a type for one and not the other?


Currently there is no standard way to communicate physical (or ethernet) addresses when doing network related development in rust, even though `std::net::IpAddrV4` and `std::net::IpAddrV6` exist. The MAC address is, however, a regularly occurring data-structure when doing any type of network related development.

There is also a proliferation of implementations which are not compatible with each other, forcing developers to manually implement the data type again and again, reducing the opportunity for code re-use and convenience. `nom`[1], `libpnet`[2] and `diesel`[3] being a couple of examples.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This exact argument applies equally to dozens if not hundreds of types. If I took this this RFC and find/replaced MacAddr48 with Uuid or Path or Polygon or Rgb or Rgba or Netmask or Quaternion or Matrix or Vector or TraceId and what would change? Libstd should not be the dumping ground for every possible type that could exist.

The IpAddr types are defined in the standard library because they're used in networking APIs. MacAddr48 on the other hand would be an orphaned type which interacts with nothing.

Copy link
Member

@eddyb eddyb Jul 28, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The best (IMO) language design solution here is to support some subset of "cubical type-checking" (an implementation of Homotopy Type Theory), and allow users of multiple libraries to specify equivalences (bidirectional conversion functions, more or less) between the libraries' definitions of the same type, to allow them to be used interchangeably.

Although that might as well be a pipe dream, or there'd need to be some compromise and the compiler wouldn't check conversion preserves information, but trust the user instead.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@sfackler fair enough, is this a criteria for all types in the std lib? Perhaps there is an argument for the inclusion of that list of types you mentioned? As said in the RFC, I don't believe in exploding the std lib and creating a massive maintenance burden (although a bunch of those are kind of settled and should not need much maintenance/tweaking going forward), but I can also see an argument for more types in the std lib as a part of the whole rust usability drive this year.
To me, extended, standardized, type support could be seen as an enabler for:
Standardized, solid, types helps with integration into other languages (rust-lang/rust-roadmap-2017#14), definitely helps with writing robust (and scalable) servers (
rust-lang/rust-roadmap-2017#9) and pushes the quality of crates up through interoperability (rust-lang/rust-roadmap-2017#10).
There is no real reason to believe that each crate using the types you mentioned (and MacAddr48) would go to the trouble of implementing all the idiomatic conversion functions and Traits that can be expected/found in the current std lib.
I understand your argument, but perhaps a bit more consideration around the topic in general would be a good idea?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Based on this news: https://github.com/carllerche/http I would like to withdraw this RFC, perhaps the answer here is to rather get a quality network types library together and then rally around it's by lobbying authors of other crates. Thanks for considering it though!
Can I just go ahead and close it?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Having polled a couple of developers there is one concern about 'non-complex type' crates as an alternative. the http crate has immense value, and is packed full of consts and enums that would take any developer a lot of time to bootstrap.
Would people opt-in to 'bloating' their Cargo.toml files (and imports) just to have a re-usable simple type? MacAddr48 is just a [u8; 6] - as a coder it might just be simpler to do the latter than go to the trouble of finding a crate. To me this is an argument for inclusion in some sort of larger, standardized library, even if it isn't std itself?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@stephanbuys I'd want to use the common type if one of my dependencies did, or if I was aware of the common crate and it had useful functionality (e.g. helpful instances for comparison and pretty-printing).

@nagisa
Copy link
Member

nagisa commented Aug 1, 2017 via email

@stephanbuys
Copy link
Author

Ok, withdrawing this RFC, perhaps at a point in the future a collection of mature type crates with conversion/helper functions would be considered for consolidation and inclusion in std. Thanks for the feedback everyone.

@stephanbuys stephanbuys closed this Aug 3, 2017
@stephanbuys stephanbuys deleted the net-mac-address branch August 3, 2017 07:31
@stephanbuys stephanbuys restored the net-mac-address branch August 3, 2017 07:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
T-libs-api Relevant to the library API team, which will review and decide on the RFC.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants