Repository: ParkMyCar/compact_str (rust)

Issue:
Consider impl trait FromStr for CompactStr
I got error when using StructOpts

```
    | |__________________________^ the trait `FromStr` is not implemented for `CompactStr`
```

Pull request description:
impl FromStr for CompactStr
Fixes #18

This PR implements the `std::str::FromStr` trait for `CompactStr`, where the error type is `core::convert::Infallible`. The ergonomics here aren't _great_ because despite making the error type "infallible" we still have to call unwrap. Once the never type, `!`, is stabilized, we can use that instead. 

Patch:
diff --git a/compact_str/src/lib.rs b/compact_str/src/lib.rs
index ed5785f7..002e399f 100644
--- a/compact_str/src/lib.rs
+++ b/compact_str/src/lib.rs
@@ -17,6 +17,7 @@ use core::{
     fmt,
     hash::{Hash, Hasher},
     ops::Deref,
+    str::FromStr,
 };
 
 mod repr;
@@ -181,6 +182,13 @@ impl<'a> From<&'a String> for CompactStr {
     }
 }
 
+impl FromStr for CompactStr {
+    type Err = core::convert::Infallible;
+    fn from_str(s: &str) -> Result<CompactStr, Self::Err> {
+        Ok(CompactStr::from(s))
+    }
+}
+
 impl fmt::Debug for CompactStr {
     fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
         fmt::Debug::fmt(self.as_str(), f)


Test patch:
diff --git a/compact_str/src/tests.rs b/compact_str/src/tests.rs
index 23031e6d..a4181529 100644
--- a/compact_str/src/tests.rs
+++ b/compact_str/src/tests.rs
@@ -1,5 +1,6 @@
 use crate::CompactStr;
 use proptest::{prelude::*, strategy::Strategy};
+use std::str::FromStr;
 
 #[cfg(target_pointer_width = "64")]
 const MAX_INLINED_SIZE: usize = 24;
@@ -129,3 +130,13 @@ fn test_medium_unicode() {
         assert_eq!(compact.is_heap_allocated(), is_heap);
     }
 }
+
+#[test]
+fn test_from_str_trait() {
+    let s = "hello_world";
+
+    // Until the never type `!` is stabilized, we have to unwrap here
+    let c = CompactStr::from_str(s).unwrap();
+
+    assert_eq!(s, c);
+}