Hello,
the following situation: I'm writing a telegram bot using telebot. I will add commands using bot.new_cmd("/<cmd name>").and_then(handle_*);
, where handle_*
is a function in a separate module (as i plan to separate commands by category, using modules).
Some of those commands only have the purpose of selecting a random string from a list, formatting it and sending the result. I would like to define those string lists in separate files, one per line, and they will never change at runtime. (If i didn't want to load them from files, i would probably not be asking this question, as i would just use a &'static [&'static str]
.)
include_str!
Sounds promising and is probably what i would use to load the file content. (If i get it right, this reads the file at compile time and inserts the content - perfect.) But i need an array of the lines, and it should be const/static, so...
This is what i've found/considered so far:
-
lazy_static
: Would definitely be an option, but i don't need anything mutable, so i don't know if it would fit. - Rethink my concept: This project is basically an attempt of rewriting a Telegram bot i've written in Java; there, i had every command as a class with one instance, so in theory, i could do the same thing here, by having structs in a map and hooking into the
get_stream()
method of mytelebot::RcBot
instead. That would make it easier and the commands more self-contained, but is it the, well, Rust-y thing to do? I'm doing this to learn and get better at the Rust way as well.
I know this became kind of complicated at the end, so here's the question again:
Is there a working way of doing something like this
const TEXTS: &'static [&'static str] = include_str!("../texts/something.txt").split('\n').collect();
?
Thanks!