Processing a considerable number of large XML files may require a lot of memory and processing power. With Rust, we can create applications that process huge XML files with a relatively small memory footprint yet are still performant. This post shows how to generate simple EPCIS 1.2 XML using Rust.
Rust Requirements To Write Out EPCIS 1.2 XML
We used the following items for this post.
- Rust 1.52.1
- Cargo
- Rust Crates
- Intellij IDEA
- Rust plugin for Intellij IDEA
Target EPCIS 1.2 XML Output
We aim to create the following EPCIS 1.2 XML using Rust and some crates.
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 | <?xml version="1.0" encoding="utf-8"?> <epcis:EPCISDocument xmlns:cbvmda="urn:epcglobal:cbv:mda" xmlns:epcis="urn:epcglobal:epcis:xsd:1" xmlns:sbdh="http://www.unece.org/cefact/namespaces/StandardBusinessDocumentHeader" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" creationDate="2016-11-08T02:05:22Z" schemaVersion="1.2"> <EPCISHeader> <sbdh:StandardBusinessDocumentHeader> <sbdh:HeaderVersion>1.0</sbdh:HeaderVersion> <sbdh:Sender> <sbdh:Identifier Authority="GLN">00000000</sbdh:Identifier> </sbdh:Sender> <sbdh:Receiver> <sbdh:Identifier Authority="GLN">11111111</sbdh:Identifier> </sbdh:Receiver> <sbdh:DocumentIdentification> <sbdh:Standard>EPCGlobal</sbdh:Standard> <sbdh:TypeVersion>1.0</sbdh:TypeVersion> <sbdh:InstanceIdentifier>0a59e4fc-3b79-459e-9512-732a89a60ccc</sbdh:InstanceIdentifier> <sbdh:Type>Events</sbdh:Type> <sbdh:CreationDateAndTime>2019-10-19T16:33:49.341Z</sbdh:CreationDateAndTime> </sbdh:DocumentIdentification> </sbdh:StandardBusinessDocumentHeader> </EPCISHeader> <EPCISBody> <EventList> <ObjectEvent> <eventTime>2019-10-19T16:33:49.342Z</eventTime> <eventTimeZoneOffset>+08:00</eventTimeZoneOffset> <epcList> <epc>urn:epc:id:sgtin:0999999.000005.100333338641</epc> </epcList> <action>ADD</action> <bizStep>urn:epcglobal:cbv:bizstep:commissioning</bizStep> <disposition>urn:epcglobal:cbv:disp:active</disposition> <readPoint> <id>urn:epc:id:sgln:0000000.00000.0</id> </readPoint> <bizLocation> <id>urn:epc:id:sgln:0000000.00000.0</id> </bizLocation> <extension> <ilmd> <cbvmda:lotNumber>22222</cbvmda:lotNumber> <cbvmda:itemExpirationDate>2022-03-12</cbvmda:itemExpirationDate> </ilmd> </extension> </ObjectEvent> </EventList> </EPCISBody> </epcis:EPCISDocument> |
Writing out XML using Closure
This post also demonstrates how effective the solution described in A Convenient Way to Write Out Start and End XML Tags using Closure is, especially for large XML data.
Update Rust Cargo.toml With Dependencies
After creating a project in IntelliJ IDEA, we update the cargo.toml as follows.
1 2 3 4 5 6 7 8 9 10 11 12 | [package] name = "RustGenerateEPCIS1_2XML" version = "0.1.0" authors = ["Karl San Gabriel <karl.sangabriel@gmail.com>"] edition = "2018" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] xml-rs = "0.8.3" uuid = { version = "0.8.2", features = ["v4"] } chrono = "0.4.19" |
Create Rust Codes To Write Out EPCIS 1.2 XML File
First, we create the main.rs and import the stuff we need.
1 2 3 4 5 6 7 | use chrono::prelude::*; use uuid::Uuid; use std::fs::File; use std::io::{self, Write}; use xml::writer::{EventWriter, EmitterConfig, XmlEvent, Result}; use std::collections::HashMap; use xml::writer::events::StartElementBuilder; |
Then, create a helper function that converts String to &str. We need this function for some string conversion because some functions from xml-rs expect some parameters of type &str instead of String.
1 2 3 | fn string_to_static_str(s: String) -> &'static str { Box::leak(s.into_boxed_str()) } |
Then, we create our “convenient” function that writes out an XML element as a block. It uses a closure to allow for nested XML element blocks, i.e., a block within a block.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 | fn write_element_block <W: Write, F: Fn(&mut EventWriter<W>)>(element: &str, ns: Option<HashMap<String, String>>, attr: Option<HashMap<String, String>>, w: &mut EventWriter<W>, f: F) -> Result<()> { let mut event_builder: StartElementBuilder = XmlEvent::start_element(element); if ns.is_some() { for (k, v) in ns.unwrap().iter() { event_builder = event_builder.ns(string_to_static_str(k.clone()), string_to_static_str(v.clone())); } } if attr.is_some() { for (k, v) in attr.unwrap().iter() { event_builder = event_builder.attr(string_to_static_str(k.clone()), string_to_static_str(v.clone())); } } let mut event: XmlEvent = event_builder.into(); w.write(event); f(w); event = XmlEvent::end_element().into(); return w.write(event); } |
Then, we create another function that calls the write_element_block to build up that EPCIS 1.2 XML content.
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 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 | fn handle_event<W: Write>(w: &mut EventWriter<W>) -> Result<()> { let mut ns_map:HashMap<String, String> = HashMap::new(); let utc: DateTime<Utc> = Utc::now(); ns_map.insert("creationDate".to_string(), utc.to_rfc3339_opts(SecondsFormat::Millis, true)); ns_map.insert("schemaVersion".to_string(), "1.2".to_string()); let mut attr_map: HashMap<String, String> = HashMap::new(); attr_map.insert("epcis".to_string(), "urn:epcglobal:epcis:xsd:1".to_string()); attr_map.insert("cbvmda".to_string(), "urn:epcglobal:cbv:mda".to_string()); attr_map.insert("sbdh".to_string(), "http://www.unece.org/cefact/namespaces/StandardBusinessDocumentHeader".to_string()); attr_map.insert("xsi".to_string(), "http://www.w3.org/2001/XMLSchema-instance".to_string()); return write_element_block("epcis:EPCISDocument", Some(ns_map), Some(attr_map), w, |w| { write_element_block("EPCISHeader", None, None, w, |w| { write_element_block("sbdh:StandardBusinessDocumentHeader", None, None, w, |w| { write_element_block("sbdh:HeaderVersion", None, None, w, |w| { let mut event: XmlEvent = XmlEvent::Characters("1.0").into(); w.write(event); }); write_element_block("sbdh:Sender", None, None, w, |w| { let mut hash_map = HashMap::new(); hash_map.insert("Authority".to_string(), "GLN".to_string()); write_element_block("sbdh:Identifier", None, Some(hash_map), w, |w| { let mut event: XmlEvent = XmlEvent::Characters("00000000").into(); w.write(event); }); }); write_element_block("sbdh:Receiver", None, None, w, |w| { let mut hash_map = HashMap::new(); hash_map.insert("Authority".to_string(), "GLN".to_string()); write_element_block("sbdh:Identifier", Some(hash_map), None, w, |w| { let mut event: XmlEvent = XmlEvent::Characters("11111111").into(); w.write(event); }); }); write_element_block("sbdh:DocumentIdentification", None, None, w, |w| { write_element_block("sbdh:Standard", None, None, w, |w| { let mut event: XmlEvent = XmlEvent::Characters("EPCGlobal").into(); w.write(event); }); write_element_block("sbdh:TypeVersion", None, None,w, |w| { let mut event: XmlEvent = XmlEvent::Characters("1.0").into(); w.write(event); }); write_element_block("sbdh:InstanceIdentifier", None, None,w, |w| { let mut event: XmlEvent = XmlEvent::Characters( string_to_static_str(Uuid::new_v4().to_hyphenated().to_string()) ).into(); w.write(event); }); write_element_block("sbdh:Type", None, None,w, |w| { let mut event: XmlEvent = XmlEvent::Characters("Events").into(); w.write(event); }); write_element_block("sbdh:CreationDateAndTime", None, None,w, |w| { // E.g., 2016-11-08T02:05:22Z let utc: DateTime<Utc> = Utc::now(); let mut event: XmlEvent = XmlEvent::Characters(string_to_static_str( utc.to_rfc3339_opts(SecondsFormat::Millis, true))).into(); w.write(event); }); }); }); }); write_element_block("EPCISBody", None, None, w, |w| { write_element_block("EventList", None, None,w, |w| { // Normally, we'd loop through a list of object to write out ObjectEvent write_element_block("ObjectEvent", None, None, w, |w| { write_element_block("eventTime", None, None,w, |w| { // This is usually not the current date/time let utc: DateTime<Utc> = Utc::now(); let mut event: XmlEvent = XmlEvent::Characters(string_to_static_str( utc.to_rfc3339_opts(SecondsFormat::Millis, true))).into(); w.write(event); }); write_element_block("eventTimeZoneOffset", None, None,w, |w| { // This is usually not the current date/time's offset let local: DateTime<Local> = Local::now(); let mut event: XmlEvent = XmlEvent::Characters(string_to_static_str(local.offset().to_string())).into(); w.write(event); }); write_element_block("epcList", None, None,w, |w| { // Normally, we'd loop through a list of object to write out epc write_element_block("epc", None, None, w, |w| { let mut event: XmlEvent = XmlEvent::Characters( "urn:epc:id:sgtin:0999999.000005.100333338641").into(); w.write(event); }); }); write_element_block("action", None, None,w, |w| { let mut event: XmlEvent = XmlEvent::Characters("ADD").into(); w.write(event); }); write_element_block("bizStep", None, None, w, |w| { let mut event: XmlEvent = XmlEvent::Characters("urn:epcglobal:cbv:bizstep:commissioning").into(); w.write(event); }); write_element_block("disposition", None, None,w, |w| { let mut event: XmlEvent = XmlEvent::Characters("urn:epcglobal:cbv:disp:active").into(); w.write(event); }); write_element_block("readPoint", None, None,w, |w| { write_element_block("id", None, None, w, |w| { let mut event: XmlEvent = XmlEvent::Characters("urn:epc:id:sgln:0000000.00000.0").into(); w.write(event); }); }); write_element_block("bizLocation", None, None, w, |w| { write_element_block("id", None, None, w, |w| { let mut event: XmlEvent = XmlEvent::Characters("urn:epc:id:sgln:0000000.00000.0").into(); w.write(event); }); }); write_element_block("extension", None, None, w, |w| { write_element_block("ilmd", None, None, w, |w| { write_element_block("cbvmda:lotNumber", None, None,w, |w| { let mut event: XmlEvent = XmlEvent::Characters("22222").into(); w.write(event); }); write_element_block("cbvmda:itemExpirationDate", None, None, w, |w| { let mut event: XmlEvent = XmlEvent::Characters("2022-03-12").into(); w.write(event); }); }); }); }); // Other events include AggregationEvent, TransformationEvent, and TransactionEvent }); }); }); } |
Finally, we code the function main function as follows.
1 2 3 4 5 | fn main() { let mut file = File::create("epcis_1dot2_output.xml").unwrap(); let mut writer = EmitterConfig::new().perform_indent(true).create_writer(&mut file); handle_event(&mut writer); } |
When we run this Rust program, it first creates an XML file. Then, it makes a writer so our functions handle_event can use to write out each XML block building up the target EPCIS 1.2 XML file.
The codes generate the following output on the console.
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 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 | C:/Users/karldev/.cargo/bin/cargo.exe run --color=always --package RustGenerateEPCIS1_2XML --bin RustGenerateEPCIS1_2XML warning: unused import: `self` --> src\main.rs:4:15 | 4 | use std::io::{self, Write}; | ^^^^ | = note: `#[warn(unused_imports)]` on by default warning: variable does not need to be mutable --> src\main.rs:58:25 | 58 | let mut event: XmlEvent = XmlEvent::Characters("1.0").into(); | ----^^^^^ | | | help: remove this `mut` | = note: `#[warn(unused_mut)]` on by default warning: variable does not need to be mutable --> src\main.rs:67:29 | 67 | let mut event: XmlEvent = XmlEvent::Characters("00000000").into(); | ----^^^^^ | | | help: remove this `mut` warning: variable does not need to be mutable --> src\main.rs:78:29 | 78 | let mut event: XmlEvent = XmlEvent::Characters("11111111").into(); | ----^^^^^ | | | help: remove this `mut` warning: variable does not need to be mutable --> src\main.rs:85:29 | 85 | let mut event: XmlEvent = XmlEvent::Characters("EPCGlobal").into(); | ----^^^^^ | | | help: remove this `mut` warning: variable does not need to be mutable --> src\main.rs:90:29 | 90 | let mut event: XmlEvent = XmlEvent::Characters("1.0").into(); | ----^^^^^ | | | help: remove this `mut` warning: variable does not need to be mutable --> src\main.rs:95:29 | 95 | let mut event: XmlEvent = XmlEvent::Characters( | ----^^^^^ | | | help: remove this `mut` warning: variable does not need to be mutable --> src\main.rs:102:29 | 102 | let mut event: XmlEvent = XmlEvent::Characters("Events").into(); | ----^^^^^ | | | help: remove this `mut` warning: variable does not need to be mutable --> src\main.rs:110:29 | 110 | let mut event: XmlEvent = XmlEvent::Characters(string_to_static_str( | ----^^^^^ | | | help: remove this `mut` warning: variable does not need to be mutable --> src\main.rs:125:29 | 125 | let mut event: XmlEvent = XmlEvent::Characters(string_to_static_str( | ----^^^^^ | | | help: remove this `mut` warning: variable does not need to be mutable --> src\main.rs:134:29 | 134 | let mut event: XmlEvent = XmlEvent::Characters(string_to_static_str(local.offset().to_string())).into(); | ----^^^^^ | | | help: remove this `mut` warning: variable does not need to be mutable --> src\main.rs:141:33 | 141 | ... let mut event: XmlEvent = XmlEvent::Characters( | ----^^^^^ | | | help: remove this `mut` warning: variable does not need to be mutable --> src\main.rs:147:29 | 147 | let mut event: XmlEvent = XmlEvent::Characters("ADD").into(); | ----^^^^^ | | | help: remove this `mut` warning: variable does not need to be mutable --> src\main.rs:151:29 | 151 | let mut event: XmlEvent = XmlEvent::Characters("urn:epcglobal:cbv:bizstep:commissioning").into(); | ----^^^^^ | | | help: remove this `mut` warning: variable does not need to be mutable --> src\main.rs:156:29 | 156 | let mut event: XmlEvent = XmlEvent::Characters("urn:epcglobal:cbv:disp:active").into(); | ----^^^^^ | | | help: remove this `mut` warning: variable does not need to be mutable --> src\main.rs:162:33 | 162 | ... let mut event: XmlEvent = XmlEvent::Characters("urn:epc:id:sgln:0000000.00000.0").into(); | ----^^^^^ | | | help: remove this `mut` warning: variable does not need to be mutable --> src\main.rs:169:33 | 169 | ... let mut event: XmlEvent = XmlEvent::Characters("urn:epc:id:sgln:0000000.00000.0").into(); | ----^^^^^ | | | help: remove this `mut` warning: variable does not need to be mutable --> src\main.rs:177:37 | 177 | ... let mut event: XmlEvent = XmlEvent::Characters("22222").into(); | ----^^^^^ | | | help: remove this `mut` warning: variable does not need to be mutable --> src\main.rs:181:37 | 181 | ... let mut event: XmlEvent = XmlEvent::Characters("2022-03-12").into(); | ----^^^^^ | | | help: remove this `mut` warning: crate `RustGenerateEPCIS1_2XML` should have a snake case name | = note: `#[warn(non_snake_case)]` on by default = help: convert the identifier to snake case: `rust_generate_epcis1_2_xml` warning: unused `Result` that must be used --> src\main.rs:32:5 | 32 | w.write(event); | ^^^^^^^^^^^^^^^ | = note: `#[warn(unused_must_use)]` on by default = note: this `Result` may be an `Err` variant, which should be handled warning: unused `Result` that must be used --> src\main.rs:55:9 | 55 | / write_element_block("EPCISHeader", None, None, w, |w| { 56 | | write_element_block("sbdh:StandardBusinessDocumentHeader", None, None, w, |w| { 57 | | write_element_block("sbdh:HeaderVersion", None, None, w, |w| { 58 | | let mut event: XmlEvent = XmlEvent::Characters("1.0").into(); ... | 115 | | }); 116 | | }); | |___________^ | = note: this `Result` may be an `Err` variant, which should be handled warning: unused `Result` that must be used --> src\main.rs:56:13 | 56 | / write_element_block("sbdh:StandardBusinessDocumentHeader", None, None, w, |w| { 57 | | write_element_block("sbdh:HeaderVersion", None, None, w, |w| { 58 | | let mut event: XmlEvent = XmlEvent::Characters("1.0").into(); 59 | | w.write(event); ... | 114 | | }); 115 | | }); | |_______________^ | = note: this `Result` may be an `Err` variant, which should be handled warning: unused `Result` that must be used --> src\main.rs:57:17 | 57 | / write_element_block("sbdh:HeaderVersion", None, None, w, |w| { 58 | | let mut event: XmlEvent = XmlEvent::Characters("1.0").into(); 59 | | w.write(event); 60 | | }); | |___________________^ | = note: this `Result` may be an `Err` variant, which should be handled warning: unused `Result` that must be used --> src\main.rs:59:21 | 59 | w.write(event); | ^^^^^^^^^^^^^^^ | = note: this `Result` may be an `Err` variant, which should be handled warning: unused `Result` that must be used --> src\main.rs:61:17 | 61 | / write_element_block("sbdh:Sender", None, None, w, |w| { 62 | | let mut hash_map = HashMap::new(); 63 | | hash_map.insert("Authority".to_string(), "GLN".to_string()); 64 | | ... | 69 | | }); 70 | | }); | |___________________^ | = note: this `Result` may be an `Err` variant, which should be handled warning: unused `Result` that must be used --> src\main.rs:66:21 | 66 | / write_element_block("sbdh:Identifier", None, Some(hash_map), w, |w| { 67 | | let mut event: XmlEvent = XmlEvent::Characters("00000000").into(); 68 | | w.write(event); 69 | | }); | |_______________________^ | = note: this `Result` may be an `Err` variant, which should be handled warning: unused `Result` that must be used --> src\main.rs:68:25 | 68 | w.write(event); | ^^^^^^^^^^^^^^^ | = note: this `Result` may be an `Err` variant, which should be handled warning: unused `Result` that must be used --> src\main.rs:72:17 | 72 | / write_element_block("sbdh:Receiver", None, None, w, |w| { 73 | | let mut hash_map = HashMap::new(); 74 | | hash_map.insert("Authority".to_string(), "GLN".to_string()); 75 | | ... | 80 | | }); 81 | | }); | |___________________^ | = note: this `Result` may be an `Err` variant, which should be handled warning: unused `Result` that must be used --> src\main.rs:77:21 | 77 | / write_element_block("sbdh:Identifier", Some(hash_map), None, w, |w| { 78 | | let mut event: XmlEvent = XmlEvent::Characters("11111111").into(); 79 | | w.write(event); 80 | | }); | |_______________________^ | = note: this `Result` may be an `Err` variant, which should be handled warning: unused `Result` that must be used --> src\main.rs:79:25 | 79 | w.write(event); | ^^^^^^^^^^^^^^^ | = note: this `Result` may be an `Err` variant, which should be handled warning: unused `Result` that must be used --> src\main.rs:83:17 | 83 | / write_element_block("sbdh:DocumentIdentification", None, None, w, |w| { 84 | | write_element_block("sbdh:Standard", None, None, w, |w| { 85 | | let mut event: XmlEvent = XmlEvent::Characters("EPCGlobal").into(); 86 | | w.write(event); ... | 113 | | }); 114 | | }); | |___________________^ | = note: this `Result` may be an `Err` variant, which should be handled warning: unused `Result` that must be used --> src\main.rs:84:21 | 84 | / write_element_block("sbdh:Standard", None, None, w, |w| { 85 | | let mut event: XmlEvent = XmlEvent::Characters("EPCGlobal").into(); 86 | | w.write(event); 87 | | }); | |_______________________^ | = note: this `Result` may be an `Err` variant, which should be handled warning: unused `Result` that must be used --> src\main.rs:86:25 | 86 | w.write(event); | ^^^^^^^^^^^^^^^ | = note: this `Result` may be an `Err` variant, which should be handled warning: unused `Result` that must be used --> src\main.rs:89:21 | 89 | / write_element_block("sbdh:TypeVersion", None, None,w, |w| { 90 | | let mut event: XmlEvent = XmlEvent::Characters("1.0").into(); 91 | | w.write(event); 92 | | }); | |_______________________^ | = note: this `Result` may be an `Err` variant, which should be handled warning: unused `Result` that must be used --> src\main.rs:91:25 | 91 | w.write(event); | ^^^^^^^^^^^^^^^ | = note: this `Result` may be an `Err` variant, which should be handled warning: unused `Result` that must be used --> src\main.rs:94:21 | 94 | / write_element_block("sbdh:InstanceIdentifier", None, None,w, |w| { 95 | | let mut event: XmlEvent = XmlEvent::Characters( 96 | | string_to_static_str(Uuid::new_v4().to_hyphenated().to_string()) 97 | | ).into(); 98 | | w.write(event); 99 | | }); | |_______________________^ | = note: this `Result` may be an `Err` variant, which should be handled warning: unused `Result` that must be used --> src\main.rs:98:25 | 98 | w.write(event); | ^^^^^^^^^^^^^^^ | = note: this `Result` may be an `Err` variant, which should be handled warning: unused `Result` that must be used --> src\main.rs:101:21 | 101 | / write_element_block("sbdh:Type", None, None,w, |w| { 102 | | let mut event: XmlEvent = XmlEvent::Characters("Events").into(); 103 | | w.write(event); 104 | | }); | |_______________________^ | = note: this `Result` may be an `Err` variant, which should be handled warning: unused `Result` that must be used --> src\main.rs:103:25 | 103 | w.write(event); | ^^^^^^^^^^^^^^^ | = note: this `Result` may be an `Err` variant, which should be handled warning: unused `Result` that must be used --> src\main.rs:106:21 | 106 | / write_element_block("sbdh:CreationDateAndTime", None, None,w, |w| { 107 | | 108 | | // E.g., 2016-11-08T02:05:22Z 109 | | let utc: DateTime<Utc> = Utc::now(); ... | 112 | | w.write(event); 113 | | }); | |_______________________^ | = note: this `Result` may be an `Err` variant, which should be handled warning: unused `Result` that must be used --> src\main.rs:112:25 | 112 | w.write(event); | ^^^^^^^^^^^^^^^ | = note: this `Result` may be an `Err` variant, which should be handled warning: unused `Result` that must be used --> src\main.rs:118:9 | 118 | / write_element_block("EPCISBody", None, None, w, |w| { 119 | | write_element_block("EventList", None, None,w, |w| { 120 | | // Normally, we'd loop through a list of object to write out ObjectEvent 121 | | write_element_block("ObjectEvent", None, None, w, |w| { ... | 189 | | }); 190 | | }); | |___________^ | = note: this `Result` may be an `Err` variant, which should be handled warning: unused `Result` that must be used --> src\main.rs:119:13 | 119 | / write_element_block("EventList", None, None,w, |w| { 120 | | // Normally, we'd loop through a list of object to write out ObjectEvent 121 | | write_element_block("ObjectEvent", None, None, w, |w| { 122 | | write_element_block("eventTime", None, None,w, |w| { ... | 188 | | // Other events include AggregationEvent, TransformationEvent, and TransactionEvent 189 | | }); | |_______________^ | = note: this `Result` may be an `Err` variant, which should be handled warning: unused `Result` that must be used --> src\main.rs:121:17 | 121 | / write_element_block("ObjectEvent", None, None, w, |w| { 122 | | write_element_block("eventTime", None, None,w, |w| { 123 | | // This is usually not the current date/time 124 | | let utc: DateTime<Utc> = Utc::now(); ... | 185 | | }); 186 | | }); | |___________________^ | = note: this `Result` may be an `Err` variant, which should be handled warning: unused `Result` that must be used --> src\main.rs:122:21 | 122 | / write_element_block("eventTime", None, None,w, |w| { 123 | | // This is usually not the current date/time 124 | | let utc: DateTime<Utc> = Utc::now(); 125 | | let mut event: XmlEvent = XmlEvent::Characters(string_to_static_str( 126 | | utc.to_rfc3339_opts(SecondsFormat::Millis, true))).into(); 127 | | w.write(event); 128 | | }); | |_______________________^ | = note: this `Result` may be an `Err` variant, which should be handled warning: unused `Result` that must be used --> src\main.rs:127:25 | 127 | w.write(event); | ^^^^^^^^^^^^^^^ | = note: this `Result` may be an `Err` variant, which should be handled warning: unused `Result` that must be used --> src\main.rs:130:21 | 130 | / write_element_block("eventTimeZoneOffset", None, None,w, |w| { 131 | | 132 | | // This is usually not the current date/time's offset 133 | | let local: DateTime<Local> = Local::now(); 134 | | let mut event: XmlEvent = XmlEvent::Characters(string_to_static_str(local.offset().to_string())).into(); 135 | | w.write(event); 136 | | }); | |_______________________^ | = note: this `Result` may be an `Err` variant, which should be handled warning: unused `Result` that must be used --> src\main.rs:135:25 | 135 | w.write(event); | ^^^^^^^^^^^^^^^ | = note: this `Result` may be an `Err` variant, which should be handled warning: unused `Result` that must be used --> src\main.rs:138:21 | 138 | / write_element_block("epcList", None, None,w, |w| { 139 | | // Normally, we'd loop through a list of object to write out epc 140 | | write_element_block("epc", None, None, w, |w| { 141 | | let mut event: XmlEvent = XmlEvent::Characters( ... | 144 | | }); 145 | | }); | |_______________________^ | = note: this `Result` may be an `Err` variant, which should be handled warning: unused `Result` that must be used --> src\main.rs:140:25 | 140 | / write_element_block("epc", None, None, w, |w| { 141 | | let mut event: XmlEvent = XmlEvent::Characters( 142 | | "urn:epc:id:sgtin:0999999.000005.100333338641").into(); 143 | | w.write(event); 144 | | }); | |___________________________^ | = note: this `Result` may be an `Err` variant, which should be handled warning: unused `Result` that must be used --> src\main.rs:143:29 | 143 | ... w.write(event); | ^^^^^^^^^^^^^^^ | = note: this `Result` may be an `Err` variant, which should be handled warning: unused `Result` that must be used --> src\main.rs:146:21 | 146 | / write_element_block("action", None, None,w, |w| { 147 | | let mut event: XmlEvent = XmlEvent::Characters("ADD").into(); 148 | | w.write(event); 149 | | }); | |_______________________^ | = note: this `Result` may be an `Err` variant, which should be handled warning: unused `Result` that must be used --> src\main.rs:148:25 | 148 | w.write(event); | ^^^^^^^^^^^^^^^ | = note: this `Result` may be an `Err` variant, which should be handled warning: unused `Result` that must be used --> src\main.rs:150:21 | 150 | / write_element_block("bizStep", None, None, w, |w| { 151 | | let mut event: XmlEvent = XmlEvent::Characters("urn:epcglobal:cbv:bizstep:commissioning").into(); 152 | | w.write(event); 153 | | }); | |_______________________^ | = note: this `Result` may be an `Err` variant, which should be handled warning: unused `Result` that must be used --> src\main.rs:152:25 | 152 | w.write(event); | ^^^^^^^^^^^^^^^ | = note: this `Result` may be an `Err` variant, which should be handled warning: unused `Result` that must be used --> src\main.rs:155:21 | 155 | / write_element_block("disposition", None, None,w, |w| { 156 | | let mut event: XmlEvent = XmlEvent::Characters("urn:epcglobal:cbv:disp:active").into(); 157 | | w.write(event); 158 | | }); | |_______________________^ | = note: this `Result` may be an `Err` variant, which should be handled warning: unused `Result` that must be used --> src\main.rs:157:25 | 157 | w.write(event); | ^^^^^^^^^^^^^^^ | = note: this `Result` may be an `Err` variant, which should be handled warning: unused `Result` that must be used --> src\main.rs:160:21 | 160 | / write_element_block("readPoint", None, None,w, |w| { 161 | | write_element_block("id", None, None, w, |w| { 162 | | let mut event: XmlEvent = XmlEvent::Characters("urn:epc:id:sgln:0000000.00000.0").into(); 163 | | w.write(event); 164 | | }); 165 | | }); | |_______________________^ | = note: this `Result` may be an `Err` variant, which should be handled warning: unused `Result` that must be used --> src\main.rs:161:25 | 161 | / write_element_block("id", None, None, w, |w| { 162 | | let mut event: XmlEvent = XmlEvent::Characters("urn:epc:id:sgln:0000000.00000.0").into(); 163 | | w.write(event); 164 | | }); | |___________________________^ | = note: this `Result` may be an `Err` variant, which should be handled warning: unused `Result` that must be used --> src\main.rs:163:29 | 163 | ... w.write(event); | ^^^^^^^^^^^^^^^ | = note: this `Result` may be an `Err` variant, which should be handled warning: unused `Result` that must be used --> src\main.rs:167:21 | 167 | / write_element_block("bizLocation", None, None, w, |w| { 168 | | write_element_block("id", None, None, w, |w| { 169 | | let mut event: XmlEvent = XmlEvent::Characters("urn:epc:id:sgln:0000000.00000.0").into(); 170 | | w.write(event); 171 | | }); 172 | | }); | |_______________________^ | = note: this `Result` may be an `Err` variant, which should be handled warning: unused `Result` that must be used --> src\main.rs:168:25 | 168 | / write_element_block("id", None, None, w, |w| { 169 | | let mut event: XmlEvent = XmlEvent::Characters("urn:epc:id:sgln:0000000.00000.0").into(); 170 | | w.write(event); 171 | | }); | |___________________________^ | = note: this `Result` may be an `Err` variant, which should be handled warning: unused `Result` that must be used --> src\main.rs:170:29 | 170 | ... w.write(event); | ^^^^^^^^^^^^^^^ | = note: this `Result` may be an `Err` variant, which should be handled warning: unused `Result` that must be used --> src\main.rs:174:21 | 174 | / write_element_block("extension", None, None, w, |w| { 175 | | write_element_block("ilmd", None, None, w, |w| { 176 | | write_element_block("cbvmda:lotNumber", None, None,w, |w| { 177 | | let mut event: XmlEvent = XmlEvent::Characters("22222").into(); ... | 184 | | }); 185 | | }); | |_______________________^ | = note: this `Result` may be an `Err` variant, which should be handled warning: unused `Result` that must be used --> src\main.rs:175:25 | 175 | / write_element_block("ilmd", None, None, w, |w| { 176 | | write_element_block("cbvmda:lotNumber", None, None,w, |w| { 177 | | let mut event: XmlEvent = XmlEvent::Characters("22222").into(); 178 | | w.write(event); ... | 183 | | }); 184 | | }); | |___________________________^ | = note: this `Result` may be an `Err` variant, which should be handled warning: unused `Result` that must be used --> src\main.rs:176:29 | 176 | / ... write_element_block("cbvmda:lotNumber", None, None,w, |w| { 177 | | ... let mut event: XmlEvent = XmlEvent::Characters("22222").into(); 178 | | ... w.write(event); 179 | | ... }); | |_________________________^ | = note: this `Result` may be an `Err` variant, which should be handled warning: unused `Result` that must be used --> src\main.rs:178:33 | 178 | ... w.write(event); | ^^^^^^^^^^^^^^^ | = note: this `Result` may be an `Err` variant, which should be handled warning: unused `Result` that must be used --> src\main.rs:180:29 | 180 | / ... write_element_block("cbvmda:itemExpirationDate", None, None, w, |w| { 181 | | ... let mut event: XmlEvent = XmlEvent::Characters("2022-03-12").into(); 182 | | ... w.write(event); 183 | | ... }); | |_________________________^ | = note: this `Result` may be an `Err` variant, which should be handled warning: unused `Result` that must be used --> src\main.rs:182:33 | 182 | ... w.write(event); | ^^^^^^^^^^^^^^^ | = note: this `Result` may be an `Err` variant, which should be handled warning: unused `Result` that must be used --> src\main.rs:197:5 | 197 | handle_event(&mut writer); | ^^^^^^^^^^^^^^^^^^^^^^^^^^ | = note: this `Result` may be an `Err` variant, which should be handled warning: 71 warnings emitted Finished dev [unoptimized + debuginfo] target(s) in 0.24s Running `target\debug\RustGenerateEPCIS1_2XML.exe` Process finished with exit code 0 |