0

I have the module string_queue:

use crossbeam_utils::thread;
use std::sync::{Arc, Mutex};

pub struct MyText {
    my_text: Arc<Mutex<Vec<String>>>,
}

pub trait MyTextOptions {
    fn new() -> MyText;
    fn add(&self, t: &str);
    fn get(&self) -> String;
}

impl MyTextOptions for MyText {
    fn new() -> MyText {
        unimplemented!();
    }

    fn add(&self, text: &str) {
        unimplemented!();
    }

    fn get(&self) -> String {
        unimplemented!();
    }
}

Is there a way to declare a mutable variable in that module that corresponds to the defined my_text type in pub struct MyText, lives for the whole application execution time and can be used as an input variable in the defined impl MyTextOptions for MyText functions?

Basically, I'm looking for something similar to the usage of self.__l = [] in this Python code, without using RustPython or similar Python + Rust hybrids.

class MyClass:
    def __init__(self):
        self.__l = []

    def add(self, t):
        self.__l += [t]

    def get(self):
        t = self.__l[0]
        self.__l = self.__l[1:]
        return t
Shepmaster
  • 388,571
  • 95
  • 1,107
  • 1,366
TalG
  • 677
  • 1
  • 9
  • 26

0 Answers0