Giter VIP home page Giter VIP logo

Comments (2)

esn01 avatar esn01 commented on May 23, 2024

I hope that this time whole text will be visible..

#[macro_use]
extern crate serde_derive;
extern crate serde_xml_rs;
//extern crate serde;

use serde_xml_rs::*;

#[derive(Debug, Deserialize, Serialize) ]
struct Item {
pub name: String,
pub source: String
}

#[derive(Debug, Deserialize, Serialize)]
struct Project {
pub name: String,

#[serde(rename = "Item", default)]
pub items: Vec<Item>

}

fn get_project() -> Project {
let s = r##"




"##;
let project: Project = deserialize(s.as_bytes()).unwrap();
project
}

fn main() {

let p: Project = get_project();
println!("\n\ndeserialized\n{:#?}", p);

let mut buffer = Vec::new();

serialize(&p, &mut buffer);
println!("\nserialized buffer:\n{:?}", buffer);
let serialized = String::from_utf8(buffer).unwrap();
println!("\nserialized:\n{}", serialized);

}

deserialized
Project {
name: "my_project",
items: [
Item {
name: "hello",
source: "world.rs"
},
Item {
name: "goodbye",
source: "world.rs"
}
]
}

serialized buffer:
[60, 80, 114, 111, 106, 101, 99, 116, 62, 60, 110, 97, 109, 101, 62, 109, 121, 95, 112, 114, 111, 106, 101, 99, 116, 60, 47, 110, 97, 109, 101, 62, 60, 73, 116, 101, 109, 62]

serialized:
my_project

from serde-xml-rs.

RReverser avatar RReverser commented on May 23, 2024

Please use ```rust and ``` lines to wrap your code blocks, then it would be much easier to read them.

from serde-xml-rs.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.