feat: added deref impl for backend types

This commit is contained in:
Ahmad 2022-06-03 19:49:13 +02:00 committed by Josh McKinney
parent ad288f5168
commit 10aeccff1a
No known key found for this signature in database
GPG key ID: 722287396A903BC5
2 changed files with 33 additions and 1 deletions

View file

@ -5,7 +5,10 @@
//! [`Backend`]: trait.Backend.html
//! [`CrosstermBackend`]: struct.CrosstermBackend.html
use std::io::{self, Write};
use std::{
io::{self, Write},
ops::{Deref, DerefMut},
};
use crossterm::{
cursor::{Hide, MoveTo, Show},
@ -71,6 +74,20 @@ where
}
}
impl<W: Write> Deref for CrosstermBackend<W> {
type Target = W;
fn deref(&self) -> &Self::Target {
&self.buffer
}
}
impl<W: Write> DerefMut for CrosstermBackend<W> {
fn deref_mut(&mut self) -> &mut Self::Target {
&mut self.buffer
}
}
impl<W> Backend for CrosstermBackend<W>
where
W: Write,

View file

@ -7,6 +7,7 @@
use std::{
fmt,
io::{self, Write},
ops::{Deref, DerefMut},
};
use crate::{
@ -61,6 +62,20 @@ where
}
}
impl<W: Write> Deref for TermionBackend<W> {
type Target = W;
fn deref(&self) -> &Self::Target {
&self.stdout
}
}
impl<W: Write> DerefMut for TermionBackend<W> {
fn deref_mut(&mut self) -> &mut Self::Target {
&mut self.stdout
}
}
impl<W> Backend for TermionBackend<W>
where
W: Write,