}
}
+#[derive(Debug, Serialize)]
+struct HLQuery {
+ input: String,
+ result: Result<Vec<HLQueryResult>, HLQueryError>
+}
+
+impl HLQuery {
+ fn new(input: String, result: Result<Vec<HLQueryResult>, HLQueryError>) -> Self {
+ Self { input, result }
+ }
+}
+
#[derive(Debug)]
enum HLQueryError {
IOError(std::io::Error),
fn main() {
let client = A2SClient::new().unwrap();
- let query_results: Vec<Result<Vec<HLQueryResult>, HLQueryError>> = args().skip(1)
- .map(|arg| arg.to_socket_addrs())
+ let query_results: Vec<HLQuery> = args().skip(1)
+ .map(|arg| {
+ let addresses = arg.to_socket_addrs();
+ (arg, addresses)
+ })
.map(|lookup_result| match lookup_result {
- Ok(iter_addr) => {
- Ok(iter_addr.filter_map(|sa| match sa {
+ (input, Ok(iter_addr)) => {
+ (input, Ok(iter_addr.filter_map(|sa| match sa {
SocketAddr::V4(sa4) => Some(sa4),
_ => None
- }))
+ })))
},
- Err(e) => Err(HLQueryError::IOError(e))
+ (input, Err(e)) => (input, Err(HLQueryError::IOError(e)))
})
- .map(|address_group| address_group.map(|addresses| addresses.map(|addr| HLQueryResult::new(&client, addr)).collect()))
+ .map(|(input, address_group)| HLQuery::new(input, address_group.map(
+ |addresses| addresses.map(|addr| HLQueryResult::new(&client, addr)).collect())))
.collect();
println!("{}\n", serde_json::to_string_pretty(&query_results).unwrap());