starting with Rust creates many questions. I hope I dont bother you...
I have the following construct.
pub fn get_double_tokens(css_path : &str) -> Vec<CSSToken> {
let css_token_list: &mut Vec<CSSToken> = &mut Vec::new();
check_files(css_token_list, css_path);
search_for_double_tokens(css_token_list);
css_token_list; <- not working because wrong type
}
fn check_files(list: &mut Vec<CSSToken>, path: &str) {
.....
}
The function check_files ist recursivly called and modifies the content of the css_token_list (Bei adding elements). So the list must be mutable first. But the resulting (returned) list should be inmutable, so that I can call get_double_tokens in that way
let css_token_list = get_double_tokens("path");
and get back a reference to an unmutable list (because mutable is not nessecary here)
There's not really a way to prevent the user from mutating the returned Vec<CSSToken>; they own it, so they're allowed to do whatever they want with it. If you want to prevent that, you could return a Box<[CSSToken]> by calling the into_boxed_slice() method on css_token_list, but that's not really idiomatic Rust; I'd just leave it at returning a Vec: