const_strcmp 0.1.0

String compare as a const function
Documentation
#![no_std]
use core::cmp::Ordering;

pub const fn compare_str(a: &str, b: &str) -> Ordering {
    let a = a.as_bytes();
    let b = b.as_bytes();
    let mut i = 0;
    loop {
        match (i >= a.len(), i >= b.len()) {
            (true, true) => break,
            (true, false) => return Ordering::Less,
            (false, true) => return Ordering::Greater,
            (false, false) => (),
        }
        if a[i] > b[i] {
            return Ordering::Greater;
        }
        if a[i] < b[i] {
            return Ordering::Less;
        }
        i += 1;
    }
    Ordering::Equal
}

#[cfg(test)]
mod tests {
    use crate::compare_str;

    #[test]
    const fn test_some_strings() {
        assert!(compare_str("a", "b").is_lt());
        assert!(!compare_str("a", "b").is_gt());
        assert!(!compare_str("a", "b").is_eq());
        assert!(compare_str("a", "a").is_eq());
        assert!(compare_str("a", "aa").is_lt());
        assert!(compare_str("b", "aa").is_gt());
        assert!(compare_str("ba", "aa").is_gt());
        assert!(compare_str("baa", "aa").is_gt());
        assert!(compare_str("aaa", "aa").is_gt());
        assert!(compare_str("aaa", "ab").is_lt());
    }
}