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
pub
pub
pub
use crateFromArgs;
use crateFunctionError;
/// Converts a slice of `String` arguments into a typed object `T`.
///
/// This function utilizes the `FromArgs` trait to parse and convert
/// a slice of `String` arguments into a specific type `T`.
/// If the conversion fails, it returns a [`FunctionError`] with details about the error.
///
/// # Arguments
///
/// * `args` - A slice of `String` arguments to be converted.
///
/// # Returns
///
/// A `Result` where:
/// - `Ok(T)` contains the successfully parsed and typed object.
/// - `Err(FunctionError)` provides details about why the conversion failed.
///
/// # Example
///
/// ```
/// use srtemplate::prelude::{to_typed_args, FromArgs, FromArgsResult};
///
/// struct MyArgs {
/// name: String,
/// count: u8,
/// }
///
/// impl FromArgs for MyArgs {
/// fn from_args(args: &[String]) -> FromArgsResult<Self> {
/// if args.len() != 2 {
/// return Err(srtemplate::prelude::FromArgsError::ArgumentsIncomplete(args.len(), 2));
/// }
/// let name = args[0].clone();
/// let count = args[1].parse::<u8>().map_err(|_| srtemplate::prelude::FromArgsError::BadType(args[1].clone()))?;
/// Ok(MyArgs { name, count })
/// }
/// }
///
/// fn my_function(args: &[String]) -> Result<String, srtemplate::prelude::FunctionError> {
/// let my_args = to_typed_args::<MyArgs>(args)?;
/// Ok(format!("Name: {}, Count: {}", my_args.name, my_args.count))
/// }
/// ```
///
/// # Errors
///
/// Returns an error if:
/// - The number of arguments does not meet the expected count for type `T`.
/// - Any argument cannot be parsed into the required type `T`.
///
/// # Feature Flags
///
/// This function requires the `typed_args` feature to be enabled.