You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
If one want to use a with statment with a pyclass then __exit__ can be automatically implemented by calling drop on the pyclass.
This elimnates the need to implement a __exit__ function.
#[pyclass]structDebugController{conn:TcpStream,}implDropforDebugController{fndrop(&mutself){// Do RAII stuff idk send bye bye message using the socket}}
withDebugControllerasd:
d.do_stuff()
I am thinking about it and not sure if it's a good idea... because implementing __exit__ might seem easier.
The text was updated successfully, but these errors were encountered:
To give some additional detail here, in general we don't automatically implement any Python methods based on the existence of a Rust trait. I think to do that would probably require specialization.
Also, some other discussion about Drop and __exit__ can be found at #1205 (comment)
If one want to use a
with
statment with apyclass
then__exit__
can be automatically implemented by calling drop on thepyclass
.This elimnates the need to implement a
__exit__
function.I am thinking about it and not sure if it's a good idea... because implementing
__exit__
might seem easier.The text was updated successfully, but these errors were encountered: