`clean_number` inside the function `clean` is destructed, and a slice into the 
destructed String is returned. You’re probably looking for the `MaybeOwned` 
enum in the standard library to do what you want:





http://is.gd/QvkESn




Regards,

  - Clark

On Mon, Oct 20, 2014 at 12:57 PM, Jake Scott <jake....@gmail.com> wrote:

> 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();
> }
_______________________________________________
Rust-dev mailing list
Rust-dev@mozilla.org
https://mail.mozilla.org/listinfo/rust-dev

Reply via email to