Skip to content

Instantly share code, notes, and snippets.

@thiagopnts
Last active August 29, 2015 14:12
Show Gist options
  • Save thiagopnts/717b6a4cde4a1c0961e1 to your computer and use it in GitHub Desktop.
Save thiagopnts/717b6a4cde4a1c0961e1 to your computer and use it in GitHub Desktop.
pub fn add_text(&mut self, text: &'static str) {
let re = regex!(r"\n");
let without_newline = re.replace_all(text, ".");
let seps = regex!("([.!?;:])");
let mut pieces = seps.split(without_newline.as_slice());
let mut sentence = "".to_string();
for piece in pieces {
if piece != "" {
sentence = match seps.find(piece) {
Some(_) => {
self.add_sentence(sentence.as_slice(), piece);
"".to_string()
},
None => piece.to_string(),
};
}
}
}
// 54:37: 54:52 error: `without_newline` does not live long enough
// /Users/thiago/code/bot/src/markov_chain.rs:54 let mut pieces = seps.split(without_newline.as_slice());
// ^~~~~~~~~~~~~~~
// note: reference must be valid for the static lifetime...
// /Users/thiago/code/bot/src/markov_chain.rs:49:52: 68:6 note: ...but borrowed value is only valid for the block at 49:51
// /Users/thiago/code/bot/src/markov_chain.rs:49 pub fn add_text(&mut self, text: &'static str) {
// /Users/thiago/code/bot/src/markov_chain.rs:50 let re = regex!(r"\n");
// /Users/thiago/code/bot/src/markov_chain.rs:51 let without_newline = re.replace_all(text, ".");
// /Users/thiago/code/bot/src/markov_chain.rs:52
// /Users/thiago/code/bot/src/markov_chain.rs:53 let seps = regex!("([.!?;:])");
// /Users/thiago/code/bot/src/markov_chain.rs:54 let mut pieces = seps.split(without_newline.as_slice());
// ...
// /Users/thiago/code/bot/src/markov_chain.rs:61:43: 61:51 error: `sentence` does not live long enough
// /Users/thiago/code/bot/src/markov_chain.rs:61 self.add_sentence(sentence.as_slice(), piece);
// ^~~~~~~~
// note: reference must be valid for the static lifetime...
// /Users/thiago/code/bot/src/markov_chain.rs:49:52: 68:6 note: ...but borrowed value is only valid for the block at 49:51
// /Users/thiago/code/bot/src/markov_chain.rs:49 pub fn add_text(&mut self, text: &'static str) {
// /Users/thiago/code/bot/src/markov_chain.rs:50 let re = regex!(r"\n");
// /Users/thiago/code/bot/src/markov_chain.rs:51 let without_newline = re.replace_all(text, ".");
// /Users/thiago/code/bot/src/markov_chain.rs:52
// /Users/thiago/code/bot/src/markov_chain.rs:53 let seps = regex!("([.!?;:])");
// /Users/thiago/code/bot/src/markov_chain.rs:54 let mut pieces = seps.split(without_newline.as_slice());
// ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment