Skip to content

Commit

Permalink
[feature] #2004: Forbid isize and usize from becoming IntoSchema.
Browse files Browse the repository at this point in the history
Signed-off-by: Aleksandr Petrosyan <a-p-petrosyan@yandex.ru>
  • Loading branch information
appetrosyan committed May 6, 2022
1 parent c59ad0d commit 4537095
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 0 deletions.
8 changes: 8 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions schema/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,6 @@ fixnum = { version = "0.6.1", default-features = false, features = ["i64"] }

[dev-dependencies]
parity-scale-codec = { version = "2.3.1", default-features = false, features = ["derive", "full"] }
impls = { version = "=1.0.0" }

iroha_schema_gen = { version = "=2.0.0-pre-rc.4", path = "gen" }
24 changes: 24 additions & 0 deletions schema/tests/architecture-dependent.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
use impls::impls;
use iroha_schema::IntoSchema;
use parity_scale_codec::{Decode, Encode};

#[test]
fn usize_isize_not_into_schema() {
// The architecture-dependent
assert!(!impls!(usize: IntoSchema));
assert!(!impls!(isize: IntoSchema));

// use serde::Serialize;
//
// assert!(!impls!(usize: Serialize));
// `usize` should be `Serialize`.

// But not `Encode`/`Decode`.
assert!(!impls!(usize: Encode | Decode));
assert!(!impls!(isize: Encode | Decode));

// There are no other primitive architecture-dependent types, so
// as long as `IntoSchema` requires all variants and all fields to
// also be `IntoSchema`, we are guaranteed that all schema types
// are safe to exchange.
}

0 comments on commit 4537095

Please sign in to comment.