From b4a779f040f18257fde1c357626461ab187490db Mon Sep 17 00:00:00 2001 From: Miquel Sabaté Solà Date: Wed, 22 Jan 2025 15:55:25 +0100 Subject: Remove dependency to the rand crate MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This dependency was easily avoidable and it brought with it a lot of inner dependencies of its own, most notably 'zerocopy-derive', which forbid us to compile the affected programs purely statically. Signed-off-by: Miquel Sabaté Solà --- lib/xixanta/src/parser.rs | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) (limited to 'lib/xixanta/src') diff --git a/lib/xixanta/src/parser.rs b/lib/xixanta/src/parser.rs index 0a4d2b8..d508003 100644 --- a/lib/xixanta/src/parser.rs +++ b/lib/xixanta/src/parser.rs @@ -1,7 +1,6 @@ use crate::node::{ControlType, NodeBodyType, NodeType, OperationType, PNode, PString}; use crate::opcodes::{CONTROL_FUNCTIONS, INSTRUCTIONS}; use crate::{Error, SourceInfo}; -use rand::distributions::{Alphanumeric, DistString}; use std::cmp::Ordering; use std::io::{self, BufRead, Read}; use std::path; @@ -61,6 +60,12 @@ pub struct Parser { /// look ahead to know where the literal ends before dealing with further /// operators. look_ahead_index: usize, + + /// Number that keeps track of random identifiers being generated so far. + /// This is because certain anonymous identifiers are not to be exposed to + /// the human eye, and we just care about them being unique. Hence this + /// counter. + generated_identifiers: usize, } impl Parser { @@ -1338,8 +1343,10 @@ impl Parser { } // Generate a unique identifier with the given prefix. - fn unique_identifier(&self, prefix: String) -> String { - prefix + &String::from("-") + &Alphanumeric.sample_string(&mut rand::thread_rng(), 16) + fn unique_identifier(&mut self, prefix: String) -> String { + let res = prefix + &String::from("-") + &self.generated_identifiers.to_string(); + self.generated_identifiers += 1; + res } // Returns a NodeType::Control node with whatever could be parsed -- cgit v1.2.3