Closed viperscape closed 9 years ago
I updated rust to newest nightly (0.12->0.13) and reran this, now getting a new error. I'm on Windows..
Compiling msgpack v0.0.1 (https://github.com/mneumann/rust-msgpack.git#cc990f56)
C:\Users\chris\.cargo\git\checkouts\rust-msgpack-437ef857d42dd556\master\src\lib.rs:96:18: 96:20 error: expected `=>`, found `..`
C:\Users\chris\.cargo\git\checkouts\rust-msgpack-437ef857d42dd556\master\src\lib.rs:96 0x00 .. 0x7f => Ok(c as u64),
^~
Could not compile `msgpack`.
@viperscape Make sure you update the library version. If you're using cargo, you can run cargo update
.
okay, reran this cleanly and got same original error:
task '<main>' failed at 'called `Option::unwrap()` on a `None` value', /home/rustbuild/src/rust-buildbot/slave/nightly-linux/build/src/libcore/option.rs:347
An unknown error occurred
@viperscape from_msgpack
doesn't return a Value
object but a T
. unwrap
is also extremely hard to debug things as it fails from within the Option
implementation.
Here's a working example:
extern crate serialize;
extern crate msgpack;
use std::io::IoError;
use std::io::IoResult;
#[deriving(Show, Encodable,Decodable)]
struct MyStruct {
a: Vec<u32>,
s: String
}
fn main() {
let m = MyStruct{ a: vec![1u32, 5], s: "hi".to_string()};
let enc = msgpack::Encoder::to_msgpack(&m).ok().unwrap();
println!("1: {}",&enc); //[130, 146, 1, 5, 162, 104, 105]
match msgpack::from_msgpack::<MyStruct>(enc) {
Ok(s) => println!("success: {}", s),
Err(err) => fail!("Error: {}", err)
}
}
great thanks, now I understand
I'm probably doing this all wrong, but this fails: