Why do many libraries define *Ref variants for structs?

113 points ManateeIA 13 comments

Socket2 defines SocketRef https://docs.rs/socket2/latest/src/socket2/sockref.rs.html#60 and Quinn has an EndpointRef https://github.com/quinn-rs/quinn/blob/main/quinn/src/endpoint.rs.

I don’t understand what benefit we get from defining these variants. They seem to be wrappers on some inner value, and they implement Deref. Why do we want this? What problem does this solve?