@@ -31,23 +31,33 @@ pub enum Error {
3131 expected( possible_field_names)
3232 ) ]
3333 UnknownField {
34+ /// Unknown field that was encountered
3435 unknown_field : String ,
36+ /// Possible fields that are expected
3537 possible_field_names : & ' static [ & ' static str ] ,
3638 } ,
39+ /// unnamed enum field is not an array
3740 #[ error( "unnamed enum field `{0}` is not an array" ) ]
3841 FieldNotAnArray ( & ' static str ) ,
42+ /// unknwon enum variant
3943 #[ error( "unknwon enum variant `{0}`" ) ]
4044 UnknownEnumVariant ( String ) ,
45+ /// invalid enum representation, needs to be either a string or an object
4146 #[ error( "invalid enum representation, needs to be either a string or an object" ) ]
4247 InvalidEnumRepresentation ,
48+ /// invalid struct representation, needs to be an object
4349 #[ error( "invalid struct representation, needs to be an object" ) ]
4450 InvalidStructRepresentation ,
51+ /// Unexpected e,nd of input
4552 #[ error( "Unexpected e,nd of input" ) ]
4653 EOF ,
54+ /// Invalid integer number
4755 #[ error( "Invalid integer number" ) ]
4856 InvalidNumber ( #[ from] TryFromIntError ) ,
57+ /// Custom error
4958 #[ error( "Custom error: {0}" ) ]
5059 Custom ( String ) ,
60+ /// The universe is broken
5161 #[ error( "The universe is broken: {0}" ) ]
5262 BrokenUniverse ( #[ from] std:: convert:: Infallible ) ,
5363}
@@ -58,43 +68,58 @@ impl Error {
5868 Error :: Custom ( msg. to_string ( ) )
5969 }
6070 /// Expected String error
71+ #[ must_use]
6172 pub const fn expected_string ( ) -> Self {
6273 Error :: Json ( simd_json:: ErrorType :: ExpectedString )
6374 }
6475 /// Expected Map error
76+ #[ must_use]
6577 pub const fn expected_map ( ) -> Self {
6678 Error :: Json ( simd_json:: ErrorType :: ExpectedMap )
6779 }
6880 /// Expected Array error
81+ #[ must_use]
6982 pub const fn expected_array ( ) -> Self {
7083 Error :: Json ( simd_json:: ErrorType :: ExpectedArray )
7184 }
7285 /// Expected Float error
86+ #[ must_use]
7387 pub const fn expected_float ( ) -> Self {
7488 Error :: Json ( simd_json:: ErrorType :: ExpectedFloat )
7589 }
7690 /// Expected Null error
91+ #[ must_use]
7792 pub fn expected_null ( ) -> Self {
7893 Error :: Json ( simd_json:: ErrorType :: ExpectedNull )
7994 }
8095 /// Expected Integer error
96+ #[ must_use]
8197 pub fn expected_integer ( ) -> Self {
8298 Error :: Json ( simd_json:: ErrorType :: ExpectedInteger )
8399 }
84100 /// Expected Boolean error
101+ #[ must_use]
85102 pub fn expected_boolean ( ) -> Self {
86103 Error :: Json ( simd_json:: ErrorType :: ExpectedBoolean )
87104 }
88105}
89106
90107// Deserialisation result
108+ /// Deserializer result
91109pub type Result < T > = std:: result:: Result < T , Error > ;
92110
111+ /// Deserialisation trait for simd-json
93112pub trait Deserialize < ' input > {
113+ /// Deserializes from a tape
114+ /// # Errors
115+ /// if deserialisation fails
94116 fn from_tape ( tape : & mut Tape < ' input > ) -> Result < Self >
95117 where
96118 Self : Sized + ' input ;
97119
120+ /// Deserializes from a u8 slice
121+ /// # Errors
122+ /// if deserialisation fails
98123 #[ inline]
99124 fn from_slice ( json : & ' input mut [ u8 ] ) -> Result < Self >
100125 where
@@ -105,6 +130,9 @@ pub trait Deserialize<'input> {
105130 Self :: from_tape ( & mut itr)
106131 }
107132
133+ /// Deserializes from a u8 slice using pre-allocated buffers
134+ /// # Errors
135+ /// if deserialisation fails
108136 #[ inline]
109137 fn from_slice_with_buffers ( json : & ' input mut [ u8 ] , buffers : & mut Buffers ) -> Result < Self >
110138 where
@@ -116,6 +144,8 @@ pub trait Deserialize<'input> {
116144 }
117145
118146 #[ inline]
147+ /// # Errors
148+ /// if deserialisation fails
119149 /// # Safety
120150 ///
121151 /// user must not use the string afterwards
0 commit comments