Last active
April 11, 2020 16:20
-
-
Save dandavison/14284c814ba8fecb2543d556d0a2dacf to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fn prepare(line: &str) -> String { | |
if !line.is_empty() { | |
let mut line = line.chars(); | |
let prefix = line.next().unwrap(); | |
let output_line = line.collect::<String>(); | |
format!("{}{}", prefix, output_line) | |
} else { | |
"<empty line>".to_string() | |
} | |
} | |
pub fn main() { | |
let result = prepare("abcdefghijklmn"); | |
println!("{}", result); | |
// This example does work: it prints aábcdefghijklmn. | |
// However, when calling a function like prepare in the context of a larger | |
// project, the string returned from prepare is sometimes truncated on the | |
// right-hand side, in apparently unpredicatble locations, but always word | |
// boundaries of some sort. What mistake might I be making? | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment