use std::{future::Future, pin::Pin};
use crate::client::{Error, SftpClient};
use crate::message::{Handle, Name};
mod close;
mod stream;
pub struct Dir {
client: SftpClient,
handle: Option<Handle>,
buffer: Option<Name>,
pending: Option<PendingOperation>,
}
type PendingOperation = Pin<Box<dyn Future<Output = Result<Name, Error>> + Send + Sync + 'static>>;
impl Dir {
pub fn new(client: SftpClient, handle: Handle) -> Self {
Dir {
client,
handle: Some(handle),
buffer: Some(Default::default()),
pending: None,
}
}
pub const fn new_closed() -> Self {
Dir {
client: SftpClient::new_stopped(),
handle: None,
buffer: None,
pending: None,
}
}
}
pub static DIR_CLOSED: Dir = Dir::new_closed();
impl std::fmt::Debug for Dir {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.debug_struct("Dir")
.field("client", &self.client)
.field("handle", &self.handle)
.field("buffer", &self.buffer)
.field("pending", &self.pending.as_ref().map(|_| "..."))
.finish()
}
}