pub async fn from_api_dir(
  path: impl AsRef<Path>,
) -> Result<Vec<SpecChunkEvent>, SpecChunkLoaderError> {
  let read_dir = fs::read_dir(path).await?;
  let mut dir_entries = ReadDirStream::new(read_dir);

  let mut chunks = Vec::<SpecChunkEvent>::new();
  while let Some(dir_entry_result) = dir_entries.next().await {
    let dir_entry = dir_entry_result?;

    let metadata = dir_entry.metadata().await?;

    if metadata.is_file() {
      let file_name = dir_entry.file_name();
      let file_path = dir_entry.path();

      let spec_events_result = spec_events::from_file(&file_path).await;
      if spec_events_result.is_err() {
        // TODO: consider logging this better
        eprintln!(
          "skipping file: not valid spec events path={:?}: {:?}",
          &file_path,
          spec_events_result.unwrap_err()
        );
        continue;
      }
      let spec_events = spec_events_result.unwrap();
      let name = file_name.into_string().map_err(|_| {
        SpecChunkLoaderError::Other("Filename could not be converted to valid UTF-8")
      })?;
      let is_root = name == "specification.json";

      chunks.push(SpecChunkEvent::from((name, is_root, spec_events)));
    }
  }

  Ok(chunks)
}
// TODO: return a stream instead of a Vec
return a stream instead of a Vec
return a stream instead of a Vec
pub async fn from_api_dir(
  path: impl AsRef<Path>,
) -> Result<Vec<SpecChunkEvent>, SpecChunkLoaderError> {
  let read_dir = fs::read_dir(path).await?;
  let mut dir_entries = ReadDirStream::new(read_dir);
  let mut chunks = Vec::<SpecChunkEvent>::new();
  while let Some(dir_entry_result) = dir_entries.next().await {
    let dir_entry = dir_entry_result?;
    let metadata = dir_entry.metadata().await?;
    if metadata.is_file() {
      let file_name = dir_entry.file_name();
      let file_path = dir_entry.path();
      let spec_events_result = spec_events::from_file(&file_path).await;
      if spec_events_result.is_err() {
        // TODO: consider logging this better
        eprintln!(
          "skipping file: not valid spec events path={:?}: {:?}",
          &file_path,
          spec_events_result.unwrap_err()
        );
        continue;
      }
      let spec_events = spec_events_result.unwrap();
      let name = file_name.into_string().map_err(|_| {
        SpecChunkLoaderError::Other("Filename could not be converted to valid UTF-8")
      })?;
      let is_root = name == "specification.json";
      chunks.push(SpecChunkEvent::from((name, is_root, spec_events)));
    }
  }
  Ok(chunks)
}
pub async fn from_api_dir ( path : impl AsRef < Path > , ) -> Result < Vec < SpecChunkEvent > , SpecChunkLoaderError > { let read_dir = fs :: read_dir ( path ) . await ? ; let mut dir_entries = ReadDirStream :: new ( read_dir ) ; let mut chunks = Vec :: < SpecChunkEvent > :: new ( ) ; while let Some ( dir_entry_result ) = dir_entries . next ( ) . await { let dir_entry = dir_entry_result ? ; let metadata = dir_entry . metadata ( ) . await ? ; if metadata . is_file ( ) { let file_name = dir_entry . file_name ( ) ; let file_path = dir_entry . path ( ) ; let spec_events_result = spec_events :: from_file ( & file_path ) . await ; if spec_events_result . is_err ( ) { // TODO: consider logging this better eprintln ! ( " " file_path spec_events_result unwrap_err ( ) ) ; continue ; } let spec_events = spec_events_result . unwrap ( ) ; let name = file_name . into_string ( ) . map_err ( | _ | { SpecChunkLoaderError :: Other ( " " ) } ) ? ; let is_root = name == " " ; chunks . push ( SpecChunkEvent :: from ( ( name , is_root , spec_events ) ) ) ; } } Ok ( chunks ) }
TODO: return a stream instead of a Vec
TODO : return a stream instead of a Vec
path
impl AsRef<Path>
path
impl AsRef<Path>