From 55ba2bc20982307d29df2a6686f6874981355185 Mon Sep 17 00:00:00 2001 From: Jean-Philippe Bossuat Date: Fri, 14 Feb 2025 18:40:26 +0100 Subject: [PATCH] removed from_bytes from trait --- base2k/src/vec_znx.rs | 41 ++++++++++++++++++++++------------------- 1 file changed, 22 insertions(+), 19 deletions(-) diff --git a/base2k/src/vec_znx.rs b/base2k/src/vec_znx.rs index fecd991..17316f4 100644 --- a/base2k/src/vec_znx.rs +++ b/base2k/src/vec_znx.rs @@ -11,13 +11,6 @@ pub trait VecZnxApi { /// Returns the minimum size of the [u8] array required to assign a /// new backend array to a [VecZnx] through [VecZnx::from_bytes]. fn bytes_of(n: usize, limbs: usize) -> usize; - /// Returns a new struct implementing [VecZnxApi] with the provided data as backing array. - /// - /// The struct will take ownership of buf[..[VecZnx::bytes_of]] - /// - /// User must ensure that data is properly alligned and that - /// the size of data is at least equal to [Module::bytes_of_vec_znx]. - fn from_bytes(n: usize, limbs: usize, bytes: &mut [u8]) -> impl VecZnxApi; fn as_ptr(&self) -> *const i64; fn as_mut_ptr(&mut self) -> *mut i64; fn at(&self, i: usize) -> &[i64]; @@ -38,12 +31,14 @@ pub struct VecZnxBorrow { pub data: *mut i64, } -impl VecZnxApi for VecZnxBorrow { - fn bytes_of(n: usize, limbs: usize) -> usize { - bytes_of_vec_znx(n, limbs) - } - - fn from_bytes(n: usize, limbs: usize, bytes: &mut [u8]) -> impl VecZnxApi { +impl VecZnxBorrow { + /// Returns a new struct implementing [VecZnxApi] with the provided data as backing array. + /// + /// The struct will take ownership of buf[..[VecZnx::bytes_of]] + /// + /// User must ensure that data is properly alligned and that + /// the size of data is at least equal to [Module::bytes_of_vec_znx]. + pub fn from_bytes(n: usize, limbs: usize, bytes: &mut [u8]) -> impl VecZnxApi { let size = Self::bytes_of(n, limbs); assert!( bytes.len() >= size, @@ -59,6 +54,12 @@ impl VecZnxApi for VecZnxBorrow { data: cast_mut(&mut bytes[..size]).as_mut_ptr(), } } +} + +impl VecZnxApi for VecZnxBorrow { + fn bytes_of(n: usize, limbs: usize) -> usize { + bytes_of_vec_znx(n, limbs) + } fn as_ptr(&self) -> *const i64 { self.data @@ -116,18 +117,14 @@ impl VecZnxApi for VecZnxBorrow { } } -impl VecZnxApi for VecZnx { - fn bytes_of(n: usize, limbs: usize) -> usize { - bytes_of_vec_znx(n, limbs) - } - +impl VecZnx { /// Returns a new struct implementing [VecZnxApi] with the provided data as backing array. /// /// The struct will take ownership of buf[..[VecZnx::bytes_of]] /// /// User must ensure that data is properly alligned and that /// the size of data is at least equal to [Module::bytes_of_vec_znx]. - fn from_bytes(n: usize, limbs: usize, buf: &mut [u8]) -> impl VecZnxApi { + pub fn from_bytes(n: usize, limbs: usize, buf: &mut [u8]) -> impl VecZnxApi { let size = Self::bytes_of(n, limbs); assert!( buf.len() >= size, @@ -143,6 +140,12 @@ impl VecZnxApi for VecZnx { data: alias_mut_slice_to_vec(cast_mut(&mut buf[..size])), } } +} + +impl VecZnxApi for VecZnx { + fn bytes_of(n: usize, limbs: usize) -> usize { + bytes_of_vec_znx(n, limbs) + } /// Returns a non-mutable pointer to the backing array of the [VecZnx]. fn as_ptr(&self) -> *const i64 {