mirror of
https://github.com/neondatabase/neon.git
synced 2026-01-05 20:42:54 +00:00
bin_ser: simplify ser_into_slice
The conversion of &mut [u8] into Write is a little tricky. Also, remove an unused generic parameter.
This commit is contained in:
committed by
Eric Seppanen
parent
d744ddee7c
commit
858ca3a4ce
@@ -83,10 +83,11 @@ pub fn le_coder() -> impl Options {
|
||||
///
|
||||
pub trait BeSer: Serialize + DeserializeOwned {
|
||||
/// Serialize into a byte slice
|
||||
fn ser_into_slice<W: Write>(&self, b: &mut [u8]) -> Result<(), SerializeError> {
|
||||
// This is slightly awkward; we need a mutable reference to a mutable reference.
|
||||
let mut w = b;
|
||||
self.ser_into(&mut w)
|
||||
fn ser_into_slice(&self, mut b: &mut [u8]) -> Result<(), SerializeError> {
|
||||
// &mut [u8] implements Write, but `ser_into` needs a mutable
|
||||
// reference to that. So we need the slightly awkward "mutable
|
||||
// reference to a mutable reference.
|
||||
self.ser_into(&mut b)
|
||||
}
|
||||
|
||||
/// Serialize into a borrowed writer
|
||||
@@ -119,10 +120,11 @@ pub trait BeSer: Serialize + DeserializeOwned {
|
||||
///
|
||||
pub trait LeSer: Serialize + DeserializeOwned {
|
||||
/// Serialize into a byte slice
|
||||
fn ser_into_slice<W: Write>(&self, b: &mut [u8]) -> Result<(), SerializeError> {
|
||||
// This is slightly awkward; we need a mutable reference to a mutable reference.
|
||||
let mut w = b;
|
||||
self.ser_into(&mut w)
|
||||
fn ser_into_slice(&self, mut b: &mut [u8]) -> Result<(), SerializeError> {
|
||||
// &mut [u8] implements Write, but `ser_into` needs a mutable
|
||||
// reference to that. So we need the slightly awkward "mutable
|
||||
// reference to a mutable reference.
|
||||
self.ser_into(&mut b)
|
||||
}
|
||||
|
||||
/// Serialize into a borrowed writer
|
||||
|
||||
Reference in New Issue
Block a user