File tree Expand file tree Collapse file tree 2 files changed +17
-0
lines changed Expand file tree Collapse file tree 2 files changed +17
-0
lines changed Original file line number Diff line number Diff line change @@ -169,6 +169,12 @@ impl ElementMap {
169
169
. and_then ( |idxs| self . elements . get ( * idxs. iter ( ) . next ( ) ?) )
170
170
}
171
171
172
+ pub fn get_mut ( & mut self , name : & str ) -> Option < & mut XmlElement > {
173
+ self . indexes
174
+ . get ( name)
175
+ . and_then ( |idxs| self . elements . get_mut ( * idxs. iter ( ) . next ( ) ?) )
176
+ }
177
+
172
178
pub fn get_all ( & self , name : & str ) -> Option < Vec < & XmlElement > > {
173
179
self . indexes
174
180
. get ( name)
Original file line number Diff line number Diff line change @@ -92,6 +92,17 @@ fn test_plugin() {
92
92
let fr = from_str :: < SdfPlugin > ( test_syntax) . unwrap ( ) ;
93
93
test_plugin_content ( & fr) ;
94
94
assert ! ( to. is_ok( ) ) ;
95
+
96
+ // Test accessing and mutating API
97
+ let test_syntax = "<plugin name=\" hello\" filename=\" world.so\" ><size>42</size></plugin>" ;
98
+ let mut plugin = from_str :: < SdfPlugin > ( test_syntax) . unwrap ( ) ;
99
+ let size = plugin. elements . get ( "size" ) . unwrap ( ) ;
100
+ assert_eq ! ( size. data, ElementData :: String ( "42" . to_string( ) ) ) ;
101
+ let size = plugin. elements . get_mut ( "size" ) . unwrap ( ) ;
102
+ size. data = ElementData :: String ( "hello" . to_string ( ) ) ;
103
+
104
+ let size = plugin. elements . get ( "size" ) . unwrap ( ) ;
105
+ assert_eq ! ( size. data, ElementData :: String ( "hello" . to_string( ) ) ) ;
95
106
}
96
107
97
108
use sdformat_rs:: SdfLight ;
You can’t perform that action at this time.
0 commit comments