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

event_graph: add gen_id() function

Dastan-glitch 3 лет назад
Родитель
Сommit
e118096815
1 измененных файлов с 6 добавлено и 0 удалено
  1. 6 0
      src/event_graph/mod.rs

+ 6 - 0
src/event_graph/mod.rs

@@ -16,6 +16,8 @@
  * along with this program.  If not, see <https://www.gnu.org/licenses/>.
  */
 
+use rand::{distributions::Alphanumeric, thread_rng, Rng};
+
 pub mod events_queue;
 pub mod model;
 pub mod protocol_event;
@@ -25,6 +27,10 @@ pub trait EventMsg {
     fn new() -> Self;
 }
 
+pub fn gen_id(len: usize) -> String {
+    thread_rng().sample_iter(&Alphanumeric).take(len).map(char::from).collect()
+}
+
 pub fn get_current_time() -> u64 {
     let start = std::time::SystemTime::now();
     start