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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add const unsafe new_unchecked to Ipv4Network & Ipv6Network #185

Merged
merged 2 commits into from Dec 21, 2023

Conversation

aurelilys
Copy link
Contributor

Hello 馃槂

I've encountered a problem using your crate, when I want to define an &[Ipv4Network], I'm not able to get the result, unwrap() is not marked as const. One of the solutions I've found would be to introduce two new new_unchecked functions for Ipv4Network and Ipv6Network. This would make it possible to:

const TEST: &[Ipv4Network] = unsafe {
    &[
        Ipv4Network::new_unchecked(Ipv4Addr::new(127, 0, 0, 0), 8),
        Ipv4Network::new_unchecked(Ipv4Addr::new(10, 0, 0, 0), 8),
    ]
};

@achanda
Copy link
Owner

achanda commented Dec 20, 2023

Thank, this is interesting. Is it possible for you to add some tests please?

@aurelilys
Copy link
Contributor Author

Yes, of course, here are two tests added.

@achanda achanda merged commit a1966d4 into achanda:master Dec 21, 2023
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants