Closed hannobraun closed 7 years ago
What if I'm sharing the terminal between threads? I happen to be doing just that.
@ArtemGr I believe your use case will not be affected at all. Send
is automatically derived by the Rust compiler wherever that is possible. That means, TerminfoTerminal<T>
will be Send
, if T
is Send
.
Currently, T
is explicitly required to be Send
, even though TerminfoTerminal
itself doesn't actually need that capability. That means, you can never use a T
that is not Send
, even if you don't actually need TerminfoTerminal<T>
to be Send
.
So, to summarize: Unless I misunderstand the subtleties of Send
, this change should make my use case possible, without changing anything about yours :)
Oh, cool. Maybe we're talking about the differend Send
s even! I'm only sharing the https://docs.rs/term/0.4.4/term/type.StdoutTerminal.html between threads. Thanks for clearing things out, though.
I wonder if it even worth it to reuse the terminal. Right now all it saves is one Box::new
it seems. On the other hand, if fn stdout()
will make some extra checks in the future, such as isatty
as discussed in #54, then suddenly I'm saving on I/O.
TBH, I wouldn't even be sharing the terminal handler between threads if I weren't using isatty
myself. Here's what I do:
let stdout = Arc::new (if unsafe {libc::isatty (1)} != 0 {term::stdout().map (|s| Mutex::new (s))} else {None});
Sorry for the long delay, LGTM
No problem. Thanks for looking into it!
As far as I can tell, the
Send
bound doesn't serve any purpose and removing it didn't seem to have any adverse effects.