Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
parity
Mirrored projects
parity-scale-codec
Commits
e71d9c1a
Unverified
Commit
e71d9c1a
authored
Jun 08, 2021
by
Robin Freyler
Committed by
GitHub
Jun 08, 2021
Browse files
improve macro hygiene (#271)
parent
9ab44832
Pipeline
#141315
passed with stages
in 19 minutes and 51 seconds
Changes
3
Pipelines
1
Show whitespace changes
Inline
Side-by-side
derive/src/decode.rs
View file @
e71d9c1a
...
...
@@ -42,7 +42,7 @@ pub fn quote(
),
Fields
::
Unit
=>
{
quote_spanned!
{
data
.fields
.span
()
=>
Ok
(
#
type_name
)
::
core
::
result
::
Result
::
Ok
(
#
type_name
)
}
},
},
...
...
@@ -68,7 +68,7 @@ pub fn quote(
);
quote_spanned!
{
v
.span
()
=>
__codec_x_edqy
if
__codec_x_edqy
==
#
index
as
u8
=>
{
__codec_x_edqy
if
__codec_x_edqy
==
#
index
as
::
core
::
primitive
::
u8
=>
{
#
create
},
}
...
...
@@ -87,7 +87,7 @@ pub fn quote(
.map_err
(|
e
|
e
.chain
(
#
read_byte_err_msg
))
?
{
#
(
#
recurse
)
*
_
=>
Err
(
#
invalid_variant_err_msg
.into
()),
_
=>
::
core
::
result
::
Result
::
Err
(
#
invalid_variant_err_msg
.into
()),
}
}
...
...
@@ -120,8 +120,8 @@ fn create_decode_expr(field: &Field, name: &str, input: &TokenStream) -> TokenSt
<
#
field_type
as
_parity_scale_codec
::
HasCompact
>
::
Type
as
_parity_scale_codec
::
Decode
>
::
decode
(
#
input
);
match
#
res
{
Err
(
e
)
=>
return
Err
(
e
.chain
(
#
err_msg
)),
Ok
(
#
res
)
=>
#
res
.into
(),
::
core
::
result
::
Result
::
Err
(
e
)
=>
return
::
core
::
result
::
Result
::
Err
(
e
.chain
(
#
err_msg
)),
::
core
::
result
::
Result
::
Ok
(
#
res
)
=>
#
res
.into
(),
}
}
}
...
...
@@ -130,21 +130,21 @@ fn create_decode_expr(field: &Field, name: &str, input: &TokenStream) -> TokenSt
{
let
#
res
=
<
#
encoded_as
as
_parity_scale_codec
::
Decode
>
::
decode
(
#
input
);
match
#
res
{
Err
(
e
)
=>
return
Err
(
e
.chain
(
#
err_msg
)),
Ok
(
#
res
)
=>
#
res
.into
(),
::
core
::
result
::
Result
::
Err
(
e
)
=>
return
::
core
::
result
::
Result
::
Err
(
e
.chain
(
#
err_msg
)),
::
core
::
result
::
Result
::
Ok
(
#
res
)
=>
#
res
.into
(),
}
}
}
}
else
if
skip
{
quote_spanned!
{
field
.span
()
=>
Default
::
default
()
}
quote_spanned!
{
field
.span
()
=>
::
core
::
default
::
Default
::
default
()
}
}
else
{
let
field_type
=
&
field
.ty
;
quote_spanned!
{
field
.span
()
=>
{
let
#
res
=
<
#
field_type
as
_parity_scale_codec
::
Decode
>
::
decode
(
#
input
);
match
#
res
{
Err
(
e
)
=>
return
Err
(
e
.chain
(
#
err_msg
)),
Ok
(
#
res
)
=>
#
res
,
::
core
::
result
::
Result
::
Err
(
e
)
=>
return
::
core
::
result
::
Result
::
Err
(
e
.chain
(
#
err_msg
)),
::
core
::
result
::
Result
::
Ok
(
#
res
)
=>
#
res
,
}
}
}
...
...
@@ -173,7 +173,7 @@ fn create_instance(
});
quote_spanned!
{
fields
.span
()
=>
Ok
(
#
name
{
::
core
::
result
::
Result
::
Ok
(
#
name
{
#
(
#
recurse
,
)
*
})
}
...
...
@@ -186,14 +186,14 @@ fn create_instance(
});
quote_spanned!
{
fields
.span
()
=>
Ok
(
#
name
(
::
core
::
result
::
Result
::
Ok
(
#
name
(
#
(
#
recurse
,
)
*
))
}
},
Fields
::
Unit
=>
{
quote_spanned!
{
fields
.span
()
=>
Ok
(
#
name
)
::
core
::
result
::
Result
::
Ok
(
#
name
)
}
},
}
...
...
derive/src/encode.rs
View file @
e71d9c1a
...
...
@@ -85,7 +85,7 @@ fn encode_single_field(
_parity_scale_codec
::
Encode
::
encode
(
&
#
final_field_variable
)
}
fn
using_encoded
<
R
,
F
:
FnOnce
(
&
[
u8
])
->
R
>
(
&
#
i_self
,
f
:
F
)
->
R
{
fn
using_encoded
<
R
,
F
:
::
core
::
ops
::
FnOnce
(
&
[::
core
::
primitive
::
u8
])
->
R
>
(
&
#
i_self
,
f
:
F
)
->
R
{
_parity_scale_codec
::
Encode
::
using_encoded
(
&
#
final_field_variable
,
f
)
}
}
...
...
@@ -240,7 +240,7 @@ fn impl_encode(data: &Data, type_name: &Ident) -> TokenStream {
quote_spanned!
{
f
.span
()
=>
#
type_name
::
#
name
{
#
(
ref
#
names
,
)
*
}
=>
{
#
dest
.push_byte
(
#
index
as
u8
);
#
dest
.push_byte
(
#
index
as
::
core
::
primitive
::
u8
);
#
encode_fields
}
}
...
...
@@ -265,7 +265,7 @@ fn impl_encode(data: &Data, type_name: &Ident) -> TokenStream {
quote_spanned!
{
f
.span
()
=>
#
type_name
::
#
name
(
#
(
ref
#
names
,
)
*
)
=>
{
#
dest
.push_byte
(
#
index
as
u8
);
#
dest
.push_byte
(
#
index
as
::
core
::
primitive
::
u8
);
#
encode_fields
}
}
...
...
@@ -273,7 +273,7 @@ fn impl_encode(data: &Data, type_name: &Ident) -> TokenStream {
Fields
::
Unit
=>
{
quote_spanned!
{
f
.span
()
=>
#
type_name
::
#
name
=>
{
#
dest
.push_byte
(
#
index
as
u8
);
#
dest
.push_byte
(
#
index
as
::
core
::
primitive
::
u8
);
}
}
},
...
...
derive/src/lib.rs
View file @
e71d9c1a
...
...
@@ -210,7 +210,7 @@ pub fn decode_derive(input: proc_macro::TokenStream) -> proc_macro::TokenStream
impl
#
impl_generics
_parity_scale_codec
::
Decode
for
#
name
#
ty_generics
#
where_clause
{
fn
decode
<
__CodecInputEdqy
:
_parity_scale_codec
::
Input
>
(
#
input_
:
&
mut
__CodecInputEdqy
)
->
core
::
result
::
Result
<
Self
,
_parity_scale_codec
::
Error
>
{
)
->
::
core
::
result
::
Result
<
Self
,
_parity_scale_codec
::
Error
>
{
#
decoding
}
}
...
...
@@ -312,9 +312,9 @@ pub fn compact_as_derive(input: proc_macro::TokenStream) -> proc_macro::TokenStr
#
inner_field
}
fn
decode_from
(
x
:
#
inner_ty
)
->
core
::
result
::
Result
<
#
name
#
ty_generics
,
_parity_scale_codec
::
Error
>
->
::
core
::
result
::
Result
<
#
name
#
ty_generics
,
_parity_scale_codec
::
Error
>
{
Ok
(
#
constructor
)
::
core
::
result
::
Result
::
Ok
(
#
constructor
)
}
}
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment