I have a HashMap
with endpoints:
#[derive(Debug, Clone, Copy, Ord, Eq, PartialOrd, PartialEq, Hash)]
enum Endpoint {
OauthToken,
Disciplines,
PublicTournaments,
MyTournaments,
Matches,
}
lazy_static! {
static ref API_EP: HashMap<Endpoint, &'static str> = {
let mut m: HashMap<Endpoint, &'static str> = HashMap::new();
m.insert(Endpoint::OauthToken, "/oauth/v2/token");
m.insert(Endpoint::Disciplines, "/v1/disciplines");
m.insert(Endpoint::PublicTournaments, "/v1/tournaments");
m.insert(Endpoint::MyTournaments, "/v1/me/tournaments");
m.insert(Endpoint::Matches, "/v1/tournaments/{}/matches");
m
};
}
As you may see, the map item which is accessible by Endpoint::Matches
key returns a string which needs to be formatted, however, I don't see a way of doing this.
I've tried to use format!
macro but it needs string literals but not an object so it does not work. I tried to search the solution over the internet and rust std library but I was unable to find it. Is there any way to do this?
For clarification why format!
does not work:
error: format argument must be a string literal.
--> src/lib.rs:249:31
|
249 | let address = format!(get_ep_address(Endpoint::Matches)?, id.0);
get_ep_address(Endpoint::Matches)?
is not a string literal so it can't work.
I would also like to know how to format both &str
and String
types.