Jake Scott
2014-10-20 19:57:43 UTC
Can someone give me a hand, I'm getting the following lifetime error:
error: clean_number does not live long enough
Short url: http://is.gd/VIzHMS
This is the code:
#![feature(phase)]
#[phase(plugin)]
extern crate regex_macros;
extern crate regex;
use regex::Regex;
static ALPHA_REGEX: Regex = regex!(r"[a-zA-Z]");
static NUMBER_REGEX: Regex = regex!(r"[^0-9]");
fn main() {
let number = number("ads(123) 456-7890");
println!("{}", number);
}
fn number<'a>(number: &'a str) -> &'a str {
let clean_number = clean(number);
clean_number
}
fn clean<'a>(number: &'a str) -> &'a str {
if ALPHA_REGEX.is_match(number) {
"0000000000";
}
let clean_number: String = NUMBER_REGEX.replace(number, "");
return clean_number.as_slice();
}
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/rust-dev/attachments/20141021/b00f2bc8/attachment.html>
error: clean_number does not live long enough
Short url: http://is.gd/VIzHMS
This is the code:
#![feature(phase)]
#[phase(plugin)]
extern crate regex_macros;
extern crate regex;
use regex::Regex;
static ALPHA_REGEX: Regex = regex!(r"[a-zA-Z]");
static NUMBER_REGEX: Regex = regex!(r"[^0-9]");
fn main() {
let number = number("ads(123) 456-7890");
println!("{}", number);
}
fn number<'a>(number: &'a str) -> &'a str {
let clean_number = clean(number);
clean_number
}
fn clean<'a>(number: &'a str) -> &'a str {
if ALPHA_REGEX.is_match(number) {
"0000000000";
}
let clean_number: String = NUMBER_REGEX.replace(number, "");
return clean_number.as_slice();
}
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/rust-dev/attachments/20141021/b00f2bc8/attachment.html>