Ad
  • Custom User Avatar

    @kazk It worked. Thanks for the explanations :)

  • Default User Avatar

    OK. Lot of thanks for your explanations and your work to fix that. I tried a solution without regex and it works!

  • Custom User Avatar

    @filosfino Can you try again? It should be fixed now.

    @g964
    I didn't realize this problem when a user can optionally use some crate and I don't think there's a way to completely fix it.
    The workaround was to bind to a different identifier.

    #[cfg(test)] extern crate regex as t_regex;
    #[cfg(test)]
    mod tests {
        use super::*;
        use t_regex::Regex;
    }
    

    You can also move extern crate inside mod tests and do use self::regex::Regex;. I don't know which one is better. If Rust users have opinions, please let me know.

    Another workaround might be to avoid use regex::Regex; and just do regex::Regex::new in the reference solution.

  • Custom User Avatar
  • Custom User Avatar

    OK, I'll try and let you know.

  • Default User Avatar

    I am lost:-( Maybe it would be better if you fix it!

  • Custom User Avatar

    @g964 I think it validated because your solution contains the declaration.
    To use crates in test, do

    #[cfg(test)]
    extern crate regex; // <- outside of `mod tests`
    
    #[cfg(test)]
    mod tests {
    }
    

    I'll try fixing it if you want.

  • Custom User Avatar

    @filosfino

    See Rust wiki page for the list of crates.

    For self::, it's because Rust 1.15 is a huge hack on Codewars for historical reasons. It's fixed on 1.25/1.33. See List of Rust 1.15 kata to update. (this was caused by invalid test code)

  • Default User Avatar

    I will try again...
    Sorry for the inconvenience!

  • Custom User Avatar

    Check this one :) BTW is there any document specifying how the crates could be used in the answer?

    error[E0432]: unresolved import regex
    --> src/lib.rs:25:9
    |
    25 | use regex::Regex;
    | ^^^^^ did you mean self::regex?

  • Default User Avatar

    Fixed, thanks!

  • Custom User Avatar

    This comment is hidden because it contains spoiler information about the solution

  • Custom User Avatar

    (Rust) use usize as return type instead of u8