Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
37c0a57
Parameterize CompactForm String for optional SCALE impl
ascjones Dec 7, 2020
643f09d
Merge remote-tracking branch 'origin/master' into aj-compact-string
dvdplm Dec 14, 2020
9a7ccbf
Fix no-std compilation
dvdplm Dec 14, 2020
254fee1
Obey the fmt
dvdplm Dec 14, 2020
e74e4f9
Introduce String trait for Form
ascjones Dec 16, 2020
7860c79
Rename "Compact" to "Frozen" (and associated fallout)
dvdplm Dec 16, 2020
579f958
Docs cleanup and more renames
dvdplm Dec 17, 2020
8333e5a
Cleanup
dvdplm Dec 17, 2020
2818f7b
More cleanup
dvdplm Dec 17, 2020
7706a38
Merge branch 'aj-compact-string' into dp-rename-compact-to-frozen
dvdplm Dec 17, 2020
e03a2cd
obey the fmt
dvdplm Dec 17, 2020
3a95663
Add a `compact` flag to `Field` to indicate that this type is to be e…
dvdplm Dec 17, 2020
004e107
Clippy warnings
dvdplm Dec 17, 2020
93a9aeb
Acommodate older clippy
dvdplm Dec 17, 2020
6569e50
Derive (scale) compact fields
dvdplm Dec 28, 2020
f098101
Merge branch 'master' into dp-flag-types-as-compact
dvdplm Jan 4, 2021
eda2769
Merge remote-tracking branch 'origin/master' into dp-flag-types-as-co…
dvdplm Jan 5, 2021
09c1241
WIP
dvdplm Jan 8, 2021
55f1413
Sort out the TypeInfo impl for Compact<T> (ty @ascjones!)
dvdplm Jan 8, 2021
e2397bf
Clean up conditionals a bit
dvdplm Jan 11, 2021
d15bf25
Add Compact to prelude
dvdplm Jan 11, 2021
1f4f8d3
Cleanup
dvdplm Jan 11, 2021
02ed1a3
fmt
dvdplm Jan 11, 2021
80a8b27
Merge branch 'master' into dp-add-TypeDef-to-handle-Compact-types
dvdplm Jan 18, 2021
7389297
fmt
dvdplm Jan 18, 2021
d8506dc
Sort out TODOs
dvdplm Jan 18, 2021
ab56118
Remove unused top-level way of adding a Compact
dvdplm Jan 19, 2021
5436755
Merge remote-tracking branch 'origin/master' into dp-add-TypeDef-to-h…
dvdplm Jan 27, 2021
c70f31c
Merge remote-tracking branch 'origin/master' into dp-add-TypeDef-to-h…
dvdplm Jan 29, 2021
e656489
Merge remote-tracking branch 'origin/master' into dp-add-TypeDef-to-h…
dvdplm Jan 29, 2021
1c0c05d
Remove unneeded bound
dvdplm Jan 29, 2021
693b23a
Remove `Compact` from the prelude
dvdplm Jan 29, 2021
c2a38f5
Resolve TODO
dvdplm Jan 29, 2021
5649a66
fmt
dvdplm Jan 29, 2021
aad3277
Use <T as HasCompact>::Type rather than Compact<T> (ty @thiolliere!)
dvdplm Jan 29, 2021
4b18500
Split long comment
dvdplm Jan 31, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Cleanup
  • Loading branch information
dvdplm committed Jan 11, 2021
commit 1f4f8d38959e01a391dd4d5103fe1908cef6bdb0
1 change: 0 additions & 1 deletion src/meta_type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,6 @@ impl MetaType {
}
}

// TODO: is this used anywhere?
/// Creates a new meta type from the type of the given reference.
pub fn of<T>(_elem: &T) -> Self
where
Expand Down
7 changes: 2 additions & 5 deletions src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,14 +81,11 @@ fn prelude_items() {
.type_params(tuple_meta_type!(i32))
.composite(Fields::unit())
);
}

#[test]
fn compact_types() {
assert_type!(
scale::Compact<i32>,
prelude::Compact<i32>,
Type::builder()
.path(Path::from_segments(vec!["scale", "Compact"]).unwrap())
.path(Path::prelude("Compact"))
.type_params(tuple_meta_type!(i32))
.compact::<i32>()
);
Expand Down
3 changes: 0 additions & 3 deletions src/ty/fields.rs
Original file line number Diff line number Diff line change
Expand Up @@ -143,9 +143,6 @@ impl Field {
where
T: TypeInfo + 'static,
{
// TODO: using `scale::Compact` here like this makes the `impl<T>
// TypeInfo for Compact<T>` kick in, but not sure that is the right
// thing to do. :/
Self::new(name, MetaType::new::<scale::Compact<T>>(), type_name)
}
}
Expand Down
3 changes: 1 addition & 2 deletions src/ty/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,7 @@ impl From<TypeDefTuple> for Type {
impl From<TypeDefCompact> for Type {
fn from(compact: TypeDefCompact) -> Self {
Self::new(
// TODO: put `Compact` in the prelude
Path::new("Compact", "scale"),
Path::prelude("Compact"),
vec![compact.type_param],
compact,
)
Expand Down
44 changes: 20 additions & 24 deletions test_suite/tests/derive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,10 @@ use pretty_assertions::assert_eq;
use scale::Encode;
use scale_info::{
build::*,
prelude::boxed::Box,
prelude::{
boxed::Box,
Compact,
},
tuple_meta_type,
Path,
Type,
Expand Down Expand Up @@ -214,36 +217,29 @@ fn scale_compact_types_work_in_structs() {
b: u16,
}

let dense = Type::builder()
let ty = Type::builder()
.path(Path::new("Dense", "derive"))
.composite(
Fields::named()
.field_of::<u8>("a", "u8")
.field_of::<scale::Compact<u16>>("b", "u16"),
.field_of::<Compact<u16>>("b", "u16"),
);

assert_type!(Dense, dense);
}
assert_type!(Dense, ty);

// TODO: both this test and the one above pass, which means something's not
// right.
#[test]
fn wip() {
#[allow(unused)]
#[derive(Encode, TypeInfo)]
struct A {
a: u8,
#[codec(compact)]
b: u16,
}
let ty = Type::builder()
.path(Path::new("A", "derive"))
.composite(
Fields::named()
.field_of::<u8>("a", "u8")
.compact_of::<u16>("b", "u16")
);
assert_type!(A, ty);
// TODO: These two tests both pass. This illustrates a doubt I have that
// this is the right way to go. With this PR we take `#[codec(compact)]` to
// mean that the type is encoded/decoded as `Compact<T>` but in reality the
// output of the `Encode` macro is something quite different and not
// `Compact<T>`.
// Maybe this is fine, maybe it's not, just not sure.

let ty_alt = Type::builder().path(Path::new("Dense", "derive")).composite(
Fields::named()
.field_of::<u8>("a", "u8")
.compact_of::<u16>("b", "u16"),
);
assert_type!(Dense, ty_alt);
}

#[test]
Expand Down
4 changes: 2 additions & 2 deletions test_suite/tests/json.rs
Original file line number Diff line number Diff line change
Expand Up @@ -381,7 +381,7 @@ fn registry_knows_about_compact_types() {
}
},
{ // type 2, the `Compact<u128>` of field `a`.
"path": ["scale", "Compact"],
"path": ["Compact"],
"def": { "compact": { "type": 3 } },
"params": [3]
},
Expand All @@ -395,7 +395,7 @@ fn registry_knows_about_compact_types() {
"def": { "primitive": "u8" }
},
{ // type 6, the `Compact<u64>` of field `c`
"path": ["scale", "Compact"],
"path": ["Compact"],
"def": { "compact": { "type": 7 } },
"params": [7]
},
Expand Down