this is my function:

pub fn to_bed<'a>(

    s: &'a str,

    parent: String,

    child: String,

    feature: String,

) -> Result<HashMap<String, HashMap<&str, String>>, &'static str> {

    s.par_lines()

        .map(|line| {

            if !line.starts_with("#") {

                Some(GxfRecord::parse(line, &feature))

            } else {

                None

            }

        })

        .filter_map(|x| x)

        .try_fold_with(HashMap::new(), |mut acc, record| {

            let record = record?;

            let tx_id = if !record.attr.feature().is_empty() {

                record.attr.feature().to_owned()

            } else {

                // continue with the next record

                return Ok(acc);

            };

            let entry = acc.entry(tx_id).or_insert(HashMap::new());

            if !parent.is_empty() {

                if record.feat == parent {

                    // args.parent

                    entry.insert("chr", record.chr.to_owned());

                    entry.insert("start", record.start.to_string());

                    entry.insert("end", record.end.to_string());

                    entry.insert("strand", record.strand.to_string());

                } else if record.feat == child {

                    // args.child

                    entry.entry("exons").or_default().push('.');

                    let exon_starts = entry.entry("exon_starts").or_insert(String::from(""));

                    exon_starts.push_str(&record.start.to_string());

                    exon_starts.push_str(",");

                    let exon_sizes = entry.entry("exon_sizes").or_insert(String::from(""));

                    exon_sizes.push_str(&(record.end - record.start).to_string());

                    exon_sizes.push_str(",");

                } else if record.feat == "start_codon" {

                    entry.insert("start_codon", record.start.to_string());

                } else if record.feat == "stop_codon" {

                    entry.insert("stop_codon", record.start.to_string());

                }

            } else {

                entry.insert("chr", record.chr.to_owned());

                entry.insert("start", record.start.to_string());

                entry.insert("end", record.end.to_string());

                entry.insert("strand", record.strand.to_string());

                entry.entry("exons").or_default().push('.');

                let exon_starts = entry.entry("exon_starts").or_insert(String::from(""));

                exon_starts.push_str(&record.start.to_string());

                exon_starts.push_str(",");

                let exon_sizes = entry.entry("exon_sizes").or_insert(String::from(""));

                exon_sizes.push_str(&(record.end - record.start).to_string());

                exon_sizes.push_str(",");

            }

            Ok(acc)

        }) // end fold

        .try_reduce_with(|mut map1, map2| {

            for (k, v) in map2 {

                let entry = map1.entry(k).or_insert(HashMap::new());

                for (k2, v2) in v {

                    entry.insert(k2, v2);

                }

            }

            Ok(map1)

        }) // end reduce

        .unwrap_or(Err("Error converting GTF/GFF3 to BED"))

}

could you help me to make this part of the code to look more elegant?

            if !parent.is_empty() {

                if record.feat == parent {

                    // args.parent

                    entry.insert("chr", record.chr.to_owned());

                    entry.insert("start", record.start.to_string());

                    entry.insert("end", record.end.to_string());

                    entry.insert("strand", record.strand.to_string());

                } else if record.feat == child {

                    // args.child

                    entry.entry("exons").or_default().push('.');

                    let exon_starts = entry.entry("exon_starts").or_insert(String::from(""));

                    exon_starts.push_str(&record.start.to_string());

                    exon_starts.push_str(",");

                    let exon_sizes = entry.entry("exon_sizes").or_insert(String::from(""));

                    exon_sizes.push_str(&(record.end - record.start).to_string());

                    exon_sizes.push_str(",");

                } else if record.feat == "start_codon" {

                    entry.insert("start_codon", record.start.to_string());

                } else if record.feat == "stop_codon" {

                    entry.insert("stop_codon", record.start.to_string());

                }

            } else {

                entry.insert("chr", record.chr.to_owned());

                entry.insert("start", record.start.to_string());

                entry.insert("end", record.end.to_string());

                entry.insert("strand", record.strand.to_string());

                entry.entry("exons").or_default().push('.');

                let exon_starts = entry.entry("exon_starts").or_insert(String::from(""));

                exon_starts.push_str(&record.start.to_string());

                exon_starts.push_str(",");

                let exon_sizes = entry.entry("exon_sizes").or_insert(String::from(""));

                exon_sizes.push_str(&(record.end - record.start).to_string());

                exon_sizes.push_str(",");

            }