fn filename_to_fileno(prefix: &str, name: &Path) -> Result<i16, FilenameParseError> {

    fn char_to_hex(byte: u8) -> Result<i16, FilenameParseError> {
        Ok(match byte {
            b'A' ... b'F' => byte - b'A' + 10,
            b'a' ... b'f' => byte - b'a' + 10,
            b'0' ... b'9' => byte - b'0',
            _             => return Err(FilenameParseError)
        } as i16)
    }

    // grab the name utf
    let name = name
        .file_name().ok_or(FilenameParseError)?
        .to_str().ok_or(FilenameParseError)?;

    // check prefix
    if !name.starts_with(prefix) {
        return Err(FilenameParseError);
    }

    // check length
    let name = name.as_bytes();
    let p = prefix.len();
    if name.len() != p + 4 {
        return Err(FilenameParseError);
    }

    // parse hex-chars
    Ok(
        (char_to_hex(name[p  ])? as i16) << 12 |
        (char_to_hex(name[p+1])? as i16) << 8 |
        (char_to_hex(name[p+2])? as i16) << 4 |
        (char_to_hex(name[p+3])? as i16) << 0
    )
}
/// Interprets the given name as
/// prefixNNNN where NNNN is big-endian
/// 16-bit signed int, and returns the number
Interprets the given name as
prefixNNNN where NNNN is big-endian
16-bit signed int, and returns the number
Interprets the given name as prefixNNNN where NNNN is big - endian 16 - bit signed int and returns the number
fn filename_to_fileno(prefix: &str, name: &Path) -> Result<i16, FilenameParseError> {
    fn char_to_hex(byte: u8) -> Result<i16, FilenameParseError> {
        Ok(match byte {
            b'A' ... b'F' => byte - b'A' + 10,
            b'a' ... b'f' => byte - b'a' + 10,
            b'0' ... b'9' => byte - b'0',
            _             => return Err(FilenameParseError)
        } as i16)
    }
    // grab the name utf
    let name = name
        .file_name().ok_or(FilenameParseError)?
        .to_str().ok_or(FilenameParseError)?;
    // check prefix
    if !name.starts_with(prefix) {
        return Err(FilenameParseError);
    }
    // check length
    let name = name.as_bytes();
    let p = prefix.len();
    if name.len() != p + 4 {
        return Err(FilenameParseError);
    }
    // parse hex-chars
    Ok(
        (char_to_hex(name[p  ])? as i16) << 12 |
        (char_to_hex(name[p+1])? as i16) << 8 |
        (char_to_hex(name[p+2])? as i16) << 4 |
        (char_to_hex(name[p+3])? as i16) << 0
    )
}
fn filename_to_fileno ( prefix : & str , name : & Path ) -> Result < i16 , FilenameParseError > { fn char_to_hex ( byte : u8 ) -> Result < i16 , FilenameParseError > { Ok ( match byte { b'A' ... b'F' => byte - b'A' + 10 , b'a' ... b'f' => byte - b'a' + 10 , b'0' ... b'9' => byte - b'0' , _ => return Err ( FilenameParseError ) } as i16 ) } // grab the name utf let name = name . file_name ( ) . ok_or ( FilenameParseError ) ? . to_str ( ) . ok_or ( FilenameParseError ) ? ; // check prefix if ! name . starts_with ( prefix ) { return Err ( FilenameParseError ) ; } // check length let name = name . as_bytes ( ) ; let p = prefix . len ( ) ; if name . len ( ) != p + 4 { return Err ( FilenameParseError ) ; } // parse hex-chars Ok ( ( char_to_hex ( name [ p ] ) ? as i16 ) << 12 | ( char_to_hex ( name [ p + 1 ] ) ? as i16 ) << 8 | ( char_to_hex ( name [ p + 2 ] ) ? as i16 ) << 4 | ( char_to_hex ( name [ p + 3 ] ) ? as i16 ) << 0 ) }
Interprets the given name as
prefixNNNN where NNNN is big-endian
16-bit signed int, and returns the number
Interprets the given name as prefixNNNN where NNNN is big - endian 16 - bit signed int and returns the number
prefix
&str
name
&Path
prefix
&str
name
&Path