Bug 1313160 - Add From<&'a String> and From<&'a Vec<u8>> conversions for rust nsstring lib; r=mystor
authorKyle Machulis <kyle@nonpolynomial.com>
Thu, 27 Oct 2016 13:07:50 -0700
changeset 319868 46acc32392759b90b5122d7678464b83ff34b5fd
parent 319867 c1d12c6ae210912b1e5005ff1cd952cdc605e593
child 319869 1e7d830ec82857d197cae4c23d9b1b4fc4cfca23
push id20749
push userryanvm@gmail.com
push dateSat, 29 Oct 2016 13:21:21 +0000
treeherderfx-team@1b170b39ed6b [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmystor
bugs1313160
milestone52.0a1
Bug 1313160 - Add From<&'a String> and From<&'a Vec<u8>> conversions for rust nsstring lib; r=mystor MozReview-Commit-ID: EBHFA8sjnM6
xpcom/rust/nsstring/src/lib.rs
--- a/xpcom/rust/nsstring/src/lib.rs
+++ b/xpcom/rust/nsstring/src/lib.rs
@@ -308,16 +308,28 @@ macro_rules! define_string_types {
         }
 
         impl<'a> DerefMut for $String<'a> {
             fn deref_mut(&mut self) -> &mut $AString {
                 &mut self.hdr
             }
         }
 
+        impl<'a> From<&'a String> for $String<'a> {
+            fn from(s: &'a String) -> $String<'a> {
+                $String::from(&s[..])
+            }
+        }
+
+        impl<'a> From<&'a Vec<$char_t>> for $String<'a> {
+            fn from(s: &'a Vec<$char_t>) -> $String<'a> {
+                $String::from(&s[..])
+            }
+        }
+
         impl<'a> From<&'a [$char_t]> for $String<'a> {
             fn from(s: &'a [$char_t]) -> $String<'a> {
                 assert!(s.len() < (u32::MAX as usize));
                 $String {
                     hdr: $StringRepr {
                         data: s.as_ptr(),
                         length: s.len() as u32,
                         flags: F_NONE,