nebius/SWE-rebench-V2-PRs huggingface dataset:
Repository: bluss/arrayvec
Pull request #170 (2020-12-09 23:22:50)

Impl TryFrom<fmt::Arguments<'a>> for ArrayString
Shortcut for

```rust
use core::fmt::Write;
let mut v = Self::new();
v.write_fmt(format_args!("Something -> {}", 123)).map_err(|e| CapacityError::new(e))?;

...
```




Patch:
diff --git a/src/array_string.rs b/src/array_string.rs
index a94c3f7..48139b2 100644
--- a/src/array_string.rs
+++ b/src/array_string.rs
@@ -594,3 +594,17 @@ where
         Ok(v)
     }
 }
+
+impl<'a, A> TryFrom<fmt::Arguments<'a>> for ArrayString<A>
+where
+    A: Array<Item = u8> + Copy
+{
+    type Error = CapacityError<fmt::Error>;
+
+    fn try_from(f: fmt::Arguments<'a>) -> Result<Self, Self::Error> {
+        use fmt::Write;
+        let mut v = Self::new();
+        v.write_fmt(f).map_err(|e| CapacityError::new(e))?;
+        Ok(v)
+    }
+}


Test patch:
diff --git a/tests/tests.rs b/tests/tests.rs
index c7ebcd0..593b5e4 100644
--- a/tests/tests.rs
+++ b/tests/tests.rs
@@ -686,3 +686,10 @@ fn test_extend_zst() {
     assert_eq!(&array[..], &[Z; 5]);
     assert_eq!(array.len(), 5);
 }
+
+#[test]
+fn test_try_from_argument() {
+    use core::convert::TryFrom;
+    let v = ArrayString::<[u8; 16]>::try_from(format_args!("Hello {}", 123)).unwrap();
+    assert_eq!(&v, "Hello 123");
+}
Repository: bluss/arrayvec
Pull request #187 (2021-05-25 21:03:24)

take and into_inner_unchecked functions
Adds two new functions

1. `into_inner_unchecked`, unsafe and unchecked variant of `into_inner`
2. `take`, which returns the ArrayVec while only borrowing, replacing the original with a new empty ArrayVec


Patch:
diff --git a/src/arrayvec.rs b/src/arrayvec.rs
index 5700237..b042242 100644
--- a/src/arrayvec.rs
+++ b/src/arrayvec.rs
@@ -636,14 +636,34 @@ impl<T, const CAP: usize> ArrayVec<T, CAP> {
         if self.len() < self.capacity() {
             Err(self)
         } else {
-            unsafe {
-                let self_ = ManuallyDrop::new(self);
-                let array = ptr::read(self_.as_ptr() as *const [T; CAP]);
-                Ok(array)
-            }
+            unsafe { Ok(self.into_inner_unchecked()) }
         }
     }
 
+    /// Return the inner fixed size array.
+    ///
+    /// Safety:
+    /// This operation is safe if and only if length equals capacity.
+    pub unsafe fn into_inner_unchecked(self) -> [T; CAP] {
+        debug_assert_eq!(self.len(), self.capacity());
+        let self_ = ManuallyDrop::new(self);
+        let array = ptr::read(self_.as_ptr() as *const [T; CAP]);
+        array
+    }
+
+    /// Returns the ArrayVec, replacing the original with a new empty ArrayVec.
+    ///
+    /// ```
+    /// use arrayvec::ArrayVec;
+    ///
+    /// let mut v = ArrayVec::from([0, 1, 2, 3]);
+    /// assert_eq!([0, 1, 2, 3], v.take().into_inner().unwrap());
+    /// assert!(v.is_empty());
+    /// ```
+    pub fn take(&mut self) -> Self  {
+        mem::replace(self, Self::new())
+    }
+
     /// Return a slice containing all elements of the vector.
     pub fn as_slice(&self) -> &[T] {
         ArrayVecImpl::as_slice(self)


Test patch:
diff --git a/tests/tests.rs b/tests/tests.rs
index ca42c74..26d09ae 100644
--- a/tests/tests.rs
+++ b/tests/tests.rs
@@ -153,6 +153,21 @@ fn test_drop() {
         assert_eq!(flag.get(), 3);
     }
 
+    // test take
+    flag.set(0);
+    {
+        let mut array1 = ArrayVec::<_,  3>::new();
+        array1.push(Bump(flag));
+        array1.push(Bump(flag));
+        array1.push(Bump(flag));
+        let array2 = array1.take();
+        assert_eq!(flag.get(), 0);
+        drop(array1);
+        assert_eq!(flag.get(), 0);
+        drop(array2);
+        assert_eq!(flag.get(), 3);
+    }
+
     // test cloning into_iter
     flag.set(0);
     {
@@ -461,6 +476,15 @@ fn test_into_inner_3() {
     assert_eq!(v.into_inner().unwrap(), [1, 2, 3, 4]);
 }
 
+#[test]
+fn test_take() {
+    let mut v1 = ArrayVec::<i32,  4>::new();
+    v1.extend(1..=4);
+    let v2 = v1.take();
+    assert!(v1.into_inner().is_err());
+    assert_eq!(v2.into_inner().unwrap(), [1, 2, 3, 4]);
+}
+
 #[cfg(feature="std")]
 #[test]
 fn test_write() {