Skip to content

Design decisions behind having poll_close in AsyncWrite? #2999

@sirhcel

Description

@sirhcel

TL;DR

What are the design decisions behind having poll_close in AsyncWrite and not in a separate trait like AsyncClose? I'm wondering because close is not part of std::io::Write which does not mandate making closing explicit and allows "close on drop" like std::fs::File

Background Story

First and foremost, thank you very much for this crate! We are currently evaluating adding async support to serialport-rs with futures-rs and I really like how this bridges to smol and tokio which we use as initial targets for our PoC.

Today, I started the discussion on why the async variant of a serial port needs to be closable where the already existing sync variant handles this as "close on drop" like for example std::io::File. I learned that closing is part of AsyncWrite which requires to deal with the concept of closing in the async serial port as well.

Having only little work done with async I/O, smol, and tokio so far, I would have it expected to be separate from AsyncWrite. The AsyncRead trait does not support closing and so I would naively have it expected in a trait like AsyncClose. The latter would have allowed to keep the async variant of a serialport "close on drop" as well. So I'm really wondering and interested in the design decisions behind having poll_close in AsyncWrite?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions