Skip to content

Instantly share code, notes, and snippets.

@dandavison
Last active April 11, 2020 16:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dandavison/14284c814ba8fecb2543d556d0a2dacf to your computer and use it in GitHub Desktop.
Save dandavison/14284c814ba8fecb2543d556d0a2dacf to your computer and use it in GitHub Desktop.
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