mirror of
https://github.com/fish-shell/fish-shell
synced 2025-01-25 19:25:06 +00:00
Remove as_ptr from IoData
We don't need this. Also improve IoChain::remove().
This commit is contained in:
parent
f6d76d2057
commit
4b9767ce83
1 changed files with 10 additions and 23 deletions
33
src/io.rs
33
src/io.rs
|
@ -178,8 +178,8 @@ pub trait IoData: Send + Sync {
|
|||
/// That is, we call dup2(source_fd, fd).
|
||||
fn source_fd(&self) -> RawFd;
|
||||
fn print(&self);
|
||||
// The address of the object, for comparison.
|
||||
fn as_ptr(&self) -> *const ();
|
||||
|
||||
// If this is an IoBufferfill, return a reference to it.
|
||||
fn as_bufferfill(&self) -> Option<&IoBufferfill> {
|
||||
None
|
||||
}
|
||||
|
@ -206,9 +206,6 @@ impl IoData for IoClose {
|
|||
fn print(&self) {
|
||||
eprintf!("close %d\n", self.fd)
|
||||
}
|
||||
fn as_ptr(&self) -> *const () {
|
||||
(self as *const Self).cast()
|
||||
}
|
||||
}
|
||||
|
||||
pub struct IoFd {
|
||||
|
@ -235,9 +232,6 @@ impl IoData for IoFd {
|
|||
fn print(&self) {
|
||||
eprintf!("FD map %d -> %d\n", self.source_fd, self.fd)
|
||||
}
|
||||
fn as_ptr(&self) -> *const () {
|
||||
(self as *const Self).cast()
|
||||
}
|
||||
}
|
||||
|
||||
/// Represents a redirection to or from an opened file.
|
||||
|
@ -267,9 +261,6 @@ impl IoData for IoFile {
|
|||
fn print(&self) {
|
||||
eprintf!("file %d -> %d\n", self.file.as_raw_fd(), self.fd)
|
||||
}
|
||||
fn as_ptr(&self) -> *const () {
|
||||
(self as *const Self).cast()
|
||||
}
|
||||
}
|
||||
|
||||
/// Represents (one end) of a pipe.
|
||||
|
@ -307,9 +298,6 @@ impl IoData for IoPipe {
|
|||
self.fd
|
||||
)
|
||||
}
|
||||
fn as_ptr(&self) -> *const () {
|
||||
(self as *const Self).cast()
|
||||
}
|
||||
}
|
||||
|
||||
/// Represents filling an IoBuffer. Very similar to IoPipe.
|
||||
|
@ -393,9 +381,6 @@ impl IoData for IoBufferfill {
|
|||
self.fd()
|
||||
)
|
||||
}
|
||||
fn as_ptr(&self) -> *const () {
|
||||
(self as *const Self).cast()
|
||||
}
|
||||
fn as_bufferfill(&self) -> Option<&IoBufferfill> {
|
||||
Some(self)
|
||||
}
|
||||
|
@ -512,12 +497,14 @@ impl IoChain {
|
|||
Default::default()
|
||||
}
|
||||
pub fn remove(&mut self, element: &dyn IoData) {
|
||||
let element = element as *const _;
|
||||
let element = element as *const ();
|
||||
self.0.retain(|e| {
|
||||
let e = Arc::as_ptr(e) as *const ();
|
||||
!std::ptr::eq(e, element)
|
||||
});
|
||||
// Discard vtable pointers when comparing.
|
||||
let e1 = element as *const dyn IoData as *const ();
|
||||
let idx = self
|
||||
.0
|
||||
.iter()
|
||||
.position(|e2| Arc::as_ref(e2) as *const dyn IoData as *const () == e1)
|
||||
.expect("Element not found");
|
||||
self.0.remove(idx);
|
||||
}
|
||||
pub fn clear(&mut self) {
|
||||
self.0.clear()
|
||||
|
|
Loading…
Reference in a new issue