Skip to content

Instantly share code, notes, and snippets.

@felipesere
Last active December 22, 2021 18:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save felipesere/3985e676bd4b233b45ab025099f9419b to your computer and use it in GitHub Desktop.
Save felipesere/3985e676bd4b233b45ab025099f9419b to your computer and use it in GitHub Desktop.
spellmaster/crates/test_terminal on  main ●●
● ❯ cargo c
Checking test_terminal v0.1.0 (/Users/felipesere/Development/rust/spellmaster/crates/test_terminal)
error[E0277]: the trait bound `&Input: std::io::Read` is not satisfied
--> src/lib.rs:25:36
|
25 | Term::read_write_pair(&*x, &*y)
| --------------------- ^^^ the trait `std::io::Read` is not implemented for `&Input`
| |
| required by a bound introduced by this call
|
= help: the following implementations were found:
<Input as std::io::Read>
note: required by a bound in `Term::read_write_pair`
--> /Users/felipesere/.cargo/registry/src/github.com-1ecc6299db9ec823/console-0.15.0/src/term.rs:183:12
|
183 | R: Read + Debug + AsRawFd + Send + 'static,
| ^^^^ required by this bound in `Term::read_write_pair`
help: consider removing the leading `&`-reference
|
25 - Term::read_write_pair(&*x, &*y)
25 + Term::read_write_pair(&*x, *y)
|
help: consider changing this borrow's mutability
|
25 | Term::read_write_pair(&*x, &mut *y)
| ~~~~
For more information about this error, try `rustc --explain E0277`.
error: could not compile `test_terminal` due to previous error
rite};
use std::fmt::Debug;
use std::os::unix::prelude::AsRawFd;
use std::sync::{Arc, Mutex};
use console::Term;
#[derive(Debug)]
pub struct TestTerminal {
input: Arc<Input>,
output: Arc<Output>,
}
impl TestTerminal {
pub fn new() -> TestTerminal {
Self {
input: Arc::new(Input::new()),
output: Arc::new(Output::new()),
}
}
pub fn term(&self) -> Term {
let x = Arc::clone(&self.input);
let y = Arc::clone(&self.output);
Term::read_write_pair(&*x, &*y)
}
}
#[derive(Debug)]
pub struct Input {
prepared_content: Arc<Mutex<String>>,
}
impl Input {
fn new() -> Self {
Self {
prepared_content: Arc::new(Mutex::new("".into())),
}
}
}
impl AsRawFd for &Input {
fn as_raw_fd(&self) -> std::os::unix::prelude::RawFd {
todo!("what do I do with a raw_fd for a test");
}
}
impl Read for Input {
fn read(&mut self, buf: &mut [u8]) -> std::io::Result<usize> {
todo!()
}
}
#[derive(Debug)]
pub struct Output {
content: Arc<Mutex<Vec<u8>>>,
}
impl Output {
fn new() -> Self {
Self {
content: Arc::new(Mutex::new(Vec::new())),
}
}
}
impl AsRawFd for &Output {
fn as_raw_fd(&self) -> std::os::unix::prelude::RawFd {
todo!("what do I do with a raw_fd for a test");
}
}
impl Write for &Output {
fn write(&mut self, buf: &[u8]) -> std::io::Result<usize> {
todo!()
}
fn flush(&mut self) -> std::io::Result<()> {
todo!()
}
}
#[cfg(test)]
mod tests {
use super::*;
fn needs_term(term: &console::Term) {}
#[test]
fn it_works() {
let term = TestTerminal::new();
needs_term(&term.term())
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment