-
Notifications
You must be signed in to change notification settings - Fork 11
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
improve docs #15
improve docs #15
Conversation
README.md
Outdated
assert_eq!(true, cidr.contains(IpAddr::from_str("192.168.51.103").unwrap())); | ||
assert_eq!(false, cidr.contains(IpAddr::from_str("192.168.50.103").unwrap())); | ||
assert_eq!(true, cidr.contains(IpAddr::from([192, 168, 51, 103]))); | ||
assert_eq!(false, cidr.contains(IpAddr::from([192, 168, 50, 103]))); | ||
``` |
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.
Why not use from_str
?
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.
examples should be clean and concise
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.
removed this particular change from this PR
README.md
Outdated
@@ -160,7 +160,7 @@ Enable the `serde` feature to support the serde framework. | |||
|
|||
```toml | |||
[dependencies.cidr-utils] | |||
version = "*" |
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.
I prefer using *
. Dot-dot-dot is not in correct format.
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.
Encouraging use of *
is dangerous. Using the "wrong" format requires users to select the version properly.
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.
Sometimes I just want to copy-paste and run, and see what happens. I don't want to make an extra effort to correct the format.
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.
My experience with helping Rust newcomers is that this is a real footgun. Regardless, I've dropped this commit.
src/cidr/ip_cidr.rs
Outdated
@@ -17,6 +17,7 @@ pub enum IpCidr { | |||
|
|||
impl IpCidr { | |||
#[allow(clippy::should_implement_trait)] | |||
#[doc(hidden)] // TODO: remove and rely on std FromStr |
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.
Is this function necessary to be hidden?
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.
We should encourage use of the FromStr trait. If a breaking change were acceptable, I'd say to make this fn private. Hiding it is an alternative that is backwards compatible.
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.
It is more convenient that a type has from_str
itself. We don't need to add the use std::str::FromStr
statement every time.
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.
Using str::parse()
is the recommended method, not FromStr
, which is why it's not in the std prelude.
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.
removed this particular change from this PR
src/cidr/ip_cidr_iterators.rs
Outdated
@@ -62,6 +62,8 @@ impl DoubleEndedIterator for IpCidrIpAddrIterator { | |||
} | |||
|
|||
impl IpCidr { | |||
#[doc(hidden)] | |||
#[deprecated(note = "Prefer `.iter()`.")] |
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.
The reason why this function is named iter_as ip_addr
is to be consistent with Ipv4Cidr::iter_as_ipv4_addr
and Ipv6Cidr::iter_as_ipv6_addr
.
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.
fair enough, reverted
src/cidr/v4/ipv4_cidr.rs
Outdated
@@ -28,8 +28,9 @@ pub struct Ipv4Cidr { | |||
} | |||
|
|||
impl Ipv4Cidr { | |||
/// Returns an integer which represents the prefix an IPv4 byte array of this CIDR in big-endian | |||
/// (BE) order. |
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.
I prefer not to wrap comments.
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.
You don't want them wrapped at all, even for extremely long lines?
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.
If the comment line is extremely long, I will wrap it by myself instead of tools,
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.
up to you, I unwrapped these long lines
src/cidr/v4/ipv4_cidr.rs
Outdated
} | ||
|
||
#[inline] | ||
pub fn get_bits(&self) -> u8 { | ||
mask_to_bits(self.mask).unwrap() | ||
} | ||
|
||
/// Returns an integer which represents the mask an IPv4 byte array of this CIDR in big-endian | ||
/// (BE) order. |
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.
I prefer not to wrap comments.
src/cidr/v4/ipv4_cidr.rs
Outdated
@@ -111,6 +109,7 @@ impl Ipv4Cidr { | |||
} | |||
|
|||
#[allow(clippy::should_implement_trait)] | |||
#[doc(hidden)] // TODO: remove and rely on std FromStr |
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.
Is this function necessary to be hidden?
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.
removed this particular change from this PR
@@ -229,7 +243,7 @@ impl Ipv4Cidr { | |||
|
|||
impl Debug for Ipv4Cidr { | |||
#[inline] | |||
fn fmt(&self, f: &mut Formatter) -> Result<(), fmt::Error> { | |||
fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), fmt::Error> { |
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.
Why we need to add <'_>
explicitly?
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.
It's part of the rust_2018_idioms
lint, omitting this anon lifetime will be a hard error in the future.
src/cidr/v6/ipv6_cidr.rs
Outdated
@@ -123,6 +119,7 @@ impl Ipv6Cidr { | |||
} | |||
|
|||
#[allow(clippy::should_implement_trait)] | |||
#[doc(hidden)] // TODO: remove and rely on std FromStr |
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.
Is this function necessary to be hidden?
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.
removed this particular change from this PR
src/lib.rs
Outdated
@@ -49,8 +49,8 @@ use cidr_utils::cidr::IpCidr; | |||
|
|||
let cidr = IpCidr::from_str("192.168.51.0/24").unwrap(); | |||
|
|||
assert_eq!(true, cidr.contains(IpAddr::from_str("192.168.51.103").unwrap())); | |||
assert_eq!(false, cidr.contains(IpAddr::from_str("192.168.50.103").unwrap())); |
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.
Why not use from_str
?
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.
removed this particular change from this PR
src/lib.rs
Outdated
@@ -158,12 +158,16 @@ Enable the `serde` feature to support the serde framework. | |||
|
|||
```toml | |||
[dependencies.cidr-utils] | |||
version = "*" | |||
version = "..." |
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.
I prefer using *
. Dot-dot-dot is not in correct format.
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.
removed this particular change from this PR
#![deny(rust_2018_idioms, nonstandard_style)] | ||
#![warn(future_incompatible)] | ||
#![cfg_attr(docsrs, feature(doc_auto_cfg))] | ||
|
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.
Why we need to add these?
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.
They provide good defaults for contributors and encourage better code style.
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.
Why fn fmt(&self, f: &mut Formatter<'_>)
is better than fn fmt(&self, f: &mut Formatter)
?
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.
Because hidden lifetimes are harmful to comprehension. These lints are likely to become errors in a future edition.
c392714
to
b107976
Compare
95a3389
to
f7adf2d
Compare
f7adf2d
to
fadab2f
Compare
Improves docs on a large portion of methods on
IpCidr
,Ipv4Cidr
, andIpv6Cidr
. Tries to adhere to standard rustdoc grammar and formatting guidelines including using imperative mood for first line of function docs.Also includes some trivial code quality improvements. No changes to public API have been made.