Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

not support complex struct? #16

Closed
importcjj opened this issue Jun 24, 2019 · 0 comments · Fixed by #25
Closed

not support complex struct? #16

importcjj opened this issue Jun 24, 2019 · 0 comments · Fixed by #25

Comments

@importcjj
Copy link

My cargo.toml

[dependencies]
serde = { version = "1.0", features = ["derive"] }
serde_bytes = "0.10.0"
serde_bencode = { path = "serde-bencode" }

Version of rustc

rustc 1.35.0 (3c235d560 2019-05-20)

And my code

use serde::{Deserialize, Serialize};

use serde_bencode::de;
use serde_bencode::ser;

use std::str;

#[derive(Debug, Deserialize, Serialize)]
struct Node(String, i64);

fn main() {

    let nodes: Vec<Node> = vec![
        Node("aaa".to_owned(), 5665),
        Node("bbb".to_owned(), 5665),
        Node("ccc".to_owned(), 5665),
    ];

    let buffer: Vec<u8> = match ser::to_bytes(&nodes) {
        Ok(s) => s,
        Err(e) => panic!(e),
    };

    println!("{}", str::from_utf8(&buffer).unwrap());


    match de::from_bytes::<Vec<Node>>(&buffer) {
        Ok(t) => {
            // println!("{}", t.len());
            println!("{:?}", t);
        }
        Err(e) => println!("ERROR: {:?}", e),
    };
}

And just got

ll3:aaai5665eel3:bbbi5665eel3:ccci5665eee
[Node("aaa", 5665)]

By the way, I am just a rust noob. Maybe I just made some mistake?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant