How to close a serial port in Rust using serialport crate?

时间:2018-12-03 13:11:58

标签: rust serial-port

How do I close a serial port that I've opened? I can't see any hint about how to do this in the docs for serialport.

1 个答案:

答案 0 :(得分:1)

The trait Serialport itself does not offer such functionality1.

However the only implementor is TTYPort and its doc states:

The port will be closed when the value is dropped.

If you look at the drop implementation, you can verify this behavior.

So, you can either use std::mem::drop directly or when the value goes out of scope the Drop implementation will be called (see the book about this chapter.).


1 I would suggest opening a issue on the GitHub repository and request the functionality.