mirror of
https://github.com/fish-shell/fish-shell.git
synced 2026-06-05 16:21:15 -03:00
Remove as_ptr from IoData
We don't need this. Also improve IoChain::remove().
This commit is contained in:
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 @@ fn source_fd(&self) -> RawFd {
|
||||
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 @@ fn source_fd(&self) -> RawFd {
|
||||
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 @@ fn source_fd(&self) -> RawFd {
|
||||
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 @@ fn print(&self) {
|
||||
self.fd
|
||||
)
|
||||
}
|
||||
fn as_ptr(&self) -> *const () {
|
||||
(self as *const Self).cast()
|
||||
}
|
||||
}
|
||||
|
||||
/// Represents filling an IoBuffer. Very similar to IoPipe.
|
||||
@@ -393,9 +381,6 @@ fn print(&self) {
|
||||
self.fd()
|
||||
)
|
||||
}
|
||||
fn as_ptr(&self) -> *const () {
|
||||
(self as *const Self).cast()
|
||||
}
|
||||
fn as_bufferfill(&self) -> Option<&IoBufferfill> {
|
||||
Some(self)
|
||||
}
|
||||
@@ -512,12 +497,14 @@ pub fn new() -> Self {
|
||||
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()
|
||||
|
||||
Reference in New Issue
Block a user