@@ -43,9 +43,14 @@ pub type List = ~[Json];
43
43
pub type Object = HashMap < ~str , Json > ;
44
44
45
45
#[ deriving( Eq ) ]
46
+ /// If an error occurs while parsing some JSON, this is the structure which is
47
+ /// returned
46
48
pub struct Error {
49
+ /// The line number at which the error occurred
47
50
line : uint ,
51
+ /// The column number at which the error occurred
48
52
col : uint ,
53
+ /// A message describing the type of the error
49
54
msg : @~str ,
50
55
}
51
56
@@ -75,10 +80,13 @@ fn spaces(n: uint) -> ~str {
75
80
return ss;
76
81
}
77
82
83
+ /// A structure for implementing serialization to JSON.
78
84
pub struct Encoder {
79
85
priv wr: @io:: Writer ,
80
86
}
81
87
88
+ /// Creates a new JSON encoder whose output will be written to the writer
89
+ /// specified.
82
90
pub fn Encoder ( wr : @io:: Writer ) -> Encoder {
83
91
Encoder {
84
92
wr : wr
@@ -228,11 +236,14 @@ impl serialize::Encoder for Encoder {
228
236
}
229
237
}
230
238
239
+ /// Another encoder for JSON, but prints out human-readable JSON instead of
240
+ /// compact data
231
241
pub struct PrettyEncoder {
232
242
priv wr: @io:: Writer ,
233
243
priv indent : uint ,
234
244
}
235
245
246
+ /// Creates a new encoder whose output will be written to the specified writer
236
247
pub fn PrettyEncoder ( wr : @io:: Writer ) -> PrettyEncoder {
237
248
PrettyEncoder {
238
249
wr : wr,
@@ -468,6 +479,7 @@ pub fn to_pretty_str(json: &Json) -> ~str {
468
479
io:: with_str_writer ( |wr| to_pretty_writer ( wr, json) )
469
480
}
470
481
482
+ #[ allow( missing_doc) ]
471
483
pub struct Parser {
472
484
priv rdr: @io:: Reader ,
473
485
priv ch: char ,
@@ -846,10 +858,12 @@ pub fn from_str(s: &str) -> Result<Json, Error> {
846
858
}
847
859
}
848
860
861
+ /// A structure to decode JSON to values in rust.
849
862
pub struct Decoder {
850
863
priv stack : ~[ Json ] ,
851
864
}
852
865
866
+ /// Creates a new decoder instance for decoding the specified JSON value.
853
867
pub fn Decoder ( json : Json ) -> Decoder {
854
868
Decoder {
855
869
stack : ~[ json]
@@ -1200,7 +1214,11 @@ impl Ord for Json {
1200
1214
fn gt ( & self , other : & Json ) -> bool { ( * other) . lt ( & ( * self ) ) }
1201
1215
}
1202
1216
1203
- trait ToJson { fn to_json ( & self ) -> Json ; }
1217
+ /// A trait for converting values to JSON
1218
+ trait ToJson {
1219
+ /// Converts the value of `self` to an instance of JSON
1220
+ fn to_json ( & self ) -> Json ;
1221
+ }
1204
1222
1205
1223
impl ToJson for Json {
1206
1224
fn to_json ( & self ) -> Json { copy * self }
0 commit comments