mirror of
https://github.com/fish-shell/fish-shell.git
synced 2026-06-06 17:31:14 -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).
|
/// That is, we call dup2(source_fd, fd).
|
||||||
fn source_fd(&self) -> RawFd;
|
fn source_fd(&self) -> RawFd;
|
||||||
fn print(&self);
|
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> {
|
fn as_bufferfill(&self) -> Option<&IoBufferfill> {
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
@@ -206,9 +206,6 @@ fn source_fd(&self) -> RawFd {
|
|||||||
fn print(&self) {
|
fn print(&self) {
|
||||||
eprintf!("close %d\n", self.fd)
|
eprintf!("close %d\n", self.fd)
|
||||||
}
|
}
|
||||||
fn as_ptr(&self) -> *const () {
|
|
||||||
(self as *const Self).cast()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct IoFd {
|
pub struct IoFd {
|
||||||
@@ -235,9 +232,6 @@ fn source_fd(&self) -> RawFd {
|
|||||||
fn print(&self) {
|
fn print(&self) {
|
||||||
eprintf!("FD map %d -> %d\n", self.source_fd, self.fd)
|
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.
|
/// Represents a redirection to or from an opened file.
|
||||||
@@ -267,9 +261,6 @@ fn source_fd(&self) -> RawFd {
|
|||||||
fn print(&self) {
|
fn print(&self) {
|
||||||
eprintf!("file %d -> %d\n", self.file.as_raw_fd(), self.fd)
|
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.
|
/// Represents (one end) of a pipe.
|
||||||
@@ -307,9 +298,6 @@ fn print(&self) {
|
|||||||
self.fd
|
self.fd
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
fn as_ptr(&self) -> *const () {
|
|
||||||
(self as *const Self).cast()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Represents filling an IoBuffer. Very similar to IoPipe.
|
/// Represents filling an IoBuffer. Very similar to IoPipe.
|
||||||
@@ -393,9 +381,6 @@ fn print(&self) {
|
|||||||
self.fd()
|
self.fd()
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
fn as_ptr(&self) -> *const () {
|
|
||||||
(self as *const Self).cast()
|
|
||||||
}
|
|
||||||
fn as_bufferfill(&self) -> Option<&IoBufferfill> {
|
fn as_bufferfill(&self) -> Option<&IoBufferfill> {
|
||||||
Some(self)
|
Some(self)
|
||||||
}
|
}
|
||||||
@@ -512,12 +497,14 @@ pub fn new() -> Self {
|
|||||||
Default::default()
|
Default::default()
|
||||||
}
|
}
|
||||||
pub fn remove(&mut self, element: &dyn IoData) {
|
pub fn remove(&mut self, element: &dyn IoData) {
|
||||||
let element = element as *const _;
|
// Discard vtable pointers when comparing.
|
||||||
let element = element as *const ();
|
let e1 = element as *const dyn IoData as *const ();
|
||||||
self.0.retain(|e| {
|
let idx = self
|
||||||
let e = Arc::as_ptr(e) as *const ();
|
.0
|
||||||
!std::ptr::eq(e, element)
|
.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) {
|
pub fn clear(&mut self) {
|
||||||
self.0.clear()
|
self.0.clear()
|
||||||
|
|||||||
Reference in New Issue
Block a user