#[cfg(doc)]
use async_std::io::{ReadExt, prelude::SeekExt};
pub mod parse;
pub mod wad_source;
mod arc_vec;
use parse::*;
use wad_source::*;
use futures::{StreamExt, TryFutureExt, TryStream};
use crate::repr::{texture::Texture, Wad};
pub type IoError = async_std::io::Error;
pub trait TextureStream: TryStream<Ok = (String, Texture), Error = IoError> {}
impl<T> TextureStream for T where T: TryStream<Ok = (String, Texture), Error = IoError> {}
pub async fn parse_wad<S, W>(handle_stream: S) -> Result<Wad, IoError>
where
S: 'static + WadSourceStream<W>,
W: 'static + WadSource + Send + Unpin,
{
parse_textures::<S, W>(handle_stream)
.and_then(Wad::from_stream)
.await
}
pub async fn parse_textures<S, W>(mut s: S) -> Result<TexStream, IoError>
where
S: 'static + WadSourceStream<W>,
W: 'static + WadSource + Send + Unpin,
{
let handle = s.next().await.unwrap()?;
let header = parse_header(handle).await?;
let stream = parse_header_textures(s, header).await?;
Ok(stream)
}