]> git.lizzy.rs Git - rust.git/blob - tests/ui-fulldeps/issue-2804.rs
Rollup merge of #107271 - Zeegomo:drop-rmw, r=oli-obk
[rust.git] / tests / ui-fulldeps / issue-2804.rs
1 // run-pass
2
3 #![allow(non_camel_case_types)]
4 #![allow(dead_code)]
5
6 use std::collections::{BTreeMap, HashMap};
7 use std::option;
8
9 #[derive(Clone, Debug)]
10 enum Json {
11     I64(i64),
12     U64(u64),
13     F64(f64),
14     String(String),
15     Boolean(bool),
16     Array(Array),
17     Object(Object),
18     Null,
19 }
20
21 type Array = Vec<Json>;
22 type Object = BTreeMap<String, Json>;
23
24 enum object {
25     bool_value(bool),
26     int_value(i64),
27 }
28
29 fn lookup(table: Object, key: String, default: String) -> String
30 {
31     match table.get(&key) {
32         option::Option::Some(&Json::String(ref s)) => {
33             s.to_string()
34         }
35         option::Option::Some(value) => {
36             println!("{} was expected to be a string but is a {:?}", key, value);
37             default
38         }
39         option::Option::None => {
40             default
41         }
42     }
43 }
44
45 fn add_interface(_store: isize, managed_ip: String, data: Json) -> (String, object)
46 {
47     match &data {
48         &Json::Object(ref interface) => {
49             let name = lookup(interface.clone(),
50                               "ifDescr".to_string(),
51                               "".to_string());
52             let label = format!("{}-{}", managed_ip, name);
53
54             (label, object::bool_value(false))
55         }
56         _ => {
57             println!("Expected dict for {} interfaces, found {:?}", managed_ip, data);
58             ("gnos:missing-interface".to_string(), object::bool_value(true))
59         }
60     }
61 }
62
63 fn add_interfaces(store: isize, managed_ip: String, device: HashMap<String, Json>)
64 -> Vec<(String, object)> {
65     match device["interfaces"] {
66         Json::Array(ref interfaces) =>
67         {
68           interfaces.iter().map(|interface| {
69                 add_interface(store, managed_ip.clone(), (*interface).clone())
70           }).collect()
71         }
72         _ =>
73         {
74             println!("Expected list for {} interfaces, found {:?}", managed_ip,
75                      device["interfaces"]);
76             Vec::new()
77         }
78     }
79 }
80
81 pub fn main() {}