nebius/SWE-rebench-V2-PRs huggingface dataset:
Repository: near/borsh-rs
Pull request #34 (2021-05-07 01:52:14)

Add serialization helpers to improve api ergonomics
Fixes: https://github.com/near/borsh-rs/issues/31

#### Problem
`BorshSerialize::serialize` method signature is not very ergonomic when using mutable slices. This is because a `&mut [T]` already implements `Write` but the method expects a `&mut W` where `W` itself implements `Write`. This means that in order to pass a mutable slice, you need to pass a mutable reference to the mutable slice: `&mut &mut [T]`.

#### Changes
- Added top-level `serialize_to_writer` and `serialize_to_vec` helper functions


Patch:
diff --git a/borsh/src/lib.rs b/borsh/src/lib.rs
index 51c81919..6a13270d 100644
--- a/borsh/src/lib.rs
+++ b/borsh/src/lib.rs
@@ -13,6 +13,7 @@ pub mod ser;
 pub use de::BorshDeserialize;
 pub use schema::BorshSchema;
 pub use schema_helpers::{try_from_slice_with_schema, try_to_vec_with_schema};
+pub use ser::helpers::{to_vec, to_writer};
 pub use ser::BorshSerialize;
 
 /// A facade around all the types we need from the `std`, `core`, and `alloc`
diff --git a/borsh/src/ser/helpers.rs b/borsh/src/ser/helpers.rs
new file mode 100644
index 00000000..1855af6b
--- /dev/null
+++ b/borsh/src/ser/helpers.rs
@@ -0,0 +1,21 @@
+use crate::maybestd::{
+    io::{Result, Write},
+    vec::Vec,
+};
+use crate::BorshSerialize;
+
+/// Serialize an object into a vector of bytes.
+pub fn to_vec<T>(value: &T) -> Result<Vec<u8>>
+where
+    T: BorshSerialize + ?Sized,
+{
+    value.try_to_vec()
+}
+
+/// Serializes an object directly into a `Writer`.
+pub fn to_writer<T, W: Write>(mut writer: W, value: &T) -> Result<()>
+where
+    T: BorshSerialize + ?Sized,
+{
+    value.serialize(&mut writer)
+}
diff --git a/borsh/src/ser/mod.rs b/borsh/src/ser/mod.rs
index fcc17e85..e01d6632 100644
--- a/borsh/src/ser/mod.rs
+++ b/borsh/src/ser/mod.rs
@@ -13,6 +13,8 @@ use crate::maybestd::{
 #[cfg(feature = "rc")]
 use std::{rc::Rc, sync::Arc};
 
+pub(crate) mod helpers;
+
 const DEFAULT_SERIALIZER_CAPACITY: usize = 1024;
 
 /// A data-structure that can be serialized into binary format by NBOR.


Test patch:
diff --git a/borsh/tests/smoke.rs b/borsh/tests/smoke.rs
new file mode 100644
index 00000000..3b99c47e
--- /dev/null
+++ b/borsh/tests/smoke.rs
@@ -0,0 +1,21 @@
+// Smoke tests that ensure that we don't accidentally remove top-level
+// re-exports in a minor release.
+
+use borsh::{self, BorshDeserialize};
+
+#[test]
+fn test_to_vec() {
+    let value = 42u8;
+    let serialized = borsh::to_vec(&value).unwrap();
+    let deserialized = u8::try_from_slice(&serialized).unwrap();
+    assert_eq!(value, deserialized);
+}
+
+#[test]
+fn test_to_writer() {
+    let value = 42u8;
+    let mut serialized = vec![0; 1];
+    borsh::to_writer(&mut serialized[..], &value).unwrap();
+    let deserialized = u8::try_from_slice(&serialized).unwrap();
+    assert_eq!(value, deserialized);
+}
Repository: rust-lang/rust-analyzer
Pull request #18820 (2025-01-02 11:00:28)

Fix no space insert before and after if value is only spaces
Continuation of #18795, as per comments in that PR


Patch:
diff --git a/crates/ide/src/hover/render.rs b/crates/ide/src/hover/render.rs
index 9d55827fe2..d72acad09f 100644
--- a/crates/ide/src/hover/render.rs
+++ b/crates/ide/src/hover/render.rs
@@ -716,16 +716,21 @@ pub(super) fn literal(
     match value {
         Ok(value) => {
             let backtick_len = value.chars().filter(|c| *c == '`').count();
+            let spaces_len = value.chars().filter(|c| *c == ' ').count();
             let backticks = "`".repeat(backtick_len + 1);
+            let space_char = if spaces_len == value.len() { "" } else { " " };
 
             if let Some(newline) = value.find('\n') {
                 format_to!(
                     s,
-                    "value of literal (truncated up to newline): {backticks} {} {backticks}",
+                    "value of literal (truncated up to newline): {backticks}{space_char}{}{space_char}{backticks}",
                     &value[..newline]
                 )
             } else {
-                format_to!(s, "value of literal: {backticks} {value} {backticks}")
+                format_to!(
+                    s,
+                    "value of literal: {backticks}{space_char}{value}{space_char}{backticks}"
+                )
             }
         }
         Err(error) => format_to!(s, "invalid literal: {error}"),


Test patch:
diff --git a/crates/ide/src/hover/tests.rs b/crates/ide/src/hover/tests.rs
index 8ea305ed8e..2e7637e467 100644
--- a/crates/ide/src/hover/tests.rs
+++ b/crates/ide/src/hover/tests.rs
@@ -8303,6 +8303,37 @@ fn main() {
             value of literal: `` ` ``
         "#]],
     );
+    check(
+        r#"
+fn main() {
+    $0r"    ";
+}"#,
+        expect![[r#"
+            *r"    "*
+            ```rust
+            &str
+            ```
+            ___
+
+            value of literal: `    `
+        "#]],
+    );
+    check(
+        r#"
+fn main() {
+    $0r" Hello World ";
+
+}"#,
+        expect![[r#"
+            *r" Hello World "*
+            ```rust
+            &str
+            ```
+            ___
+
+            value of literal: `  Hello World  `
+"#]],
+    )
 }
 
 #[test]