chyh1990 / yaml-rust

A pure rust YAML implementation.
Apache License 2.0
609 stars 140 forks source link

Support unsigned type #128

Open jerry73204 opened 5 years ago

jerry73204 commented 5 years ago

I found .as_u64() is not available along with .as_i64(). It leaves me a bit inconvenience to parse the values manually. Is there a reason that it's included or is it not supported yet?

chyh1990 commented 5 years ago

as YAML only have Integer (signed) type, so it should be parse as i64

jerry73204 commented 5 years ago

Yes, I agree the idea to choose more a generalised type, but I think we can make things further.

The YAML spec states integer is arbitrary sized finite, so in I think there's no size limit and sign concept in mind. The spec later states it is parser's responsibility to reject or accept to convert to language type.

IMO, allowing {i,u}{8,16,32,64} basically does not violate the specification. We can simply move it ParseError whenever the Rust type cannot accept the value, and that would let users write less code with ? mark.