Skip to content
Snippets Groups Projects

Cleanup in `kernel::common::parse_ip`

Merged Jeremy Soller requested to merge stratact:master into master

Created by: stratact

Merge request reports

Loading
Loading

Activity

Filter activity
  • Approvals
  • Assignees & reviewers
  • Comments (from bots)
  • Comments (from users)
  • Commits & branches
  • Edits
  • Labels
  • Lock status
  • Mentions
  • Merge request status
  • Tracking
25 let mut b = 0;
26
27 26 // TODO: Username/Password syntax
28 for (n, c) in string.chars().enumerate() {
29 match c {
30 ':' | '/' => break,
31 _ => b += 1,
32 }
33 }
34
35 &string[..b + 1]
36
27 let pos = match string.find(':') {
28 Some(pos) => pos + 1,
29 None => match string.find('/') {
30 Some(pos) => pos + 1,
  • Jeremy Soller
    Jeremy Soller @jackpot51 started a thread on commit dd096a1d
  • 25 let mut b = 0;
    26
    27 26 // TODO: Username/Password syntax
    28 for (n, c) in string.chars().enumerate() {
    29 match c {
    30 ':' | '/' => break,
    31 _ => b += 1,
    32 }
    33 }
    34
    35 &string[..b + 1]
    36
    27 let pos = match string.find(':') {
    28 Some(pos) => pos + 1,
    29 None => match string.find('/') {
    30 Some(pos) => pos + 1,
    • Created by: stratact

      Alright, but is there a way to say, if the loop finishes we wouldn't be doing a &string[..b + 1]? That could mean a possible panic if : or / were not found.

  • Jeremy Soller
    Jeremy Soller @jackpot51 started a thread on commit dd096a1d
  • 25 let mut b = 0;
    26
    27 26 // TODO: Username/Password syntax
    28 for (n, c) in string.chars().enumerate() {
    29 match c {
    30 ':' | '/' => break,
    31 _ => b += 1,
    32 }
    33 }
    34
    35 &string[..b + 1]
    36
    27 let pos = match string.find(':') {
    28 Some(pos) => pos + 1,
    29 None => match string.find('/') {
    30 Some(pos) => pos + 1,
  • Jeremy Soller
    Jeremy Soller @jackpot51 started a thread on commit dd096a1d
  • 25 let mut b = 0;
    26
    27 26 // TODO: Username/Password syntax
    28 for (n, c) in string.chars().enumerate() {
    29 match c {
    30 ':' | '/' => break,
    31 _ => b += 1,
    32 }
    33 }
    34
    35 &string[..b + 1]
    36
    27 let pos = match string.find(':') {
    28 Some(pos) => pos + 1,
    29 None => match string.find('/') {
    30 Some(pos) => pos + 1,
  • Jeremy Soller
    Jeremy Soller @jackpot51 started a thread on commit dd096a1d
  • 25 let mut b = 0;
    26
    27 26 // TODO: Username/Password syntax
    28 for (n, c) in string.chars().enumerate() {
    29 match c {
    30 ':' | '/' => break,
    31 _ => b += 1,
    32 }
    33 }
    34
    35 &string[..b + 1]
    36
    27 let pos = match string.find(':') {
    28 Some(pos) => pos + 1,
    29 None => match string.find('/') {
    30 Some(pos) => pos + 1,
    • Created by: stratact

      Sure, just keep in mind to account for the possibility that if it can't find those two chars, the slice should be &string[..b], not &string[..b + 1], by which b is pretty much string.len() by the time the loop finishes.

    Please register or sign in to reply
    Loading