Skip to content

Commit

Permalink
Evil commit: Fixed removing tokio dep from wasm targeted builds
Browse files Browse the repository at this point in the history
  • Loading branch information
batconjurer committed Sep 19, 2023
1 parent de1d926 commit e3516d7
Showing 1 changed file with 27 additions and 3 deletions.
30 changes: 27 additions & 3 deletions shared/src/types/io.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,18 +42,41 @@ pub trait Io {
eprintln!("{}", output.as_ref());
}

async fn read() -> tokio::io::Result<String> {
read_aux(tokio::io::stdin()).await
async fn read() -> std::io::Result<String> {
#[cfg(not(target_family = "wasm"))]
{
read_aux(tokio::io::stdin()).await
}
#[cfg(target_family = "wasm")]
{
unreachable!("Wasm should not perform general IO")
}
}

async fn prompt(question: impl AsRef<str>) -> String {
prompt_aux(tokio::io::stdin(), tokio::io::stdout(), question.as_ref())
#[cfg(not(target_family = "wasm"))]
{
prompt_aux(
tokio::io::stdin(),
tokio::io::stdout(),
question.as_ref(),
)
.await
}
#[cfg(target_family = "wasm")]
{
unreachable!(
"Wasm should not perform general IO; received call for input \
with question\n: {}",
question.as_ref()
)
}
}
}

/// A generic function for displaying a prompt to users and reading
/// in their response.
#[cfg(not(target_family = "wasm"))]
pub async fn prompt_aux<R, W>(
mut reader: R,
mut writer: W,
Expand All @@ -74,6 +97,7 @@ where
}

/// A generic function for reading input from users
#[cfg(not(target_family = "wasm"))]
pub async fn read_aux<R>(mut reader: R) -> tokio::io::Result<String>
where
R: tokio::io::AsyncReadExt + Unpin,
Expand Down

0 comments on commit e3516d7

Please sign in to comment.