def match_barcode_rule(trello_db, barcode):
    """Finds a barcode rule matching the given barcode.

       Returns the rule if it exists, otherwise returns None."""
    rules = trello_db.get_all('barcode_rules')
    for r in rules:
        if r['barcode'] == barcode:
            return r
    return None