-
Notifications
You must be signed in to change notification settings - Fork 20
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
Remove ipnetwork
from public API
#123
base: main
Are you sure you want to change the base?
Conversation
Export custom `IpNetwork` type instead. This will allow upgrading the `ipnetwork` crate to not be a breaking change.
665d967
to
eb2048f
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reviewed 7 of 7 files at r1, all commit messages.
Reviewable status: complete! all files reviewed, all discussions resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reviewable status: all files reviewed, 1 unresolved discussion (waiting on @MarkusPettersson98)
src/rule/ip.rs
line 48 at r1 (raw file):
impl IpNetwork { pub fn new(ip: impl Into<IpAddr>, prefix: u8) -> IpNetwork { Self::new_checked(ip.into(), prefix).unwrap()
I wonder if we really need the unchecked version. I think the constructor requiring an explicit unwrap is a bit nicer.
|
By having Alternative solutions to this problem are welcome 😊 |
The only solution that I can think of is to set the dependency to |
For those who are interested the problem is better articulated in this RFC: https://rust-lang.github.io/rfcs/1977-public-private-dependencies.html |
This PR tries to address a painpoint of maintaining
pfctl
: Upgradingipnetwork
is considered a breaking change becauseipnetwork
is part of the public API.The upcoming release will bump the
ipnetwork
crate anyway, so lets take the opportunity to changepfctl
such that the dependency onipnetwork
just becomes an implementation detail that any library consumer doesn't have to worry about.To solve this issue, I used the newtype pattern to expose an
IpNetwork
type thatpfctl
owns. To make the migration straightforward, I gave the new type the same name as the equivalent type in theipnetwork
crate, and I even relaxed the constructor a bit while adding more constructors for useconst
contexts.TODO
pfctl
codeIpNetwork
has to be exposed at all, of if we can get away by only exposing theIp
data typeIpNetwork
constructors - which one do we want / need?This change is