A Rust client library for WaitHuman - pause execution and request human input or confirmation on demand.
- Async API: Built on tokio for efficient async I/O
- Type-safe: Leverages Rust's type system for compile-time safety
- Multiple answer formats: Support for free text and multiple choice questions
- Configurable timeouts: Optional timeout support for all requests
- Ergonomic API: Generic type parameters eliminate the need for
.to_string()calls
Add this to your Cargo.toml:
[dependencies]
wait-human = "0.1"
tokio = { version = "1", features = ["rt-multi-thread", "macros"] }use wait_human::WaitHuman;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
// Create a new client
let client = WaitHuman::new_from_key("your-api-key")?;
// Ask a multiple choice question
let answer = client
.ask_multiple_choice(
"Send invoice?",
["yes, send", "no"],
Some("Customer asked for a 3-page website. is 500$ ok?"),
None,
)
.await?;
if answer == "yes, send" {
println!("Send!");
} else {
println!("wait...");
}
// Ask a free-text question
let feedback = client
.ask_free_text(
"User Feedback",
Some("Please explain why you rejected the invoice."),
None,
)
.await?;
println!("{}", feedback);
Ok(())
}Create a client with just an API key (uses default endpoint):
let client = WaitHuman::new_from_key("your-api-key")?;Create a client with custom configuration:
use wait_human::WaitHumanConfig;
let client = WaitHuman::new(
WaitHumanConfig::new("your-api-key")
.with_endpoint("https://custom.endpoint.com")
)?;Ask an open-ended text question:
let answer = client
.ask_free_text(
"What's your favorite color?",
Some("Please be specific"),
None,
)
.await?;Ask a multiple-choice question:
let choice = client
.ask_multiple_choice(
"Choose a framework",
["Actix", "Rocket", "Axum"],
None::<&str>,
None,
)
.await?;Low-level method for full control:
use wait_human::{ConfirmationQuestion, QuestionMethod, AnswerFormat};
let question = ConfirmationQuestion {
method: QuestionMethod::Push,
subject: "Approve deployment?".to_string(),
body: Some("Production environment".to_string()),
answer_format: AnswerFormat::FreeText,
};
let answer = client.ask(question, None).await?;Configure request timeouts:
use wait_human::AskOptions;
let answer = client
.ask_free_text(
"Quick question",
None::<&str>,
Some(AskOptions {
timeout_seconds: Some(30),
}),
)
.await?;The library uses Result<T, WaitHumanError> for error handling:
match client.ask_free_text("Question?", None::<&str>, None).await {
Ok(answer) => println!("Answer: {}", answer),
Err(e) => eprintln!("Error: {}", e),
}Error types include:
Timeout- Request exceeded timeoutNetworkError- Network connectivity issuesCreateFailed- Failed to create confirmationPollFailed- Failed to poll for answerUnexpectedAnswerType- Answer type mismatchInvalidSelectedIndex- Invalid choice indexInvalidResponse- Unexpected server response
Run the demo example:
cargo run --example demoThis project is licensed under the MIT License - see the LICENSE file for details.