Loading system/gd/rust/linux/dbus_projection/dbus_macros/src/lib.rs +0 −79 Original line number Diff line number Diff line Loading @@ -854,7 +854,6 @@ pub fn generate_dbus_arg(_item: TokenStream) -> TokenStream { use std::error::Error; use std::fmt; use std::hash::Hash; use std::sync::{Arc, Mutex}; // Key for serialized Option<T> in propmap Loading Loading @@ -992,34 +991,6 @@ pub fn generate_dbus_arg(_item: TokenStream) -> TokenStream { } } impl< K: 'static + Eq + Hash + RefArgToRust<RustType = K>, V: 'static + RefArgToRust<RustType = V> > RefArgToRust for std::collections::HashMap<K, V> { type RustType = std::collections::HashMap<K, V>; fn ref_arg_to_rust( arg: &(dyn dbus::arg::RefArg + 'static), name: String, ) -> Result<Self::RustType, Box<dyn Error>> { let mut map: std::collections::HashMap<K, V> = std::collections::HashMap::new(); let mut iter = arg.as_iter().unwrap(); let mut key = iter.next(); let mut val = iter.next(); while !key.is_none() && !val.is_none() { let k = key.unwrap().box_clone(); let k = <K as RefArgToRust>::ref_arg_to_rust(&k, name.clone() + " key")?; let v = val.unwrap().box_clone(); let v = <V as RefArgToRust>::ref_arg_to_rust(&v, name.clone() + " value")?; map.insert(k, v); key = iter.next(); val = iter.next(); } Ok(map) } } /// Trait describing how to convert to and from a D-Bus type. /// /// All Rust structs that need to be serialized to and from D-Bus need Loading Loading @@ -1182,56 +1153,6 @@ pub fn generate_dbus_arg(_item: TokenStream) -> TokenStream { Ok(props) } } impl<K: Eq + Hash + DBusArg, V: DBusArg> DBusArg for std::collections::HashMap<K, V> where <K as DBusArg>::DBusType: 'static + Eq + Hash + dbus::arg::RefArg + RefArgToRust<RustType = <K as DBusArg>::DBusType>, { type DBusType = std::collections::HashMap<K::DBusType, V::DBusType>; fn from_dbus( data: std::collections::HashMap<K::DBusType, V::DBusType>, conn: Option<std::sync::Arc<dbus::nonblock::SyncConnection>>, remote: Option<dbus::strings::BusName<'static>>, disconnect_watcher: Option< std::sync::Arc<std::sync::Mutex<dbus_projection::DisconnectWatcher>>>, ) -> Result<std::collections::HashMap<K, V>, Box<dyn std::error::Error>> { let mut map = std::collections::HashMap::new(); for (key, val) in data { let k = K::from_dbus( key, conn.clone(), remote.clone(), disconnect_watcher.clone() )?; let v = V::from_dbus( val, conn, remote, disconnect_watcher )?; map.insert(k, v); } Ok(map) } fn to_dbus( data: std::collections::HashMap<K, V>, ) -> Result<std::collections::HashMap<K::DBusType, V::DBusType>, Box<dyn std::error::Error>> { let mut map = std::collections::HashMap::new(); for (key, val) in data { let k = K::to_dbus(key)?; let v = V::to_dbus(val)?; map.insert(k, v); } Ok(map) } } }; debug_output_to_file(&gen, format!("out-generate_dbus_arg.rs")); Loading system/gd/rust/linux/dbus_projection/tests/conversions.rs +0 −25 Original line number Diff line number Diff line use core::any::Any; use std::collections::HashMap; use dbus_macros::{dbus_propmap, generate_dbus_arg}; Loading @@ -24,7 +23,6 @@ struct SomeStruct { number: i32, other_struct: OtherStruct, bytes: Vec<u8>, dict: HashMap<String, Vec<i32>>, nested: Vec<Vec<String>>, recursive: Vec<SomeStruct>, } Loading @@ -35,7 +33,6 @@ struct SomeStructDBus { number: i32, other_struct: OtherStruct, bytes: Vec<u8>, dict: HashMap<String, Vec<i32>>, nested: Vec<Vec<String>>, recursive: Vec<SomeStruct>, } Loading Loading @@ -115,13 +112,6 @@ mod tests { }), ), (String::from("bytes"), Box::new(vec![1 as u8, 2, 3])), ( String::from("dict"), Box::new(HashMap::from([ (String::from("key-0"), Box::new(vec![5, 6, 7, 8])), (String::from("key-1"), Box::new(vec![-5, -6, -7, -8])), ])), ), ( String::from("nested"), Box::new(vec![ Loading Loading @@ -149,13 +139,6 @@ mod tests { }), ), (String::from("bytes"), Box::new(Vec::<u8>::new())), ( String::from("dict"), Box::new(HashMap::from([ (String::from("key-2"), Box::new(vec![5, 5, 6, 8, 8])), (String::from("key-3"), Box::new(vec![])), ])), ), (String::from("nested"), Box::new(Vec::<Vec<u8>>::new())), (String::from("recursive"), Box::new(Vec::<FakeDictionary>::new())), ], Loading @@ -175,10 +158,6 @@ mod tests { number: 100, other_struct: OtherStruct { address: String::from("aa:bb:cc:dd:ee:ff") }, bytes: vec![1, 2, 3], dict: HashMap::from([ (String::from("key-0"), vec![5, 6, 7, 8]), (String::from("key-1"), vec![-5, -6, -7, -8]), ]), nested: vec![ vec![String::from("string a"), String::from("string b"), String::from("string c")], vec![String::from("string 1"), String::from("string 2")], Loading @@ -188,10 +167,6 @@ mod tests { number: 200, other_struct: OtherStruct { address: String::from("xx") }, bytes: vec![], dict: HashMap::from([ (String::from("key-2"), vec![5, 5, 6, 8, 8]), (String::from("key-3"), vec![]), ]), nested: vec![], recursive: vec![], }], Loading Loading
system/gd/rust/linux/dbus_projection/dbus_macros/src/lib.rs +0 −79 Original line number Diff line number Diff line Loading @@ -854,7 +854,6 @@ pub fn generate_dbus_arg(_item: TokenStream) -> TokenStream { use std::error::Error; use std::fmt; use std::hash::Hash; use std::sync::{Arc, Mutex}; // Key for serialized Option<T> in propmap Loading Loading @@ -992,34 +991,6 @@ pub fn generate_dbus_arg(_item: TokenStream) -> TokenStream { } } impl< K: 'static + Eq + Hash + RefArgToRust<RustType = K>, V: 'static + RefArgToRust<RustType = V> > RefArgToRust for std::collections::HashMap<K, V> { type RustType = std::collections::HashMap<K, V>; fn ref_arg_to_rust( arg: &(dyn dbus::arg::RefArg + 'static), name: String, ) -> Result<Self::RustType, Box<dyn Error>> { let mut map: std::collections::HashMap<K, V> = std::collections::HashMap::new(); let mut iter = arg.as_iter().unwrap(); let mut key = iter.next(); let mut val = iter.next(); while !key.is_none() && !val.is_none() { let k = key.unwrap().box_clone(); let k = <K as RefArgToRust>::ref_arg_to_rust(&k, name.clone() + " key")?; let v = val.unwrap().box_clone(); let v = <V as RefArgToRust>::ref_arg_to_rust(&v, name.clone() + " value")?; map.insert(k, v); key = iter.next(); val = iter.next(); } Ok(map) } } /// Trait describing how to convert to and from a D-Bus type. /// /// All Rust structs that need to be serialized to and from D-Bus need Loading Loading @@ -1182,56 +1153,6 @@ pub fn generate_dbus_arg(_item: TokenStream) -> TokenStream { Ok(props) } } impl<K: Eq + Hash + DBusArg, V: DBusArg> DBusArg for std::collections::HashMap<K, V> where <K as DBusArg>::DBusType: 'static + Eq + Hash + dbus::arg::RefArg + RefArgToRust<RustType = <K as DBusArg>::DBusType>, { type DBusType = std::collections::HashMap<K::DBusType, V::DBusType>; fn from_dbus( data: std::collections::HashMap<K::DBusType, V::DBusType>, conn: Option<std::sync::Arc<dbus::nonblock::SyncConnection>>, remote: Option<dbus::strings::BusName<'static>>, disconnect_watcher: Option< std::sync::Arc<std::sync::Mutex<dbus_projection::DisconnectWatcher>>>, ) -> Result<std::collections::HashMap<K, V>, Box<dyn std::error::Error>> { let mut map = std::collections::HashMap::new(); for (key, val) in data { let k = K::from_dbus( key, conn.clone(), remote.clone(), disconnect_watcher.clone() )?; let v = V::from_dbus( val, conn, remote, disconnect_watcher )?; map.insert(k, v); } Ok(map) } fn to_dbus( data: std::collections::HashMap<K, V>, ) -> Result<std::collections::HashMap<K::DBusType, V::DBusType>, Box<dyn std::error::Error>> { let mut map = std::collections::HashMap::new(); for (key, val) in data { let k = K::to_dbus(key)?; let v = V::to_dbus(val)?; map.insert(k, v); } Ok(map) } } }; debug_output_to_file(&gen, format!("out-generate_dbus_arg.rs")); Loading
system/gd/rust/linux/dbus_projection/tests/conversions.rs +0 −25 Original line number Diff line number Diff line use core::any::Any; use std::collections::HashMap; use dbus_macros::{dbus_propmap, generate_dbus_arg}; Loading @@ -24,7 +23,6 @@ struct SomeStruct { number: i32, other_struct: OtherStruct, bytes: Vec<u8>, dict: HashMap<String, Vec<i32>>, nested: Vec<Vec<String>>, recursive: Vec<SomeStruct>, } Loading @@ -35,7 +33,6 @@ struct SomeStructDBus { number: i32, other_struct: OtherStruct, bytes: Vec<u8>, dict: HashMap<String, Vec<i32>>, nested: Vec<Vec<String>>, recursive: Vec<SomeStruct>, } Loading Loading @@ -115,13 +112,6 @@ mod tests { }), ), (String::from("bytes"), Box::new(vec![1 as u8, 2, 3])), ( String::from("dict"), Box::new(HashMap::from([ (String::from("key-0"), Box::new(vec![5, 6, 7, 8])), (String::from("key-1"), Box::new(vec![-5, -6, -7, -8])), ])), ), ( String::from("nested"), Box::new(vec![ Loading Loading @@ -149,13 +139,6 @@ mod tests { }), ), (String::from("bytes"), Box::new(Vec::<u8>::new())), ( String::from("dict"), Box::new(HashMap::from([ (String::from("key-2"), Box::new(vec![5, 5, 6, 8, 8])), (String::from("key-3"), Box::new(vec![])), ])), ), (String::from("nested"), Box::new(Vec::<Vec<u8>>::new())), (String::from("recursive"), Box::new(Vec::<FakeDictionary>::new())), ], Loading @@ -175,10 +158,6 @@ mod tests { number: 100, other_struct: OtherStruct { address: String::from("aa:bb:cc:dd:ee:ff") }, bytes: vec![1, 2, 3], dict: HashMap::from([ (String::from("key-0"), vec![5, 6, 7, 8]), (String::from("key-1"), vec![-5, -6, -7, -8]), ]), nested: vec![ vec![String::from("string a"), String::from("string b"), String::from("string c")], vec![String::from("string 1"), String::from("string 2")], Loading @@ -188,10 +167,6 @@ mod tests { number: 200, other_struct: OtherStruct { address: String::from("xx") }, bytes: vec![], dict: HashMap::from([ (String::from("key-2"), vec![5, 5, 6, 8, 8]), (String::from("key-3"), vec![]), ]), nested: vec![], recursive: vec![], }], Loading