fn parse_profile_name(line: &str) -> Option<&str> {
    // NOTE(benesch): should this handle whitespace inside the brackets? Seems
    // like we should maybe use a proper INI parser here? Someone should
    // investigate how other AWS SDKs work.
    if let Some(line) = line.trim().strip_suffix("]") {
        if let Some(profile_name) = line.strip_prefix("[profile ") {
            return Some(profile_name);
        }
        if let Some(profile_name) = line.strip_prefix("[") {
            return Some(profile_name);
        }
    }
    None
}
Parses a profile header, returning the profile name.
rusoto/credential/src/profile.rs