kurtbuilds_std_ext 0.1.13

Standard library extensions
Documentation
pub trait StrExt {
    fn into_option(self) -> Option<String>;
}

impl StrExt for &str {
    fn into_option(self) -> Option<String> {
        if self.is_empty() {
            None
        } else {
            Some(self.to_string())
        }
    }
}

#[cfg(test)]
mod tests {
    use super::*;

    #[test]
    fn test_option_string() {
        let s = "hello".to_string();
        assert_eq!(s.into_option().as_deref(), Some("hello"));
    }
}