Просмотр исходного кода

Revert "sdk: move find_subslice() and NextTupleN from zkas into SDK util.rs"

This reverts commit dcf419b0ca839c359674ed79cb726c242c6489c8.
zero 2 лет назад
Родитель
Сommit
1a1a26e396
4 измененных файлов с 32 добавлено и 36 удалено
  1. 0 1
      Cargo.toml
  2. 0 32
      src/sdk/src/util.rs
  3. 5 1
      src/zkas/decoder.rs
  4. 27 2
      src/zkas/parser.rs

+ 0 - 1
Cargo.toml

@@ -307,7 +307,6 @@ zk = [
 
 zkas = [
     "darkfi-serial",
-    "darkfi-sdk",
 ]
 # -----END LIBRARY FEATURES-----
 

+ 0 - 32
src/sdk/src/util.rs

@@ -16,11 +16,6 @@
  * along with this program.  If not, see <https://www.gnu.org/licenses/>.
  */
 
-// https://stackoverflow.com/questions/35901547/how-can-i-find-a-subsequence-in-a-u8-slice
-pub fn find_subslice(haystack: &[u8], needle: &[u8]) -> Option<usize> {
-    haystack.windows(needle.len()).position(|window| window == needle)
-}
-
 /// Extra methods for Iterator. Copied from [itertools](https://github.com/rust-itertools/itertools).
 ///
 /// Licensed under MIT.
@@ -55,30 +50,3 @@ pub trait Itertools: Iterator {
 }
 
 impl<T> Itertools for T where T: Iterator + ?Sized {}
-
-pub trait NextTuple3<I>: Iterator<Item = I> {
-    fn next_tuple(&mut self) -> Option<(I, I, I)>;
-}
-
-impl<I: Iterator<Item = T>, T> NextTuple3<T> for I {
-    fn next_tuple(&mut self) -> Option<(T, T, T)> {
-        let a = self.next()?;
-        let b = self.next()?;
-        let c = self.next()?;
-        Some((a, b, c))
-    }
-}
-
-pub trait NextTuple4<I>: Iterator<Item = I> {
-    fn next_tuple(&mut self) -> Option<(I, I, I, I)>;
-}
-
-impl<I: Iterator<Item = T>, T> NextTuple4<T> for I {
-    fn next_tuple(&mut self) -> Option<(T, T, T, T)> {
-        let a = self.next()?;
-        let b = self.next()?;
-        let c = self.next()?;
-        let d = self.next()?;
-        Some((a, b, c, d))
-    }
-}

+ 5 - 1
src/zkas/decoder.rs

@@ -16,7 +16,6 @@
  * along with this program.  If not, see <https://www.gnu.org/licenses/>.
  */
 
-use darkfi_sdk::util::find_subslice;
 use darkfi_serial::{deserialize_partial, VarInt};
 
 use super::{
@@ -39,6 +38,11 @@ pub struct ZkBinary {
     pub opcodes: Vec<(Opcode, Vec<(HeapType, usize)>)>,
 }
 
+// https://stackoverflow.com/questions/35901547/how-can-i-find-a-subsequence-in-a-u8-slice
+fn find_subslice(haystack: &[u8], needle: &[u8]) -> Option<usize> {
+    haystack.windows(needle.len()).position(|window| window == needle)
+}
+
 impl ZkBinary {
     pub fn decode(bytes: &[u8]) -> Result<Self> {
         // Ensure that bytes is a certain minimum length. Otherwise the code

+ 27 - 2
src/zkas/parser.rs

@@ -20,8 +20,6 @@ use std::{
     borrow::Borrow, collections::HashMap, hash::Hash, io::Result, iter::Peekable, str::Chars,
 };
 
-use darkfi_sdk::util::{NextTuple3, NextTuple4};
-
 use super::{
     ast::{Arg, Constant, Literal, Statement, StatementType, Variable, Witness},
     constants::{ALLOWED_FIELDS, MAX_K, MAX_NS_LEN},
@@ -1161,3 +1159,30 @@ impl Parser {
         Ok(ret)
     }
 }
+
+trait NextTuple3<I>: Iterator<Item = I> {
+    fn next_tuple(&mut self) -> Option<(I, I, I)>;
+}
+
+impl<I: Iterator<Item = T>, T> NextTuple3<T> for I {
+    fn next_tuple(&mut self) -> Option<(T, T, T)> {
+        let a = self.next()?;
+        let b = self.next()?;
+        let c = self.next()?;
+        Some((a, b, c))
+    }
+}
+
+trait NextTuple4<I>: Iterator<Item = I> {
+    fn next_tuple(&mut self) -> Option<(I, I, I, I)>;
+}
+
+impl<I: Iterator<Item = T>, T> NextTuple4<T> for I {
+    fn next_tuple(&mut self) -> Option<(T, T, T, T)> {
+        let a = self.next()?;
+        let b = self.next()?;
+        let c = self.next()?;
+        let d = self.next()?;
+        Some((a, b, c, d))
+    }
+}