Skip to content

Instantly share code, notes, and snippets.

@lffg
Last active December 17, 2021 23:55
Show Gist options
  • Select an option

  • Save lffg/52d38c2ad49fe68ab341785a19137827 to your computer and use it in GitHub Desktop.

Select an option

Save lffg/52d38c2ad49fe68ab341785a19137827 to your computer and use it in GitHub Desktop.
let source: &str = todo!("get some string slice here");
// A função `strip_prefix` retorna `Some` contendo o resto da string sem o prefixo se ele existir.
// Se não tiver o prefixo, retorna `None` (análogo ao `false` da outra função).
// Ver: https://doc.rust-lang.org/std/primitive.slice.html#method.strip_prefix
if let Some(tail) = source.strip_prefix(':') {
let cmd: Vec<_> = tail // Agora não preciso mais utilizar um range para remover o prefixo.
.split_ascii_whitespace()
.filter(|s| !s.is_empty())
.collect();
// use `cmd` here
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment