Skip to content

feat: add port_info() default method to SerialPort trait - #339

Draft
KaustubhOG wants to merge 1 commit into
serialport:mainfrom
KaustubhOG:feat/port-info-method
Draft

feat: add port_info() default method to SerialPort trait#339
KaustubhOG wants to merge 1 commit into
serialport:mainfrom
KaustubhOG:feat/port-info-method

Conversation

@KaustubhOG

Copy link
Copy Markdown

Closes #276

Problem

There is currently no way to retrieve SerialPortInfo from an opendyn SerialPort without calling available_ports() manually and searching by name.

Solution

Add a default port_info() method to the SerialPort trait. The implementation calls self.name(), enumerates available ports, and returns the matching SerialPortInfo entry.

Since it is a default method, all existing implementors (TTYPort,COMPort, and the &mut T blanket impl) get it for free with no changes required on their end.

Returns Err if:

  • the port has no name (e.g. virtual/pseudo-terminal ports)
  • available_ports() fails
  • no matching port is found

Notes

  • All existing tests pass
  • Platform-specific types can override this method in the future
    if a faster implementation is needed (e.g. caching info at open time)

@KaustubhOG
KaustubhOG marked this pull request as draft March 25, 2026 19:57
@KaustubhOG

Copy link
Copy Markdown
Author

Should this target the playground-5.0 branch instead of main, given that it touches the SerialPort trait? i read some old pr where you listed it specific point

@sirhcel

sirhcel commented Mar 29, 2026

Copy link
Copy Markdown
Contributor

Thank you for starting this draft PR @KaustubhOG! Please see my comment #276 (comment) in the original issue.

Regarding this PR: Enumerating all ports for identifying the details of a single one looks somewhat like a brute force approach. Sure, this is what we could do with just the current public API. Did you have a look into how information for a certain port could be fetched with the enumeration mechanisms we are using (like libudev, macOS' I/O registry, SetupDiEnumDeviceInfo on Windows, ...)? I would favor such an approach because it would generate only a fraction of the runtime cost of enumerating all serial devices.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Allow getting SerialPortInfo from dyn SerialPort

2 participants