rust-lang-deprecated / rustc-serialize Goto Github PK
View Code? Open in Web Editor NEWDeprecated serialization/deserialization for Rust
License: Apache License 2.0
Deprecated serialization/deserialization for Rust
License: Apache License 2.0
Issue by huonw
Tuesday Aug 06, 2013 at 14:08 GMT
For earlier discussion, see rust-lang/rust#8335
This issue was labelled with: A-libs, I-papercut in the Rust repository
If one wants to convert an Encodable
type to a Json
value, then one has to do something like (i.e. encode as JSON to a string and then parse that string):
let foo = something_to_convert_to_json;
let s = do std::io::with_str_writer |w| {
foo.encode(&mut extra::json::Encoder(w));
};
let json = match extra::json::from_str(s) {
Ok(j) => j,
Err(_) => fail!("Rust output some json it doesn't understand itself.")
};
Will this library ever support XML?
The version number should be 0.2.2
Specifically some short fixed-length arrays like [T;1]
through [T;16]
. There are like a dozen tuple implementations, so this wouldn't be much of a stretch.
Currently only old_path::Path is supported
Latest version has a fix for latest rustc. Please update crates.io!
Is there a reason why the Hash trait is not implemented for json::Json?
Would be nice to use a Json instance as key in a HashMap.
Searching for "base64" or "json" on crates.io should pull this up.
Option types as HashMap keys is problematic when used with rustc-serialize. The issue is that if you use None
as a key and try to serialize it, it will serialize to something like "null": /* value */
. Note that this is the string null, and not the keyword null. As a result, when you try to decode it from JSON, you run into this issue: if you have an Option<String>
, it'll decode as Some(null)
instead of None
. If you have a non-String type (e.g. u8), it will fail with an error. This issue is made more complex by the fact that there isn't a clear answer, at least that I can see, within the JSON specification. With the way HashMaps are encoded (as objects per the spec), the only valid key value is a string.
Here is the code where I encountered the issue. Here is an example of a HashMap<Option<String>, HashMap<Option<String>, uint>>
being serialized:
{
"map": {
"I": {
"like":2
},
"null": {
"I":1
},
"dogs": {
"null":1
},
"cats": {
"and":1
},
"like": {
"cats":1,
"dogs":1
},
"and": {
"I":1
}
}
}
All the "null"
keys were originally None
.
Implementing Decoder for a representation that does not know the length of sequences ahead of time requires infinite lookahead, since the length needs to be known before the first element is parsed.
For example: if Json were not parsed to the Json enum as an intermediate, when a sequence is expected, the read_seq
function would need to parse ahead until it finds the corresponding ]
.
Also, all the collection implementations in collection_impls.rs
do not require the length to be known beforehand. They only use it as an optimization to reduce the number of allocations.
rustc 1.0.0-nightly (d754722a0 2015-03-31) (built 2015-04-01)
git clone https://github.com/rust-lang/rustc-serialize.git
cd rustc-serialize
cargo build
cargo build
Compiling rustc-serialize v0.3.12 (file:///home/kostya/projects/rustc-serialize)
<std macros>:6:1: 6:41 error: the trait `core::error::FromError<core::fmt::Error>` is not implemented for the type `json::EncoderError` [E0277]
<std macros>:6 $ crate:: error:: FromError:: from_error ( err ) ) } } )
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
<std macros>:1:1: 6:57 note: in expansion of try!
src/json.rs:436:5: 436:30 note: expansion site
<std macros>:6:1: 6:41 error: the trait `core::error::FromError<core::fmt::Error>` is not implemented for the type `json::EncoderError` [E0277]
<std macros>:6 $ crate:: error:: FromError:: from_error ( err ) ) } } )
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
...
am i doing something wrong?
I would create a PR but I am not sure what the actual correct value is:
Here there is a 'i' in the format string https://github.com/rust-lang/rustc-serialize/blob/master/src/json.rs#L133
Here it says there should be a 'j' https://github.com/rust-lang/rustc-serialize/blob/master/src/json.rs#L153
Getting this error with newest rust
error: invalid character -
in crate name: rustc-serialize
error: aborting due to previous error
Build failed, waiting for other jobs to finish...
Could not compile rustc-serialize
.
I'm working on a project which requires rustc-serialize
as a dependency (for docopt
). The project builds fine on my machine, but a few commits ago, the build on Travis CI started failing due to an error when compiling rustc-serialize
. The build has failed ever since.
I'm pretty new to Rust, so it's entirely possible that I've done something wrong, but I haven't been able to find any changes between the last successful build and the first failed build that would break rustc-serialize
.
Any ideas?
Issue by zokier
Saturday Jan 04, 2014 at 12:23 GMT
For earlier discussion, see rust-lang/rust#11308
This issue was labelled with: in the Rust repository
Demonstration/testcase: https://gist.github.com/zokier/8254831
I'm thinking that in here should be a check for newlines to allow a single trailing newline.
On a related note it might be better to escape the invalid character in the error message, so that in cases of non-printable characters (like newlines) the message would be clearer.
Instead of what we have now:
#[derive(Clone, PartialEq, PartialOrd, Debug)]
pub enum Json {
I64(i64),
U64(u64),
F64(f64),
String(string::String),
Boolean(bool),
Array(self::Array),
Object(self::Object),
Null,
}
do something like:
#[derive(Clone, PartialEq, PartialOrd, Debug)]
pub enum Json<I: SignedInt, U: UnsignedInt, F: Float> {
Int(I),
UInt(U),
Float(F),
String(string::String),
Boolean(bool),
Array(self::Array),
Object(self::Object),
Null,
}
Forgive me if this is a terrible idea. I was thinking about some of my large JSON datasets and it'd be nice to be able to control the precision for each numeric type.
Veeery minor quibble, but putting a "-" in the name makes things uselessly complicated. Is it too late to change the name to, e.g. rustc_serialize ou just rustserialize ?
Why do I get this error?
unresolved import
std::old_path. There is no
old_pathin
std``
Attempting to parse:
{"":"","":{"":"","":[{"":""},-0
Results in:
root@afl-rust:~/afl-staging-area# cargo run < outputs/crashes/new
Running `target/debug/afl-staging-area`
thread '<main>' panicked at 'arithmetic operation overflowed', /root/rustc-serialize/src/json.rs:1488
An unknown error occurred
This bug was found using https://github.com/kmcallister/afl.rs ๐
Hello guys, I was trying to use the toml-rs library to read config files made in toml for my project and it had marked the rustc-serialize crate (is that ok?) as a dependecy. During the build I encountered the following error that I couldn't sort out so if you could give me a hint of what is happening I would be really grateful.
$ cargo build --verbose
Compiling rustc-serialize v0.2.7 (https://github.com/rust-lang/rustc-serialize.git#2ff7f6c1)
Running `rustc /home/vagrant/.cargo/git/checkouts/rustc-serialize-bdc70357aa712c7d/master/src/lib.rs --crate-name rustc-serialize --crate-type lib -g -C metadata=4fe51b58123782a8 -C extra-filename=-4fe51b58123782a8 --out-dir /home/vagrant/infeyes/target/deps --emit=dep-info,link -L dependency=/home/vagrant/infeyes/target/deps -L dependency=/home/vagrant/infeyes/target/deps -Awarnings`
Fresh libey v0.0.1 (file:///home/vagrant/infeyes)
/home/vagrant/.cargo/git/checkouts/rustc-serialize-bdc70357aa712c7d/master/src/json.rs:3422:27: 3422:30 error: illegal suffix `us` for numeric literal
/home/vagrant/.cargo/git/checkouts/rustc-serialize-bdc70357aa712c7d/master/src/json.rs:3422 for i in range(0, 4us) {
^~~
/home/vagrant/.cargo/git/checkouts/rustc-serialize-bdc70357aa712c7d/master/src/json.rs:3803:42: 3803:45 error: illegal suffix `us` for numeric literal
/home/vagrant/.cargo/git/checkouts/rustc-serialize-bdc70357aa712c7d/master/src/json.rs:3803 tree_map.insert("a".to_string(), 1us);
^~~
/home/vagrant/.cargo/git/checkouts/rustc-serialize-bdc70357aa712c7d/master/src/json.rs:3807:42: 3807:45 error: illegal suffix `us` for numeric literal
/home/vagrant/.cargo/git/checkouts/rustc-serialize-bdc70357aa712c7d/master/src/json.rs:3807 hash_map.insert("a".to_string(), 1us);
^~~
error: aborting due to 3 previous errors
Could not compile `rustc-serialize`.
Caused by:
Process didn't exit successfully: `rustc /home/vagrant/.cargo/git/checkouts/rustc-serialize-bdc70357aa712c7d/master/src/lib.rs --crate-name rustc-serialize --crate-type lib -g -C metadata=4fe51b58123782a8 -C extra-filename=-4fe51b58123782a8 --out-dir /home/vagrant/infeyes/target/deps --emit=dep-info,link -L dependency=/home/vagrant/infeyes/target/deps -L dependency=/home/vagrant/infeyes/target/deps -Awarnings` (status=101)
Regards
I am trying to implement a google bigquery tabledata.insertAll
request, which requires me to allow arbitrary json data within the json-encoded data structure. The official docs present it like this:
{
"kind": "bigquery#tableDataInsertAllRequest",
"rows": [
{
"insertId": string,
"json": {
(key): (value)
}
}
]
}
The enclosing structure is implementing the Default
trait (it's a requirement), which fails to auto-implement as json::Json
doesn't implement it for some reason. To my mind, it could be implemented like this:
impl Default for Json {
fn default() -> Json {
Json::Null
}
}
Do you think this can be done, or is there a reason to omit this trait ?
Thank you
Users/aeufemio/.cargo/registry/src/github.com-1ecc6299db9ec823/rustc-serialize-0.3.5/src/base64.rs:107:23: 110:10 error: match arms have incompatible types:
expected `&[u8; 1]`,
found `&'static [u8; 2]`
(expected an array with a fixed size of 1 elements,
found one with 2 elements) [E0308]
/Users/aeufemio/.cargo/registry/src/github.com-1ecc6299db9ec823/rustc-serialize-0.3.5/src/base64.rs:107 let newline = match config.newline {
/Users/aeufemio/.cargo/registry/src/github.com-1ecc6299db9ec823/rustc-serialize-0.3.5/src/base64.rs:108 Newline::LF => b"\n",
/Users/aeufemio/.cargo/registry/src/github.com-1ecc6299db9ec823/rustc-serialize-0.3.5/src/base64.rs:109 Newline::CRLF => b"\r\n"
/Users/aeufemio/.cargo/registry/src/github.com-1ecc6299db9ec823/rustc-serialize-0.3.5/src/base64.rs:110 };
/Users/aeufemio/.cargo/registry/src/github.com-1ecc6299db9ec823/rustc-serialize-0.3.5/src/base64.rs:109:30: 109:37 note: match arm with an incompatible type
/Users/aeufemio/.cargo/registry/src/github.com-1ecc6299db9ec823/rustc-serialize-0.3.5/src/base64.rs:109 Newline::CRLF => b"\r\n"
^~~~~~~
/Users/aeufemio/.cargo/registry/src/github.com-1ecc6299db9ec823/rustc-serialize-0.3.5/src/base64.rs:115:53: 115:55 error: the type of this value must be known in this context
/Users/aeufemio/.cargo/registry/src/github.com-1ecc6299db9ec823/rustc-serialize-0.3.5/src/base64.rs:115 v.extend(newline.iter().map(|x| *x));
^~
/Users/aeufemio/.cargo/registry/src/github.com-1ecc6299db9ec823/rustc-serialize-0.3.5/src/base64.rs:137:53: 137:55 error: the type of this value must be known in this context
/Users/aeufemio/.cargo/registry/src/github.com-1ecc6299db9ec823/rustc-serialize-0.3.5/src/base64.rs:137 v.extend(newline.iter().map(|x| *x));
^~
Hello all,
When trying to encode/decode SocketAddr
I noticed that it was neither encodable or decodable despite implementing both 'ToString' and 'FromStr'.
fn main() {
if let Ok(ref addr) = "127.0.0.1:1234".parse::<std::net::SocketAddr>() {
println!("{:?} == {:?}", addr.to_string(), addr)
}
}
"127.0.0.1:1234" == V4(127.0.0.1:1234)
Here the to_string()
almost gives us an Encodable
type and parse/FromStr
almost gives us a Decodable
type.
Any chance that we can get the following?
impl<T: std::string::ToString> Encodable for T { }
impl<T: std::str::FromStr> Decodable for T { }
Cheers,
DarkFox.
Or should at least give the option to ignore them.
f514d05#diff-53fb26f5f2a7c73aed739f3cf6a2c81aR1672
With this, if there is garbage within a string, you cannot decode the json in question
json::decode()
has the signature: pub fn decode<T: Decodable>(s: &str) -> DecodeResult<T>
, yet panics when fed malformed JSON (when presumably it should return the Err
variant of DecoderResult)
.
To reproduce:
extern crate "rustc-serialize" as rustc_serialize;
use rustc_serialize::json;
#[derive(Debug, RustcDecodable)]
pub enum ChatEvent {
Variant(i32)
}
fn main() {
let serialized = "{\"variant\": \"Variant\", \"fields\": []}";
match json::decode(serialized) {
Ok(event) => {
let event: ChatEvent = event;
println!("Ok {:?}", event);
},
Err(e) => println!("Err {:?}", e)
}
}
When run:
$ RUST_BACKTRACE=1 cargo run--verbose
Fresh rustc-serialize v0.3.0
Fresh codec_test v0.0.1 (file:///home/wilsoniya/Devel/rust/codec_test)
Running `target/codec_test`
thread '<main>' panicked at 'called `Option::unwrap()` on a `None` value', /home/rustbuild/src/rust-buildbot/slave/nightly-dist-rustc-linux/build/src/libcore/option.rs:362
stack backtrace:
1: 0xd7d38ed0 - sys::backtrace::write::h36f27d57607c02a1zfA
2: 0xd7d3c260 - panicking::on_panic::h9138d9a94c738b62F9I
3: 0xd7d32e00 - rt::unwind::begin_unwind_inner::ha129cf244cc26e118PI
4: 0xd7d338d0 - rt::unwind::begin_unwind_fmt::h3eb3af7ad971d12cLOI
5: 0xd7d3c180 - rust_begin_unwind
6: 0xd7d67120 - panicking::panic_fmt::hb0af434144b60e81Y9r
7: 0xd7d67030 - panicking::panic::hbfce9629384270cda8r
8: 0xd7d2f0b0 - option::Option<T>::unwrap::h17985508233427626339
9: 0xd7d2f040 - json::Decoder::pop::h3baa3de0ffceb8e2LFh
10: 0xd7d2f4b0 - json::Decoder...Decoder::read_i32::haa735559d0d3751cP6h
11: 0xd7d07ca0 - serialize::i32.Decodable::decode::h14025026717791657052
12: 0xd7d07c50 - fn(&mut rustc.serialize..json..Decoder) .> core..result..Result<i32, rustc.serialize..json..DecoderError> $u7b$rustc.serialize..serialize..Decodable..decode$u7d$::fn_pointer_shim.2798::h54fb51cf77ad7b78
13: 0xd7d07bf0 - ops::F.FnMut<A>::call_mut::h15546216301823000430
14: 0xd7d07b90 - ops::F.FnOnce<A>::call_once::h6394649898615469647
15: 0xd7d07b30 - json::Decoder...Decoder::read_enum_variant_arg::h16179315386903127666
16: 0xd7d078f0 - ChatEvent...rustc_serialize..Decodable::decode::closure.2790
17: 0xd7cfa990 - json::Decoder...Decoder::read_enum_variant::h14667130271225086222
18: 0xd7cfa8e0 - ChatEvent...rustc_serialize..Decodable::decode::closure.2179
19: 0xd7cfa880 - json::Decoder...Decoder::read_enum::h12831975579321903567
20: 0xd7cfa7e0 - ChatEvent...rustc_serialize..Decodable::decode::h13508651075621685618
21: 0xd7cf64d0 - json::decode::h16234319560854349711
22: 0xd7cf60a0 - main::hdcecd00cb3507a16nca
23: 0xd7d40c40 - rust_try_inner
24: 0xd7d40c30 - rust_try
25: 0xd7d3dd90 - rt::lang_start::h95373964c3e0731fl4I
26: 0xd7cf6370 - main
27: 0xd6f08f50 - __libc_start_main
28: 0xd7cf5d50 - <unknown>
29: 0x0 - <unknown>
Process didn't exit successfully: `target/codec_test` (status=101)
which appears to be due to Decoder::pop()
calling unwrap()
on a value pop'd from a Vec
: http://doc.rust-lang.org/src/serialize/json.rs.html#2092 i.e.:
impl Decoder {
fn pop(&mut self) -> Json {
self.stack.pop().unwrap()
}
}
Issue by seanmonstar
Saturday Nov 01, 2014 at 23:36 GMT
For earlier discussion, see rust-lang/rust#18520
This issue was labelled with: A-libs in the Rust repository
I have a string that when written to a writer, needs to be converted to base64. Currently I have to allocate a new string that is encoded, before passing it to fmt.
I'd imagine some like struct Base64Fmt<'a> { s: &'a str, c: Config}
.
Let's say I have a bare-bones plugin
#![crate_name="json_macros"]
#![feature(plugin_registrar, quote)]
#![allow(unstable)]
extern crate rustc;
extern crate syntax;
//extern crate "rustc-serialize" as rustc_serialize;
use syntax::ast::TokenTree;
use syntax::codemap::Span;
use syntax::ext::base::{ExtCtxt, MacResult, DummyResult};
use rustc::plugin::Registry;
#[plugin_registrar]
pub fn plugin_registrar(reg: &mut Registry) {
reg.register_macro("json", expand);
}
fn expand<'cx>(_: &'cx mut ExtCtxt, sp: Span,
_: &[TokenTree]) -> Box<MacResult + 'cx> {
return DummyResult::expr(sp);
}
used in my program. If I add an extern crate "rustc-serialize" as rustc_serialize;
line to it I get a linking problem:
root@boot2docker(Docker):/tmp/test-case$ cargo build
Compiling json_macros v0.1.2 (file:///tmp/test-case)
Compiling err v0.0.1 (file:///tmp/test-case)
error: linking with `cc` failed: exit code: 1
note: cc '-Wl,--as-needed' '-m64' '-L' '/usr/local/lib/rustlib/x86_64-unknown-linux-gnu/lib' '-o' '/tmp/test-case/target/test' '/tmp/test-case/target/test.o' '-Wl,--whole-archive' '-lmorestack' '-Wl,--no-whole-archive' '-Wl,--gc-sections' '-pie' '-nodefaultlibs' '-L' '/tmp/test-case/target/deps' '-ljson_macros-4df5f724b343b7dd' '-L' '/usr/local/lib/rustlib/x86_64-unknown-linux-gnu/lib' '-lrustc-4e7c5e5c' '-L' '/usr/local/lib/rustlib/x86_64-unknown-linux-gnu/lib' '-lrustc_back-4e7c5e5c' '-L' '/usr/local/lib/rustlib/x86_64-unknown-linux-gnu/lib' '-lsyntax-4e7c5e5c' '-L' '/usr/local/lib/rustlib/x86_64-unknown-linux-gnu/lib' '-lfmt_macros-4e7c5e5c' '-L' '/usr/local/lib/rustlib/x86_64-unknown-linux-gnu/lib' '-lgraphviz-4e7c5e5c' '-L' '/usr/local/lib/rustlib/x86_64-unknown-linux-gnu/lib' '-lflate-4e7c5e5c' '-L' '/usr/local/lib/rustlib/x86_64-unknown-linux-gnu/lib' '-larena-4e7c5e5c' '-L' '/usr/local/lib/rustlib/x86_64-unknown-linux-gnu/lib' '-lgetopts-4e7c5e5c' '-L' '/usr/local/lib/rustlib/x86_64-unknown-linux-gnu/lib' '-lterm-4e7c5e5c' '-L' '/usr/local/lib/rustlib/x86_64-unknown-linux-gnu/lib' '-lrbml-4e7c5e5c' '-L' '/usr/local/lib/rustlib/x86_64-unknown-linux-gnu/lib' '-lserialize-4e7c5e5c' '-L' '/usr/local/lib/rustlib/x86_64-unknown-linux-gnu/lib' '-llog-4e7c5e5c' '-L' '/usr/local/lib/rustlib/x86_64-unknown-linux-gnu/lib' '-lregex-4e7c5e5c' '-L' '/usr/local/lib/rustlib/x86_64-unknown-linux-gnu/lib' '-lrustc_llvm-4e7c5e5c' '-L' '/usr/local/lib/rustlib/x86_64-unknown-linux-gnu/lib' '-lstd-4e7c5e5c' '-L' '/tmp/test-case/target' '-L' '/tmp/test-case/target/deps' '-L' '/usr/local/lib/rustlib/x86_64-unknown-linux-gnu/lib' '-L' '/tmp/test-case/.rust/lib/x86_64-unknown-linux-gnu' '-L' '/tmp/test-case/lib/x86_64-unknown-linux-gnu' '-Wl,--whole-archive' '-Wl,-Bstatic' '-Wl,--no-whole-archive' '-Wl,-Bdynamic' '-lpthread' '-lrt' '-ldl' '-lm' '-ldl' '-lpthread' '-lrt' '-lgcc_s' '-lpthread' '-lc' '-lm' '-lcompiler-rt'
note: /tmp/test-case/target/test.o: In function `test::main':
/tmp/test-case/test.rs:10: undefined reference to `json::Json::from_str::h04331c517e0d1e39hLg'
/tmp/test-case/target/test.o: In function `result::Result$LT$T$C$$u{20}E$GT$::unwrap::h14896951616154145496':
test.0.rs:(.text._ZN6result25Result$LT$T$C$$u{20}E$GT$6unwrap21h14896951616154145496E+0x1e4): undefined reference to `json::ParserError...std..fmt..Show::fmt::hd963556d3347d834qTe'
collect2: error: ld returned 1 exit status
error: aborting due to previous error
Could not compile `err`.
To learn more, run the command again with --verbose.
Not sure if it's a Rust issue or a package issue?
Rust version is rustc 1.0.0-nightly (f4f10dba2 2015-01-17 20:31:08 +0000)
.
Here's a test case https://gist.github.com/ArtemGr/96f45adaf2e16f3e16d4 which can be easily converted to a fully local one by replacing version = "*"
with path = "json_macros"
in Cargo.toml
.
I have a json string (used for Apple Push Notification Service : https://github.com/rohitjoshi/apns ) whose value can be either a string or other json object. e.g { "alert" : "Hello world!!" }
or { "alert" : {"body": "Hello, world!", "action-loc-key": "Open"} }
To define this I am using enum as
enum AlertPayloadType {
AlertString(String),
AlertDictionary(BTreeMap)
}
Now, to parse the json string , I have implemented ToJson/Decoder traits in which I need to read raw string to determine whether value is string or dictionary and convert into appropriate object but there is no function available in Decoder trait to retrieve Json object.
I tried to use read_str() function which works fine for String data type but due to expect!(self.pop(), String)
validation, it return error rather than converting Json object into string.
Is it possible to modify read_str() as below
fn read_str(&mut self) -> DecodeResult<string::String> {
//expect!(self.pop(), String)
match self.pop() {
Json::Null => Ok("".to_string()),
value => Ok(format!("{}", value)),
}
}
For more details on what I am trying to do, see
https://github.com/rohitjoshi/apns/blob/master/src/message.rs#L98 which invokes ApnsMessage::to_alert_payload_type()
at https://github.com/rohitjoshi/apns/blob/master/src/message.rs#L127
Hi,
I'm trying to deser a json blob with a ref
field. And guess what, ref
is a reserved word. Is there any way to overcome this "limitation" or do I have to write down my decodable implementation for this struct ?
Thank you very much!
It seems that #19741 is breaking this code, for instance std::str::ScalarValue
doesn't exist anymore:
rustc-serialize-0.1.3/src/json.rs:205:25: 205:36 error: unresolved import `std::str::ScalarValue`. There is no `ScalarValue` in `std::str`
/Users/seb/.cargo/registry/src/github.com-1ecc6299db9ec823/rustc-serialize-0.1.3/src/json.rs:205 use std::str::{FromStr, ScalarValue};
^~~~~~~~~~~
error: aborting due to previous error
Could not compile `rustc-serialize`.
Downloading rustc-serialize v0.3.8
Unable to get packages from source
Caused by:
Failed to unpack package `rustc-serialize v0.3.8`
Caused by:
corrupt deflate stream
This should work basically the same as with Vec<u8>
.
Right now, an Object
is pub type Object = BTreeMap<string::String, Json>;
According to the Rust docs:
Use a HashMap when:
You want to associate arbitrary keys with an arbitrary value.
You want a cache.
You want a map, with no extra functionality.
Use a BTreeMap when:
You're interested in what the smallest or largest key-value pair is.
You want to find the largest or smallest key that is smaller or larger than something
You want to be able to get all of the entries in order on-demand.
You want a sorted map.
Based off of those distinctions, why should Object
be a BTreeMap
? From what I understand, we don't need it sorted.
Due to cfe392f
After an update to the latest nightly I have compilation issues
rustc --version
rustc 1.0.0-nightly (ea6f65c5f 2015-01-06 19:47:08 +0000)
cargo build
Compiling rustc-serialize v0.2.5
/Users/craig.hills/.cargo/registry/src/github.com-1ecc6299db9ec823/rustc-serialize-0.2.5/src/serialize.rs:193:25: 193:30 error: obsolete syntax: for Sized?
/Users/craig.hills/.cargo/registry/src/github.com-1ecc6299db9ec823/rustc-serialize-0.2.5/src/serialize.rs:193 pub trait Encodable for Sized? {
^~~~~
note: no longer required. Traits (and their Self
type) do not have the Sized
bound by default
/Users/craig.hills/.cargo/registry/src/github.com-1ecc6299db9ec823/rustc-serialize-0.2.5/src/serialize.rs:399:17: 399:18 error: obsolete syntax: Sized? T
syntax for removing the Sized
bound
/Users/craig.hills/.cargo/registry/src/github.com-1ecc6299db9ec823/rustc-serialize-0.2.5/src/serialize.rs:399 impl<'a, Sized? T: Encodable> Encodable for &'a T {
^
note: write T: ?Sized
instead
/Users/craig.hills/.cargo/registry/src/github.com-1ecc6299db9ec823/rustc-serialize-0.2.5/src/serialize.rs:405:13: 405:14 error: obsolete syntax: Sized? T
syntax for removing the Sized
bound
/Users/craig.hills/.cargo/registry/src/github.com-1ecc6299db9ec823/rustc-serialize-0.2.5/src/serialize.rs:405 impl<Sized? T: Encodable> Encodable for Box {
^
/Users/craig.hills/.cargo/registry/src/github.com-1ecc6299db9ec823/rustc-serialize-0.2.5/src/base64.rs:73:24: 73:29 error: obsolete syntax: for Sized?
/Users/craig.hills/.cargo/registry/src/github.com-1ecc6299db9ec823/rustc-serialize-0.2.5/src/base64.rs:73 pub trait ToBase64 for Sized? {
^~~~~
note: no longer required. Traits (and their Self
type) do not have the Sized
bound by default
/Users/craig.hills/.cargo/registry/src/github.com-1ecc6299db9ec823/rustc-serialize-0.2.5/src/base64.rs:173:26: 173:31 error: obsolete syntax: for Sized?
/Users/craig.hills/.cargo/registry/src/github.com-1ecc6299db9ec823/rustc-serialize-0.2.5/src/base64.rs:173 pub trait FromBase64 for Sized? {
^~~~~
/Users/craig.hills/.cargo/registry/src/github.com-1ecc6299db9ec823/rustc-serialize-0.2.5/src/hex.rs:21:21: 21:26 error: obsolete syntax: for Sized?
/Users/craig.hills/.cargo/registry/src/github.com-1ecc6299db9ec823/rustc-serialize-0.2.5/src/hex.rs:21 pub trait ToHex for Sized? {
^~~~~
note: no longer required. Traits (and their Self
type) do not have the Sized
bound by default
/Users/craig.hills/.cargo/registry/src/github.com-1ecc6299db9ec823/rustc-serialize-0.2.5/src/hex.rs:57:23: 57:28 error: obsolete syntax: for Sized?
/Users/craig.hills/.cargo/registry/src/github.com-1ecc6299db9ec823/rustc-serialize-0.2.5/src/hex.rs:57 pub trait FromHex for Sized? {
^~~~~
/Users/craig.hills/.cargo/registry/src/github.com-1ecc6299db9ec823/rustc-serialize-0.2.5/src/json.rs:2305:22: 2305:27 error: obsolete syntax: for Sized?
/Users/craig.hills/.cargo/registry/src/github.com-1ecc6299db9ec823/rustc-serialize-0.2.5/src/json.rs:2305 pub trait ToJson for Sized? {
^~~~~
note: no longer required. Traits (and their Self
type) do not have the Sized
bound by default
error: aborting due to 8 previous errors
Could not compile rustc-serialize
.
The Decoder
trait includes
fn error(&mut self, err: &str) -> Self::Error;
but the Encoder
trait doesn't have an equivalent method. AFAICT, inside an implementation of Encodable
like this:
impl Encodable for Foo {
fn encode<S: Encoder>(&self, s: &mut S) -> Result<(), S::Error> {
/* ... */
}
}
it's impossible to create an S::Error
(other than by one of the s.emit_xyz
methods failing).
When importing rustc-serialize inside a module, [derive(RustcDecodable, RustcEncodable)]
fails.
The code inside the module file:
extern crate "rustc-serialize" as rustc_serialize;
use self::rustc_serialize::json::{self, ToJson, Json, DecoderError};
#[derive(RustcDecodable, RustcEncodable)]
struct Test {
test: String
}
fn test(s: String) -> Test {
Test {test: s}
}
When compiling I get the following errors:
$ cargo build
Compiling serialize_issue v0.0.1 (file://rust-playground/serialize_issue)
src/mod1/mod.rs:4:26: 4:41 error: failed to resolve. Did you mean `self::rustc_serialize`?
src/mod1/mod.rs:4 #[derive(RustcDecodable, RustcEncodable)]
^~~~~~~~~~~~~~~
note: in expansion of #[derive]
src/mod1/mod.rs:4:1: 4:42 note: expansion site
src/mod1/mod.rs:4:26: 4:40 error: attempt to implement a nonexistent trait `rustc_serialize::Encodable`
src/mod1/mod.rs:4 #[derive(RustcDecodable, RustcEncodable)]
^~~~~~~~~~~~~~
note: in expansion of #[derive]
src/mod1/mod.rs:4:1: 4:42 note: expansion site
src/mod1/mod.rs:4:26: 4:41 error: failed to resolve. Did you mean `self::rustc_serialize`?
src/mod1/mod.rs:4 #[derive(RustcDecodable, RustcEncodable)]
^~~~~~~~~~~~~~~
note: in expansion of #[derive]
src/mod1/mod.rs:4:1: 4:42 note: expansion site
src/mod1/mod.rs:4:26: 4:40 error: attempt to bound type parameter with a nonexistent trait `rustc_serialize::Encoder`
src/mod1/mod.rs:4 #[derive(RustcDecodable, RustcEncodable)]
^~~~~~~~~~~~~~
note: in expansion of #[derive]
src/mod1/mod.rs:4:1: 4:42 note: expansion site
src/mod1/mod.rs:4:10: 4:25 error: failed to resolve. Did you mean `self::rustc_serialize`?
src/mod1/mod.rs:4 #[derive(RustcDecodable, RustcEncodable)]
^~~~~~~~~~~~~~~
note: in expansion of #[derive]
src/mod1/mod.rs:4:1: 4:42 note: expansion site
src/mod1/mod.rs:4:10: 4:24 error: attempt to implement a nonexistent trait `rustc_serialize::Decodable`
src/mod1/mod.rs:4 #[derive(RustcDecodable, RustcEncodable)]
^~~~~~~~~~~~~~
note: in expansion of #[derive]
src/mod1/mod.rs:4:1: 4:42 note: expansion site
src/mod1/mod.rs:4:10: 4:25 error: failed to resolve. Did you mean `self::rustc_serialize`?
src/mod1/mod.rs:4 #[derive(RustcDecodable, RustcEncodable)]
^~~~~~~~~~~~~~~
note: in expansion of #[derive]
src/mod1/mod.rs:4:1: 4:42 note: expansion site
src/mod1/mod.rs:4:10: 4:24 error: attempt to bound type parameter with a nonexistent trait `rustc_serialize::Decoder`
src/mod1/mod.rs:4 #[derive(RustcDecodable, RustcEncodable)]
^~~~~~~~~~~~~~
note: in expansion of #[derive]
src/mod1/mod.rs:4:1: 4:42 note: expansion site
src/mod1/mod.rs:4:10: 4:25 error: failed to resolve. Did you mean `self::rustc_serialize::Decodable`?
src/mod1/mod.rs:4 #[derive(RustcDecodable, RustcEncodable)]
^~~~~~~~~~~~~~~
note: in expansion of #[derive]
src/mod1/mod.rs:4:1: 4:42 note: expansion site
src/mod1/mod.rs:4:10: 4:24 error: unresolved name `rustc_serialize::Decodable::decode`
src/mod1/mod.rs:4 #[derive(RustcDecodable, RustcEncodable)]
^~~~~~~~~~~~~~
note: in expansion of #[derive]
src/mod1/mod.rs:4:1: 4:42 note: expansion site
error: aborting due to 10 previous errors
Could not compile `serialize_issue`.
The issue can be workaround by moving the imports to the lib.rs
file.
$ cat src/mod1/mod.rs
use super::rustc_serialize::json::{self, ToJson, Json, DecoderError};
#[derive(RustcDecodable, RustcEncodable)]
struct Test {
test: String
}
fn test(s: String) -> Test {
Test {test: s}
}
$ cat src/lib.rs
extern crate "rustc-serialize" as rustc_serialize;
mod mod1;
Issue by huonw
Tuesday Jul 01, 2014 at 23:58 GMT
For earlier discussion, see rust-lang/rust#15317
This issue was labelled with: A-libs in the Rust repository
The Encodable
/Decodable
interface is designed to avoid having to allocate everything to intermediate buffers, but json
is encouraging going via String
. serialize::json
has the top level encode
function returning a String
, and all the examples use encode
directly, there's no demonstration of the good direct-to-Writer
API.
That is, something like
println!("{}", json::encode(&x))
can be written a little like
encodable.encode(&mut json::Encoder::new(&mut io::stdout()))
If that is deemed too ugly, I think we should work on fixing the ergonomics of the good version, rather than just leaping straight to the -> String
ones (e.g. json::encode(&mut io::stdout(), &x)
would be nice, and work with json::encode(&mut some_file, &x)
, json::encode(&mut some_tcp_stream, &x)
, etc.).
cc @aturon
What is the relationship between serialize::json and rustc-serialize::json?
The doc pages look very similar to me...
http://doc.rust-lang.org/serialize/json/
http://doc.rust-lang.org/rustc-serialize/rustc-serialize/json/index.html
It would be nice, in JSON ser/deser to map an optional key in a json objet to an Option<_> field in a struct. "None" would map from/to the absence of the key/value pair in the json object.
As far as I can tell, the current implementation makes it non-trivial as values are serialized separately from their key.
Yaml is a very popular and I am sure a lot of rustacean will use it. There is already one library implementing it, but, even though it is probably very efficient, it is a c wrapper and it would be great to have one library taking care of the serialization for all the most popular languages.
Since json is a subset of yaml, there could even be an interface for both, making it easy to translate from one to another. Xml could be added as I explained in another issue.
let data1 = xml::from_string(xml_string); // return a Node structure
let data2 = yaml::from_string(yaml_string); // also return a Node structure
let data3 = json.from_string(json_string); // also return a Node structure
Tell me if you are interested in implementing that feature, that's a topic I am eager to work on.
...
Object: equivalent to rust's Treemap<String, json::Json>
...
Is this a typo or a change related to consistent renaming of the std collections in a near future?
The Encodable and Decodable implementations for the types BTreeSet and BTreeMap go like this:
impl<T: Encodable + PartialEq + Ord> Encodable for BTreeSet<T>
impl<T: Decodable + PartialEq + Ord> Decodable for BTreeSet<T>
impl<K: Encodable + PartialEq + Ord, V: Encodable + PartialEq> Encodable for BTreeMap<T>
impl<K: Decodable + PartialEq + Ord, V: Decodable + PartialEq> Decodable for BTreeMap<K, V>
What's the reasoning behind requiring PartialEq in these impls? I found out that PartialEq is rather unnecessary and the code compiles just fine without it:
impl<T: Encodable + Ord> Encodable for BTreeSet<T>
impl<T: Decodable + Ord> Decodable for BTreeSet<T>
impl<K: Encodable + Ord, V: Encodable> Encodable for BTreeMap<T>
impl<K: Decodable + Ord, V: Decodable> Decodable for BTreeMap<K, V>
Issue by yaitskov
Thursday Sep 18, 2014 at 20:14 GMT
For earlier discussion, see rust-lang/rust#17377
This issue was labelled with: in the Rust repository
Now it's impossible to implement Decodable for a map with different value types
because read_* methods lose the stack head anyway.
Decodable doesn't have a method returning the stack head as-is without any type casting.
Let's look a case where Json dictionary has values with int and String types.
extern crate serialize;
use serialize::{Decodable, Decoder};
use serialize::json::{Json, Boolean, String, Null, I64, U64, F64};
use serialize::json;
#[deriving(Show)]
struct Primitive(Json);
impl<S: Decoder<E>, E> Decodable<S, E> for Primitive {
fn decode(decoder: &mut S) -> Result<Primitive, E> {
match decoder.pop() {
n @ I64(_) => Primitive(n),
n @ U64(_) => Primitive(n),
n @ F64(_) => Primitive(n),
s @ String(_) => Primitive(s),
bad => fail!("bad {}", bad)
}
}
}
There needs to be a way to rename struct fields for use with #[derive(RustcDecodable, RustcEncodable)]
.
For example:
#[derive(RustcDecodable, RustcEncodable)]
struct Thing {
#[serialize(decode_name="type", encode_name="type")]
type_ : String
}
Since JSON and MessagePack both encode type information (array, map, int, float, string, bool and nil) having API that step by step expects some particular type of data is very inflexible and quite useless in real life scenarios.
The power of this two formats compared to formats that needs external schema definition to work is that they offer extended flexibility and backward compatibility by providing type information within the actual data.
This in turn allows one to map JSON or MessagePack messages onto structures even when the fields are in different order, there are extra fields or even use different data types (like int for float) where you can simply handle them by casting or actually expect them and use enums to store them in your structure.
With current API the message is expected to exactly follow you decoding code and any variation like different key order, extra keys or different type will cause error that you cannot act upon even when it should be possible to extract all the information from the message that you may need.
There is no way to branch (match) based on actual message content.
Now while this style of API is correct for Encoder - you want to dictate exactly what data types and in what order you want to encode in it, decoding needs to be way more flexible then it is now taking that you may not control the source of the messages and some variation in formats like JSON or MessagPack is to be expected and it should be possible to handle thous variations even automatically.
While following the Nickel demo, I received some errors while compiling. You'll notice there's two of them, I believe one of the errors was coming from this project:
nickel-demo $ cargo build --verbose
Fresh groupable v0.1.0 (https://github.com/nickel-org/groupable-rs#efc8d769)
Fresh phantom v0.0.3
Compiling rust-mustache v0.3.0 (https://github.com/nickel-org/rust-mustache.git#fd5d0e1c)
Running `rustc /Users/benmorgan/.cargo/git/checkouts/rust-mustache-b850d4795ca6321d/master/src/lib.rs --crate-name mustache --crate-type lib -g -C metadata=48f7150e9c575dbb -C extra-filename=-48f7150e9c575dbb --out-dir /Users/benmorgan/Sites/sandbox/rust/nickel-demo/target/deps --emit=dep-info,link -L dependency=/Users/benmorgan/Sites/sandbox/rust/nickel-demo/target/deps -L dependency=/Users/benmorgan/Sites/sandbox/rust/nickel-demo/target/deps -Awarnings`
Compiling rustc-serialize v0.2.9
Running `rustc /Users/benmorgan/.cargo/registry/src/github.com-1ecc6299db9ec823/rustc-serialize-0.2.9/src/lib.rs --crate-name rustc-serialize --crate-type lib -g -C metadata=8214bc2e838e96ca -C extra-filename=-8214bc2e838e96ca --out-dir /Users/benmorgan/Sites/sandbox/rust/nickel-demo/target/deps --emit=dep-info,link -L dependency=/Users/benmorgan/Sites/sandbox/rust/nickel-demo/target/deps -L dependency=/Users/benmorgan/Sites/sandbox/rust/nickel-demo/target/deps -Awarnings`
Compiling pkg-config v0.1.6
Running `rustc /Users/benmorgan/.cargo/registry/src/github.com-1ecc6299db9ec823/pkg-config-0.1.6/src/lib.rs --crate-name pkg-config --crate-type lib -g -C metadata=582ce12f7a395fbc -C extra-filename=-582ce12f7a395fbc --out-dir /Users/benmorgan/Sites/sandbox/rust/nickel-demo/target/deps --emit=dep-info,link -L dependency=/Users/benmorgan/Sites/sandbox/rust/nickel-demo/target/deps -L dependency=/Users/benmorgan/Sites/sandbox/rust/nickel-demo/target/deps -Awarnings`
Compiling gcc v0.1.6
Running `rustc /Users/benmorgan/.cargo/registry/src/github.com-1ecc6299db9ec823/gcc-0.1.6/src/lib.rs --crate-name gcc --crate-type lib -g -C metadata=46e0c3c1c2bb4e55 -C extra-filename=-46e0c3c1c2bb4e55 --out-dir /Users/benmorgan/Sites/sandbox/rust/nickel-demo/target/deps --emit=dep-info,link -L dependency=/Users/benmorgan/Sites/sandbox/rust/nickel-demo/target/deps -L dependency=/Users/benmorgan/Sites/sandbox/rust/nickel-demo/target/deps -Awarnings`
/Users/benmorgan/.cargo/registry/src/github.com-1ecc6299db9ec823/rustc-serialize-0.2.9/src/base64.rs:189:6: 189:16 error: attempt to implement a nonexistent trait `fmt::Debug`
/Users/benmorgan/.cargo/registry/src/github.com-1ecc6299db9ec823/rustc-serialize-0.2.9/src/base64.rs:189 impl fmt::Debug for FromBase64Error {
^~~~~~~~~~
/Users/benmorgan/.cargo/registry/src/github.com-1ecc6299db9ec823/rustc-serialize-0.2.9/src/base64.rs:208:6: 208:18 error: attempt to implement a nonexistent trait `fmt::Display`
/Users/benmorgan/.cargo/registry/src/github.com-1ecc6299db9ec823/rustc-serialize-0.2.9/src/base64.rs:208 impl fmt::Display for FromBase64Error {
^~~~~~~~~~~~
/Users/benmorgan/.cargo/registry/src/github.com-1ecc6299db9ec823/rustc-serialize-0.2.9/src/base64.rs:210:9: 210:24 error: failed to resolve. Could not find `Debug` in `std::fmt`
/Users/benmorgan/.cargo/registry/src/github.com-1ecc6299db9ec823/rustc-serialize-0.2.9/src/base64.rs:210 fmt::Debug::fmt(&self, f)
^~~~~~~~~~~~~~~
/Users/benmorgan/.cargo/registry/src/github.com-1ecc6299db9ec823/rustc-serialize-0.2.9/src/base64.rs:210:9: 210:24 error: unresolved name `fmt::Debug::fmt`
/Users/benmorgan/.cargo/registry/src/github.com-1ecc6299db9ec823/rustc-serialize-0.2.9/src/base64.rs:210 fmt::Debug::fmt(&self, f)
^~~~~~~~~~~~~~~
/Users/benmorgan/.cargo/registry/src/github.com-1ecc6299db9ec823/rustc-serialize-0.2.9/src/hex.rs:73:6: 73:16 error: attempt to implement a nonexistent trait `fmt::Debug`
/Users/benmorgan/.cargo/registry/src/github.com-1ecc6299db9ec823/rustc-serialize-0.2.9/src/hex.rs:73 impl fmt::Debug for FromHexError {
^~~~~~~~~~
/Users/benmorgan/.cargo/registry/src/github.com-1ecc6299db9ec823/rustc-serialize-0.2.9/src/hex.rs:92:6: 92:18 error: attempt to implement a nonexistent trait `fmt::Display`
/Users/benmorgan/.cargo/registry/src/github.com-1ecc6299db9ec823/rustc-serialize-0.2.9/src/hex.rs:92 impl fmt::Display for FromHexError {
^~~~~~~~~~~~
/Users/benmorgan/.cargo/registry/src/github.com-1ecc6299db9ec823/rustc-serialize-0.2.9/src/hex.rs:94:9: 94:24 error: failed to resolve. Could not find `Debug` in `std::fmt`
/Users/benmorgan/.cargo/registry/src/github.com-1ecc6299db9ec823/rustc-serialize-0.2.9/src/hex.rs:94 fmt::Debug::fmt(&self, f)
^~~~~~~~~~~~~~~
/Users/benmorgan/.cargo/registry/src/github.com-1ecc6299db9ec823/rustc-serialize-0.2.9/src/hex.rs:94:9: 94:24 error: unresolved name `fmt::Debug::fmt`
/Users/benmorgan/.cargo/registry/src/github.com-1ecc6299db9ec823/rustc-serialize-0.2.9/src/hex.rs:94 fmt::Debug::fmt(&self, f)
^~~~~~~~~~~~~~~
/Users/benmorgan/.cargo/registry/src/github.com-1ecc6299db9ec823/rustc-serialize-0.2.9/src/json.rs:336:6: 336:16 error: attempt to implement a nonexistent trait `fmt::Debug`
/Users/benmorgan/.cargo/registry/src/github.com-1ecc6299db9ec823/rustc-serialize-0.2.9/src/json.rs:336 impl fmt::Debug for ErrorCode {
^~~~~~~~~~
/Users/benmorgan/.cargo/registry/src/github.com-1ecc6299db9ec823/rustc-serialize-0.2.9/src/json.rs:356:6: 356:18 error: attempt to implement a nonexistent trait `fmt::Display`
/Users/benmorgan/.cargo/registry/src/github.com-1ecc6299db9ec823/rustc-serialize-0.2.9/src/json.rs:356 impl fmt::Display for DecoderError {
^~~~~~~~~~~~
/Users/benmorgan/.cargo/registry/src/github.com-1ecc6299db9ec823/rustc-serialize-0.2.9/src/json.rs:358:9: 358:24 error: failed to resolve. Could not find `Debug` in `std::fmt`
/Users/benmorgan/.cargo/registry/src/github.com-1ecc6299db9ec823/rustc-serialize-0.2.9/src/json.rs:358 fmt::Debug::fmt(&self, f)
^~~~~~~~~~~~~~~
/Users/benmorgan/.cargo/registry/src/github.com-1ecc6299db9ec823/rustc-serialize-0.2.9/src/json.rs:358:9: 358:24 error: unresolved name `fmt::Debug::fmt`
/Users/benmorgan/.cargo/registry/src/github.com-1ecc6299db9ec823/rustc-serialize-0.2.9/src/json.rs:358 fmt::Debug::fmt(&self, f)
^~~~~~~~~~~~~~~
/Users/benmorgan/.cargo/registry/src/github.com-1ecc6299db9ec823/rustc-serialize-0.2.9/src/json.rs:366:6: 366:18 error: attempt to implement a nonexistent trait `fmt::Display`
/Users/benmorgan/.cargo/registry/src/github.com-1ecc6299db9ec823/rustc-serialize-0.2.9/src/json.rs:366 impl fmt::Display for ParserError {
^~~~~~~~~~~~
/Users/benmorgan/.cargo/registry/src/github.com-1ecc6299db9ec823/rustc-serialize-0.2.9/src/json.rs:368:9: 368:24 error: failed to resolve. Could not find `Debug` in `std::fmt`
/Users/benmorgan/.cargo/registry/src/github.com-1ecc6299db9ec823/rustc-serialize-0.2.9/src/json.rs:368 fmt::Debug::fmt(&self, f)
^~~~~~~~~~~~~~~
/Users/benmorgan/.cargo/registry/src/github.com-1ecc6299db9ec823/rustc-serialize-0.2.9/src/json.rs:368:9: 368:24 error: unresolved name `fmt::Debug::fmt`
/Users/benmorgan/.cargo/registry/src/github.com-1ecc6299db9ec823/rustc-serialize-0.2.9/src/json.rs:368 fmt::Debug::fmt(&self, f)
^~~~~~~~~~~~~~~
/Users/benmorgan/.cargo/registry/src/github.com-1ecc6299db9ec823/rustc-serialize-0.2.9/src/json.rs:376:6: 376:18 error: attempt to implement a nonexistent trait `fmt::Display`
/Users/benmorgan/.cargo/registry/src/github.com-1ecc6299db9ec823/rustc-serialize-0.2.9/src/json.rs:376 impl fmt::Display for EncoderError {
^~~~~~~~~~~~
/Users/benmorgan/.cargo/registry/src/github.com-1ecc6299db9ec823/rustc-serialize-0.2.9/src/json.rs:378:9: 378:24 error: failed to resolve. Could not find `Debug` in `std::fmt`
/Users/benmorgan/.cargo/registry/src/github.com-1ecc6299db9ec823/rustc-serialize-0.2.9/src/json.rs:378 fmt::Debug::fmt(&self, f)
^~~~~~~~~~~~~~~
/Users/benmorgan/.cargo/registry/src/github.com-1ecc6299db9ec823/rustc-serialize-0.2.9/src/json.rs:378:9: 378:24 error: unresolved name `fmt::Debug::fmt`
/Users/benmorgan/.cargo/registry/src/github.com-1ecc6299db9ec823/rustc-serialize-0.2.9/src/json.rs:378 fmt::Debug::fmt(&self, f)
^~~~~~~~~~~~~~~
/Users/benmorgan/.cargo/registry/src/github.com-1ecc6299db9ec823/rustc-serialize-0.2.9/src/json.rs:2556:6: 2556:18 error: attempt to implement a nonexistent trait `fmt::Display`
/Users/benmorgan/.cargo/registry/src/github.com-1ecc6299db9ec823/rustc-serialize-0.2.9/src/json.rs:2556 impl fmt::Display for Json {
^~~~~~~~~~~~
/Users/benmorgan/.cargo/registry/src/github.com-1ecc6299db9ec823/rustc-serialize-0.2.9/src/json.rs:2568:10: 2568:22 error: attempt to implement a nonexistent trait `fmt::Display`
/Users/benmorgan/.cargo/registry/src/github.com-1ecc6299db9ec823/rustc-serialize-0.2.9/src/json.rs:2568 impl<'a> fmt::Display for PrettyJson<'a> {
^~~~~~~~~~~~
/Users/benmorgan/.cargo/registry/src/github.com-1ecc6299db9ec823/rustc-serialize-0.2.9/src/json.rs:2580:24: 2580:36 error: attempt to implement a nonexistent trait `fmt::Display`
/Users/benmorgan/.cargo/registry/src/github.com-1ecc6299db9ec823/rustc-serialize-0.2.9/src/json.rs:2580 impl<'a, T: Encodable> fmt::Display for AsJson<'a, T> {
^~~~~~~~~~~~
/Users/benmorgan/.cargo/registry/src/github.com-1ecc6299db9ec823/rustc-serialize-0.2.9/src/json.rs:2600:24: 2600:36 error: attempt to implement a nonexistent trait `fmt::Display`
/Users/benmorgan/.cargo/registry/src/github.com-1ecc6299db9ec823/rustc-serialize-0.2.9/src/json.rs:2600 impl<'a, T: Encodable> fmt::Display for AsPrettyJson<'a, T> {
^~~~~~~~~~~~
error: aborting due to 22 previous errors
Fresh unsafe-any v0.2.1
Fresh nickel_macros v0.0.1 (https://github.com/nickel-org/nickel.rs.git#4e7b5dda)
Fresh libc v0.1.0
Compiling anymap v0.9.9 (https://github.com/nickel-org/anymap.git#26ca5678)
Running `rustc /Users/benmorgan/.cargo/git/checkouts/anymap-b244d42fb4bc5d28/master/src/lib.rs --crate-name anymap --crate-type lib -g -C metadata=bc8106039bccd388 -C extra-filename=-bc8106039bccd388 --out-dir /Users/benmorgan/Sites/sandbox/rust/nickel-demo/target/deps --emit=dep-info,link -L dependency=/Users/benmorgan/Sites/sandbox/rust/nickel-demo/target/deps -L dependency=/Users/benmorgan/Sites/sandbox/rust/nickel-demo/target/deps -Awarnings`
/Users/benmorgan/.cargo/git/checkouts/anymap-b244d42fb4bc5d28/master/src/lib.rs:11:21: 11:27 error: unresolved import `std::any::TypeId`. There is no `TypeId` in `std::any`
/Users/benmorgan/.cargo/git/checkouts/anymap-b244d42fb4bc5d28/master/src/lib.rs:11 use std::any::{Any, TypeId};
^~~~~~
error: aborting due to previous error
Fresh matches v0.1.2
Build failed, waiting for other jobs to finish...
/Users/benmorgan/.cargo/registry/src/github.com-1ecc6299db9ec823/pkg-config-0.1.6/src/lib.rs:40:45: 40:48 error: the trait `core::fmt::Show` is not implemented for the type `std::io::process::Command`
/Users/benmorgan/.cargo/registry/src/github.com-1ecc6299db9ec823/pkg-config-0.1.6/src/lib.rs:40 format!("failed to run `{:?}`: {}", cmd, e)
^~~
note: in expansion of format_args!
<std macros>:2:28: 2:61 note: expansion site
<std macros>:1:1: 2:63 note: in expansion of format!
/Users/benmorgan/.cargo/registry/src/github.com-1ecc6299db9ec823/pkg-config-0.1.6/src/lib.rs:40:9: 41:6 note: expansion site
<std macros>:1:1: 6:60 note: in expansion of try!
/Users/benmorgan/.cargo/registry/src/github.com-1ecc6299db9ec823/pkg-config-0.1.6/src/lib.rs:39:15: 41:9 note: expansion site
/Users/benmorgan/.cargo/registry/src/github.com-1ecc6299db9ec823/pkg-config-0.1.6/src/lib.rs:45:71: 45:74 error: the trait `core::fmt::Show` is not implemented for the type `std::io::process::Command`
/Users/benmorgan/.cargo/registry/src/github.com-1ecc6299db9ec823/pkg-config-0.1.6/src/lib.rs:45 let mut msg = format!("`{:?}` did not exit successfully: {}", cmd,
^~~
note: in expansion of format_args!
<std macros>:2:28: 2:61 note: expansion site
<std macros>:1:1: 2:63 note: in expansion of format!
/Users/benmorgan/.cargo/registry/src/github.com-1ecc6299db9ec823/pkg-config-0.1.6/src/lib.rs:45:23: 46:43 note: expansion site
/Users/benmorgan/.cargo/git/checkouts/rust-mustache-b850d4795ca6321d/master/src/builder.rs:137:53: 137:78 error: mismatched types: expected `core::cell::RefCell<Box<core::ops::FnMut(collections::string::String) -> collections::string::String + Send>>`, found `core::cell::RefCell<Box<F>>` (expected trait core::ops::FnMut, found type parameter)
/Users/benmorgan/.cargo/git/checkouts/rust-mustache-b850d4795ca6321d/master/src/builder.rs:137 data.insert(key.as_slice().to_string(), Fun(RefCell::new(Box::new(f))));
^~~~~~~~~~~~~~~~~~~~~~~~~
/Users/benmorgan/.cargo/registry/src/github.com-1ecc6299db9ec823/gcc-0.1.6/src/lib.rs:119:31: 119:34 error: the trait `core::fmt::Show` is not implemented for the type `std::io::process::Command`
/Users/benmorgan/.cargo/registry/src/github.com-1ecc6299db9ec823/gcc-0.1.6/src/lib.rs:119 println!("running: {:?}", cmd);
^~~
note: in expansion of format_args!
<std macros>:2:42: 2:75 note: expansion site
<std macros>:1:1: 2:77 note: in expansion of println!
/Users/benmorgan/.cargo/registry/src/github.com-1ecc6299db9ec823/gcc-0.1.6/src/lib.rs:119:5: 119:36 note: expansion site
/Users/benmorgan/.cargo/git/checkouts/rust-mustache-b850d4795ca6321d/master/src/builder.rs:273:23: 273:48 error: mismatched types: expected `core::cell::RefCell<Box<core::ops::FnMut(collections::string::String) -> collections::string::String + Send>>`, found `core::cell::RefCell<Box<F>>` (expected trait core::ops::FnMut, found type parameter)
/Users/benmorgan/.cargo/git/checkouts/rust-mustache-b850d4795ca6321d/master/src/builder.rs:273 data.push(Fun(RefCell::new(Box::new(f))));
^~~~~~~~~~~~~~~~~~~~~~~~~
error: aborting due to 2 previous errors
error: aborting due to previous error
error: aborting due to 2 previous errors
Could not compile `rustc-serialize`.
Caused by:
Process didn't exit successfully: `rustc /Users/benmorgan/.cargo/registry/src/github.com-1ecc6299db9ec823/rustc-serialize-0.2.9/src/lib.rs --crate-name rustc-serialize --crate-type lib -g -C metadata=8214bc2e838e96ca -C extra-filename=-8214bc2e838e96ca --out-dir /Users/benmorgan/Sites/sandbox/rust/nickel-demo/target/deps --emit=dep-info,link -L dependency=/Users/benmorgan/Sites/sandbox/rust/nickel-demo/target/deps -L dependency=/Users/benmorgan/Sites/sandbox/rust/nickel-demo/target/deps -Awarnings` (status=101)
I propose to implement as_object_mut
and as_array_mut
methods that are very useful when we want to modify JSON object/array in-place.
If you agree I'll make a PR.
I was hoping to use this crate to #[derive(RustcEncodable, RustcDecodable)]
on SocketAddr
, however it does not appear to be possible with the orphan trait restrictions.
Are there any guides on how I might do this?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.