Skip to content

Commit

Permalink
[fix]: 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 eb015c4 commit 40ab00a
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 6 deletions.
6 changes: 3 additions & 3 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

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 40ab00a

Please sign in to comment.