self.buf is a fat pointer to string which allocate at heap, so calling get_and_reset will causing self.buf point to a new string which also allocate at heap, and the old string will be moved to returned value, it seems very ok for me.
I can't understand why rust stop this? or is there any other code cases will lead to memory unsafe ?
There is a temporary move between the two statements. You can avoid this by using mem::replace or in your case where you take the value from the mutable reference and replace it with the default value of the type, mem::take. Here an example.