Skip to main content

clawless_core/prompt/
confirmation.rs

1/// The answer of a user to a [`Confirm`] prompt
2///
3/// The answer is an enum and not a `bool`, so that a `match` on it names both answers.
4///
5/// # Examples
6///
7/// ```
8/// use clawless_core::prompt::{Confirm, Confirmation};
9///
10/// let question = Confirm::new("Delete the branch?").with_default(Confirmation::No);
11///
12/// assert_eq!(question.default(), Some(Confirmation::No));
13/// ```
14///
15/// [`Confirm`]: super::Confirm
16#[derive(Copy, Clone, Eq, PartialEq, Hash, Debug)]
17pub enum Confirmation {
18    /// The user agreed
19    Yes,
20    /// The user declined
21    No,
22}
23
24#[cfg(test)]
25mod tests {
26    use super::*;
27
28    #[test]
29    fn trait_send() {
30        fn assert_send<T: Send>() {}
31        assert_send::<Confirmation>();
32    }
33
34    #[test]
35    fn trait_sync() {
36        fn assert_sync<T: Sync>() {}
37        assert_sync::<Confirmation>();
38    }
39
40    #[test]
41    fn trait_unpin() {
42        fn assert_unpin<T: Unpin>() {}
43        assert_unpin::<Confirmation>();
44    }
45}