I have the following method to check if an String
ID exists. If it doesn't, generate and then return it:
fn generate_id(&self) -> ID<'m> {
let id = nanoid::generate(15);
while self[&id].is_some() {
id = nanoid::generate(15);
};
id
}
ID
is a type alias: type ID<'id> = &'id String;
The return value needs to be &'m std::string::String
but id
is std::string::String
.
I have tried doing:
let id: ID<'m> = nanoid::generate(15);
but then it gives the same error that the method is giving only for id
.