1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
mod private
{
use std ::io :: { self, Write };
/// Ask use input from standard input.
#[ must_use ]
pub fn ask( request: &str ) -> String
{
let mut response = String ::new();
print!( "{request} : " );
io ::stdout().flush().ok();
io ::stdin().read_line( &mut response ).ok();
response.trim().to_string()
}
/// A structure representing an input with a single string value.
///
/// This struct is designed to encapsulate a single piece of input data as a `Vec< String >`.
/// It provides a simple wrapper that can be used to convert various types of string
/// representations into a uniform `Input` struct.
#[ derive( Debug ) ]
pub struct Input( pub Vec< String > );
/// A trait for converting various types into `Input`.
///
/// The `IntoInput` trait defines a method `into_input` for converting an implementing type
/// into the `Input` struct. This allows for a flexible way of handling different string
/// representations and aggregating them into a single `Input` type.
pub trait IntoInput
{
/// Converts the implementing type into an `Input` instance.
///
/// # Examples
///
/// Basic usage :
///
/// ```
/// use wca ::IntoInput;
///
/// let string_input: &str = "example string";
/// let input_struct = string_input.into_input();
///
/// let owned_string_input: String = "owned example".to_string();
/// let owned_input_struct = owned_string_input.into_input();
/// ```
fn into_input( self ) -> Input;
}
impl IntoInput for &str
{
fn into_input( self ) -> Input
{
Input( self.split( ' ' ).map( ToString ::to_string ).collect() )
}
}
impl IntoInput for String
{
fn into_input( self ) -> Input
{
Input( self.split( ' ' ).map( ToString ::to_string ).collect() )
}
}
impl IntoInput for Vec< String >
{
fn into_input( self ) -> Input
{
Input( self )
}
}
}
//
crate ::mod_interface!
{
exposed use ask;
exposed use Input;
exposed use IntoInput;
}