fn parse_filename(filename: &str) -> Result<MigrationFile> {
    let re = Regex::new(
        r"^(?P<number>[0-9]{4})\.(?P<name>[_0-9a-zA-Z]*)\.(?P<direction>up|down)\.sql$"
    ).unwrap();

    let caps = match re.captures(filename) {
        None => bail!("File {} has an invalid filename", filename),
        Some(c) => c
    };

    // Unwrapping below should be safe (in theory)
    let number = caps.name("number").unwrap().as_str().parse::<i32>().unwrap();
    let name = caps.name("name").unwrap().as_str();
    let direction = if caps.name("direction").unwrap().as_str() == "up" {
        Direction::Up
    } else {
        Direction::Down
    };

    Ok(MigrationFile::new(filename, name, number, direction))
}
/// Gets a filename and check whether it's a valid format.
/// If it is, grabs all the info from it
Gets a filename and check whether it's a valid format.
If it is, grabs all the info from it
Gets a filename and check whether it ' s a valid format . If it is grabs all the info from it
fn parse_filename(filename: &str) -> Result<MigrationFile> {
    let re = Regex::new(
        r"^(?P<number>[0-9]{4})\.(?P<name>[_0-9a-zA-Z]*)\.(?P<direction>up|down)\.sql$"
    ).unwrap();
    let caps = match re.captures(filename) {
        None => bail!("File {} has an invalid filename", filename),
        Some(c) => c
    };
    // Unwrapping below should be safe (in theory)
    let number = caps.name("number").unwrap().as_str().parse::<i32>().unwrap();
    let name = caps.name("name").unwrap().as_str();
    let direction = if caps.name("direction").unwrap().as_str() == "up" {
        Direction::Up
    } else {
        Direction::Down
    };
    Ok(MigrationFile::new(filename, name, number, direction))
}
fn parse_filename ( filename : & str ) -> Result < MigrationFile > { let re = Regex :: new ( r"^(?P<number>[0-9]{4})\.(?P<name>[_0-9a-zA-Z]*)\.(?P<direction>up|down)\.sql$" ) . unwrap ( ) ; let caps = match re . captures ( filename ) { None => bail ! ( " " filename ) , Some ( c ) => c } ; // Unwrapping below should be safe (in theory) let number = caps . name ( " " ) . unwrap ( ) . as_str ( ) . parse :: < i32 > ( ) . unwrap ( ) ; let name = caps . name ( " " ) . unwrap ( ) . as_str ( ) ; let direction = if caps . name ( " " ) . unwrap ( ) . as_str ( ) == " " { Direction :: Up } else { Direction :: Down } ; Ok ( MigrationFile :: new ( filename , name , number , direction ) ) }
Gets a filename and check whether it's a valid format.
Gets a filename and check whether it ' s a valid format .
filename
&str