From 6f671c05d0bd61d67c25a2a9982913c13a441b7f Mon Sep 17 00:00:00 2001 From: crowlkats Date: Wed, 25 May 2022 18:54:03 +0200 Subject: [PATCH] add from impls for startupdata --- src/snapshot.rs | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/src/snapshot.rs b/src/snapshot.rs index 01ac800f..5226e899 100644 --- a/src/snapshot.rs +++ b/src/snapshot.rs @@ -53,6 +53,26 @@ pub struct StartupData { raw_size: int, } +impl From> for StartupData { + fn from(slice: Box<[u8]>) -> Self { + let mut data: Vec = vec![]; + data.copy_from_slice(&slice); + StartupData { + data: data.as_ptr() as *const char, + raw_size: data.len() as int, + } + } +} + +impl From<&[u8]> for StartupData { + fn from(slice: &[u8]) -> Self { + StartupData { + data: slice.as_ptr() as *const char, + raw_size: slice.len() as int, + } + } +} + impl Deref for StartupData { type Target = [u8]; fn deref(&self) -> &Self::Target {