Skip to content

Commit

Permalink
Remove unnecessary API from StreamAdaptor
Browse files Browse the repository at this point in the history
A StreamAdaptor is only constructed internally in
RustConnection::connect() and cannot be queried by the user. Thus, we
don't need much public API for it.

This commit removes everything that we do not use internally.

If people want to call RustConnection::connect_to_stream() with a
StreamAdaptor, that is still possible, because I left new() public.

Signed-off-by: Uli Schlachter <[email protected]>
  • Loading branch information
psychon committed Feb 8, 2024
1 parent 990ad06 commit 00f97ab
Showing 1 changed file with 5 additions and 39 deletions.
44 changes: 5 additions & 39 deletions x11rb-async/src/rust_connection/stream.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ use std::pin::Pin;
use std::task::{Context, Poll};

#[cfg(unix)]
use std::os::unix::io::{AsFd, AsRawFd as AsRaw, RawFd};
use std::os::unix::io::AsFd;

#[cfg(windows)]
use std::os::windows::io::{AsRawSocket as AsRaw, AsSocket as AsFd, RawSocket};
use std::os::windows::io::AsRawSocket as AsRaw;

use async_io::Async;
use futures_lite::future;
Expand Down Expand Up @@ -53,40 +53,6 @@ impl<S: AsFd> StreamAdaptor<S> {
}
}

impl<S> StreamAdaptor<S> {
/// Get a reference to the inner stream.
pub fn get_ref(&self) -> &S {
self.inner.get_ref()
}

/// Get a mutable reference to the inner stream.
///
/// # Safety
///
/// This function inherits its unsafety from [`async_io::Async::get_mut`]. This means that the
/// underlying I/O source must not be dropped using this function.
pub unsafe fn get_mut(&mut self) -> &mut S {
self.inner.get_mut()
}

/// Consume this adaptor and return the inner stream.
pub fn into_inner(self) -> io::Result<S> {
self.inner.into_inner()
}
}

impl<S: AsRaw> AsRaw for StreamAdaptor<S> {
#[cfg(unix)]
fn as_raw_fd(&self) -> RawFd {
self.inner.get_ref().as_raw_fd()
}

#[cfg(windows)]
fn as_raw_socket(&self) -> RawSocket {
self.inner.get_ref().as_raw_socket()
}
}

/// A future for reading from a [`StreamAdaptor`].
#[derive(Debug)]
pub struct Readable<'a, S>(async_io::Readable<'a, S>);
Expand Down Expand Up @@ -143,18 +109,18 @@ impl<S: X11rbStream> X11rbStream for StreamAdaptor<S> {
}

fn read(&self, buf: &mut [u8], fd_storage: &mut Vec<RawFdContainer>) -> io::Result<usize> {
self.get_ref().read(buf, fd_storage)
self.inner.get_ref().read(buf, fd_storage)

Check warning on line 112 in x11rb-async/src/rust_connection/stream.rs

View check run for this annotation

Codecov / codecov/patch

x11rb-async/src/rust_connection/stream.rs#L112

Added line #L112 was not covered by tests
}

fn write(&self, buf: &[u8], fds: &mut Vec<RawFdContainer>) -> io::Result<usize> {
self.get_ref().write(buf, fds)
self.inner.get_ref().write(buf, fds)

Check warning on line 116 in x11rb-async/src/rust_connection/stream.rs

View check run for this annotation

Codecov / codecov/patch

x11rb-async/src/rust_connection/stream.rs#L116

Added line #L116 was not covered by tests
}

fn write_vectored(
&self,
bufs: &[io::IoSlice<'_>],
fds: &mut Vec<RawFdContainer>,
) -> io::Result<usize> {
self.get_ref().write_vectored(bufs, fds)
self.inner.get_ref().write_vectored(bufs, fds)

Check warning on line 124 in x11rb-async/src/rust_connection/stream.rs

View check run for this annotation

Codecov / codecov/patch

x11rb-async/src/rust_connection/stream.rs#L124

Added line #L124 was not covered by tests
}
}

0 comments on commit 00f97ab

Please sign in to comment.