When i use tonic,how can i reassign a variable in main in handle function?

I have been learning Rust for two weeks,There is still a lot of confusion.
It seems to be very tightly controlled in terms of global variables, I want a singleton, and then after
the GRPC handler changes or reads its value, the singleton should be global. How do I make this?

example:


I tried to add this singleton as a member of the FilWindowPostServer, and then use "&mut self",And then it seems like the compiler reminds me that I can't use mut here

You can add it as a member to FilWindowPostServer, but to actually modify it, you will need to wrap it in some sort of Mutex, which would allow modification through &self.

1 Like

thanks.I'll have a try

that's working,thks :grinning:

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.