Skip to content

Commit 5f7b73a

Browse files
committed
Adds missing test.
1 parent 33f853a commit 5f7b73a

File tree

4 files changed

+86
-0
lines changed

4 files changed

+86
-0
lines changed
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
[[package]]
2+
name = "core"
3+
source = "path+from-root-708A1FDFF71F06AE"
4+
5+
[[package]]
6+
name = "std"
7+
source = "path+from-root-708A1FDFF71F06AE"
8+
dependencies = ["core"]
9+
10+
[[package]]
11+
name = "trait_generic_override"
12+
source = "member"
13+
dependencies = ["std"]
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
[project]
2+
authors = ["Fuel Labs <contact@fuel.sh>"]
3+
entry = "main.sw"
4+
license = "Apache-2.0"
5+
name = "trait_generic_override"
6+
7+
[dependencies]
8+
std = { path = "../../../../../../../sway-lib-std" }
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
script;
2+
3+
use std::constants::ZERO_B256;
4+
5+
struct MyStruct<T> {
6+
val: u64
7+
}
8+
9+
trait From<T> {
10+
fn from2(num: T) -> Self;
11+
fn try_from2(num: T) -> Option<Self>;
12+
fn into2(self) -> T;
13+
}
14+
15+
// Implements on MyStruct<T>
16+
impl<T> From<b256> for MyStruct<T> {
17+
fn from2(num: b256) -> Self {
18+
MyStruct { val: 0 }
19+
}
20+
21+
fn try_from2(num: b256) -> Option<Self> {
22+
Some(MyStruct { val: 0 })
23+
}
24+
25+
fn into2(self) -> b256 {
26+
ZERO_B256
27+
}
28+
}
29+
30+
// Implements on MyStruct<u64>
31+
impl From<u64> for MyStruct<u64> {
32+
fn from2(num: u64) -> Self {
33+
MyStruct { val: 0 }
34+
}
35+
36+
fn try_from2(num: u64) -> Option<Self> {
37+
Some(MyStruct { val: 0 })
38+
}
39+
40+
fn into2(self) -> u64 {
41+
0
42+
}
43+
}
44+
45+
fn main() -> bool {
46+
let my_struct: MyStruct<u64> = MyStruct { val: 1 };
47+
let my_b256 = ZERO_B256;
48+
let my_u64 = 1_u64;
49+
50+
let _into_b256: b256 = my_struct.into2();
51+
let _into_u64: u64 = my_struct.into2();
52+
53+
let _from_b256: MyStruct<b256> = MyStruct::from2(my_b256);
54+
let _from_u64: MyStruct<u64> = MyStruct::from2(my_u64);
55+
56+
let _try_from_b256: Option<MyStruct<b256>> = MyStruct::try_from2(my_b256);
57+
let _try_from_u64: Option<MyStruct<u64>> = MyStruct::try_from2(my_u64);
58+
59+
true
60+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
category = "run"
2+
expected_result = { action = "return", value = 1 }
3+
expected_result_new_encoding = { action = "return_data", value = "01" }
4+
validate_abi = false
5+
expected_warnings = 7

0 commit comments

Comments
 (0)