Skip to content

Commit

Permalink
Improve doc and comments
Browse files Browse the repository at this point in the history
  • Loading branch information
yescallop committed Jun 8, 2024
1 parent d145acc commit db4cde7
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 12 deletions.
23 changes: 14 additions & 9 deletions src/encoding/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -381,8 +381,10 @@ impl EStr<Path> {

/// Returns an iterator over the [path segments].
///
/// See the following examples for the exact behavior of this method.
///
/// The returned iterator does **not** uniquely identify a path
/// because it does not output the empty string before a preceding `'/'`.
/// because it does not output the empty string before a leading `'/'`.
/// You may need to check whether the path is [absolute] in addition to calling this method.
///
/// [path segments]: https://datatracker.ietf.org/doc/html/rfc3986/#section-3.3
Expand All @@ -393,18 +395,21 @@ impl EStr<Path> {
/// ```
/// use fluent_uri::Uri;
///
/// // An empty path has no segments.
/// let uri = Uri::parse("")?;
/// assert_eq!(uri.path().segments().next(), None);
///
/// // Segments are separated by '/'.
/// let uri = Uri::parse("a/b/c")?;
/// assert!(uri.path().segments().eq(["a", "b", "c"]));
///
/// // The empty string before a preceding '/' is not a segment.
/// // The empty string before a leading '/' is not a segment.
/// // However, segments can be empty in the other cases.
/// let uri = Uri::parse("/path/to//dir/")?;
/// assert!(uri.path().segments().eq(["path", "to", "", "dir", ""]));
///
/// // Segments of an absolute path may equal those of a rootless path.
/// let uri_a = Uri::parse("/foo/bar")?;
/// let uri_b = Uri::parse("foo/bar")?;
/// assert!(uri_a.path().segments().eq(["foo", "bar"]));
/// assert!(uri_b.path().segments().eq(["foo", "bar"]));
///
/// // An empty path has no segments.
/// let uri = Uri::parse("")?;
/// assert_eq!(uri.path().segments().next(), None);
/// # Ok::<_, fluent_uri::error::ParseError>(())
/// ```
#[inline]
Expand Down
2 changes: 1 addition & 1 deletion src/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ impl<'a> Reader<'a> {
match self.read_v6_segment() {
Some(Seg::Normal(seg, colon)) => {
if colon == (i == 0 || i == ellipsis_i) {
// Preceding colon, triple colons, or no colon.
// Leading colon, triple colons, or no colon.
return None;
}
segs[i] = seg;
Expand Down
4 changes: 2 additions & 2 deletions tests/parse_ip.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ fn test_parse_v4() {
// octal zero
assert!(parse_v4("255.0.0.00").is_none());
assert!(parse_v4("255.0.00.0").is_none());
// preceding dot
// leading dot
assert!(parse_v4(".0.0.0.0").is_none());
// trailing dot
assert!(parse_v4("0.0.0.0.").is_none());
Expand Down Expand Up @@ -103,7 +103,7 @@ fn test_parse_v6() {
assert!(parse_v6("::1:2:3:4:5:6:7:8").is_none());
assert!(parse_v6("1:2:3:4::5:6:7:8").is_none());
assert!(parse_v6("1:2:3:4:5:6:7:8::").is_none());
// preceding colon
// leading colon
assert!(parse_v6(":1:2:3:4:5:6:7:8").is_none());
assert!(parse_v6(":1::1").is_none());
assert!(parse_v6(":1").is_none());
Expand Down

0 comments on commit db4cde7

Please sign in to comment.