diff --git a/crates/sui-framework/docs/std/macros.md b/crates/sui-framework/docs/std/macros.md
index 25c8332062e21..9f1304e40fceb 100644
--- a/crates/sui-framework/docs/std/macros.md
+++ b/crates/sui-framework/docs/std/macros.md
@@ -40,7 +40,7 @@ This module holds shared implementation of macros used in std
-
public macro fun num_max($x: _, $y: _): _
+public macro fun num_max<$T>($x: $T, $y: $T): $T
@@ -49,7 +49,7 @@ This module holds shared implementation of macros used in std
Implementation
-public macro fun num_max($x: _, $y: _): _ {
+public macro fun num_max<$T>($x: $T, $y: $T): $T {
let x = $x;
let y = $y;
if (x > y) x
@@ -67,7 +67,7 @@ This module holds shared implementation of macros used in std
-public macro fun num_min($x: _, $y: _): _
+public macro fun num_min<$T>($x: $T, $y: $T): $T
@@ -76,7 +76,7 @@ This module holds shared implementation of macros used in std
Implementation
-public macro fun num_min($x: _, $y: _): _ {
+public macro fun num_min<$T>($x: $T, $y: $T): $T {
let x = $x;
let y = $y;
if (x < y) x
@@ -94,7 +94,7 @@ This module holds shared implementation of macros used in std
-public macro fun num_diff($x: _, $y: _): _
+public macro fun num_diff<$T>($x: $T, $y: $T): $T
@@ -103,7 +103,7 @@ This module holds shared implementation of macros used in std
Implementation
-public macro fun num_diff($x: _, $y: _): _ {
+public macro fun num_diff<$T>($x: $T, $y: $T): $T {
let x = $x;
let y = $y;
if (x > y) x - y
@@ -121,7 +121,7 @@ This module holds shared implementation of macros used in std
-public macro fun num_divide_and_round_up($x: _, $y: _): _
+public macro fun num_divide_and_round_up<$T>($x: $T, $y: $T): $T
@@ -130,7 +130,7 @@ This module holds shared implementation of macros used in std
Implementation
-public macro fun num_divide_and_round_up($x: _, $y: _): _ {
+public macro fun num_divide_and_round_up<$T>($x: $T, $y: $T): $T {
let x = $x;
let y = $y;
if (x % y == 0) x / y
@@ -255,7 +255,7 @@ This module holds shared implementation of macros used in std
-public macro fun range_do($start: _, $stop: _, $f: |_| -> ())
+public macro fun range_do<$T, $R: drop>($start: $T, $stop: $T, $f: |$T| -> $R)
@@ -264,7 +264,7 @@ This module holds shared implementation of macros used in std
Implementation
-public macro fun range_do($start: _, $stop: _, $f: |_|) {
+public macro fun range_do<$T, $R: drop>($start: $T, $stop: $T, $f: |$T| -> $R) {
let mut i = $start;
let stop = $stop;
while (i < stop) {
@@ -284,7 +284,7 @@ This module holds shared implementation of macros used in std
-public macro fun range_do_eq($start: _, $stop: _, $f: |_| -> ())
+public macro fun range_do_eq<$T, $R: drop>($start: $T, $stop: $T, $f: |$T| -> $R)
@@ -293,7 +293,7 @@ This module holds shared implementation of macros used in std
Implementation
-public macro fun range_do_eq($start: _, $stop: _, $f: |_|) {
+public macro fun range_do_eq<$T, $R: drop>($start: $T, $stop: $T, $f: |$T| -> $R) {
let mut i = $start;
let stop = $stop;
// we check `i >= stop` inside the loop instead of `i <= stop` as `while` condition to avoid
@@ -319,7 +319,7 @@ This module holds shared implementation of macros used in std
-public macro fun do($stop: _, $f: |_| -> ())
+public macro fun do<$T, $R: drop>($stop: $T, $f: |$T| -> $R)
@@ -328,7 +328,7 @@ This module holds shared implementation of macros used in std
Implementation
-public macro fun do($stop: _, $f: |_|) {
+public macro fun do<$T, $R: drop>($stop: $T, $f: |$T| -> $R) {
range_do!(0, $stop, $f)
}
@@ -343,7 +343,7 @@ This module holds shared implementation of macros used in std
-public macro fun do_eq($stop: _, $f: |_| -> ())
+public macro fun do_eq<$T, $R: drop>($stop: $T, $f: |$T| -> $R)
@@ -352,7 +352,7 @@ This module holds shared implementation of macros used in std
Implementation
-public macro fun do_eq($stop: _, $f: |_|) {
+public macro fun do_eq<$T, $R: drop>($stop: $T, $f: |$T| -> $R) {
range_do_eq!(0, $stop, $f)
}
diff --git a/crates/sui-framework/docs/std/option.md b/crates/sui-framework/docs/std/option.md
index c2987266d9cf2..5fa0cb6e855c4 100644
--- a/crates/sui-framework/docs/std/option.md
+++ b/crates/sui-framework/docs/std/option.md
@@ -569,7 +569,7 @@ and an empty vector otherwise
Destroy Option<T>
and call the closure f
on the value inside if it holds one.
-public macro fun destroy<$T>($o: std::option::Option<$T>, $f: |$T| -> ())
+public macro fun destroy<$T, $R: drop>($o: std::option::Option<$T>, $f: |$T| -> $R)
@@ -578,7 +578,7 @@ Destroy Option<T>
Implementation
-public macro fun destroy<$T>($o: Option<$T>, $f: |$T|) {
+public macro fun destroy<$T, $R: drop>($o: Option<$T>, $f: |$T| -> $R) {
let o = $o;
o.do!($f);
}
@@ -595,7 +595,7 @@ Destroy Option<T>
Destroy Option<T>
and call the closure f
on the value inside if it holds one.
-public macro fun do<$T>($o: std::option::Option<$T>, $f: |$T| -> ())
+public macro fun do<$T, $R: drop>($o: std::option::Option<$T>, $f: |$T| -> $R)
@@ -604,9 +604,9 @@ Destroy Option<T>
Implementation
-public macro fun do<$T>($o: Option<$T>, $f: |$T|) {
+public macro fun do<$T, $R: drop>($o: Option<$T>, $f: |$T| -> $R) {
let o = $o;
- if (o.is_some()) $f(o.destroy_some())
+ if (o.is_some()) { $f(o.destroy_some()); }
else o.destroy_none()
}
@@ -622,7 +622,7 @@ Destroy Option<T>
Execute a closure on the value inside t
if it holds one.
-public macro fun do_ref<$T>($o: &std::option::Option<$T>, $f: |&$T| -> ())
+public macro fun do_ref<$T, $R: drop>($o: &std::option::Option<$T>, $f: |&$T| -> $R)
@@ -631,9 +631,9 @@ Execute a closure on the value inside t
if it holds one.
Implementation
-public macro fun do_ref<$T>($o: &Option<$T>, $f: |&$T|) {
+public macro fun do_ref<$T, $R: drop>($o: &Option<$T>, $f: |&$T| -> $R) {
let o = $o;
- if (o.is_some()) $f(o.borrow());
+ if (o.is_some()) { $f(o.borrow()); }
}
@@ -648,7 +648,7 @@ Execute a closure on the value inside t
if it holds one.
Execute a closure on the mutable reference to the value inside t
if it holds one.
-public macro fun do_mut<$T>($o: &mut std::option::Option<$T>, $f: |&mut $T| -> ())
+public macro fun do_mut<$T, $R: drop>($o: &mut std::option::Option<$T>, $f: |&mut $T| -> $R)
@@ -657,9 +657,9 @@ Execute a closure on the mutable reference to the value inside t
if
Implementation
-public macro fun do_mut<$T>($o: &mut Option<$T>, $f: |&mut $T|) {
+public macro fun do_mut<$T, $R: drop>($o: &mut Option<$T>, $f: |&mut $T| -> $R) {
let o = $o;
- if (o.is_some()) $f(o.borrow_mut());
+ if (o.is_some()) { $f(o.borrow_mut()); }
}
diff --git a/crates/sui-framework/docs/std/u128.md b/crates/sui-framework/docs/std/u128.md
index f7f95c789ed37..8854ba3d517e3 100644
--- a/crates/sui-framework/docs/std/u128.md
+++ b/crates/sui-framework/docs/std/u128.md
@@ -387,7 +387,7 @@ Maximum value for a u128
Loops applying $f
to each number from $start
to $stop
(exclusive)
-public macro fun range_do($start: u128, $stop: u128, $f: |u128| -> ())
+public macro fun range_do<$R: drop>($start: u128, $stop: u128, $f: |u128| -> $R)
@@ -396,7 +396,7 @@ Loops applying $f
to each number from $start
to
Implementation
-public macro fun range_do($start: u128, $stop: u128, $f: |u128|) {
+public macro fun range_do<$R: drop>($start: u128, $stop: u128, $f: |u128| -> $R) {
std::macros::range_do!($start, $stop, $f)
}
@@ -412,7 +412,7 @@ Loops applying $f
to each number from $start
to
Loops applying $f
to each number from $start
to $stop
(inclusive)
-public macro fun range_do_eq($start: u128, $stop: u128, $f: |u128| -> ())
+public macro fun range_do_eq<$R: drop>($start: u128, $stop: u128, $f: |u128| -> $R)
@@ -421,7 +421,7 @@ Loops applying $f
to each number from $start
to
Implementation
-public macro fun range_do_eq($start: u128, $stop: u128, $f: |u128|) {
+public macro fun range_do_eq<$R: drop>($start: u128, $stop: u128, $f: |u128| -> $R) {
std::macros::range_do_eq!($start, $stop, $f)
}
@@ -437,7 +437,7 @@ Loops applying $f
to each number from $start
to
Loops applying $f
to each number from 0
to $stop
(exclusive)
-public macro fun do($stop: u128, $f: |u128| -> ())
+public macro fun do<$R: drop>($stop: u128, $f: |u128| -> $R)
@@ -446,7 +446,7 @@ Loops applying $f
to each number from 0
to $stop
Implementation
-public macro fun do($stop: u128, $f: |u128|) {
+public macro fun do<$R: drop>($stop: u128, $f: |u128| -> $R) {
std::macros::do!($stop, $f)
}
@@ -462,7 +462,7 @@ Loops applying $f
to each number from 0
to $stop
Loops applying $f
to each number from 0
to $stop
(inclusive)
-public macro fun do_eq($stop: u128, $f: |u128| -> ())
+public macro fun do_eq<$R: drop>($stop: u128, $f: |u128| -> $R)
@@ -471,7 +471,7 @@ Loops applying $f
to each number from 0
to $stop
Implementation
-public macro fun do_eq($stop: u128, $f: |u128|) {
+public macro fun do_eq<$R: drop>($stop: u128, $f: |u128| -> $R) {
std::macros::do_eq!($stop, $f)
}
diff --git a/crates/sui-framework/docs/std/u16.md b/crates/sui-framework/docs/std/u16.md
index 2207c8d27da8f..3e2009edb5427 100644
--- a/crates/sui-framework/docs/std/u16.md
+++ b/crates/sui-framework/docs/std/u16.md
@@ -309,7 +309,7 @@ Maximum value for a u16
Loops applying $f
to each number from $start
to $stop
(exclusive)
-public macro fun range_do($start: u16, $stop: u16, $f: |u16| -> ())
+public macro fun range_do<$R: drop>($start: u16, $stop: u16, $f: |u16| -> $R)
@@ -318,7 +318,7 @@ Loops applying $f
to each number from $start
to
Implementation
-public macro fun range_do($start: u16, $stop: u16, $f: |u16|) {
+public macro fun range_do<$R: drop>($start: u16, $stop: u16, $f: |u16| -> $R) {
std::macros::range_do!($start, $stop, $f)
}
@@ -334,7 +334,7 @@ Loops applying $f
to each number from $start
to
Loops applying $f
to each number from $start
to $stop
(inclusive)
-public macro fun range_do_eq($start: u16, $stop: u16, $f: |u16| -> ())
+public macro fun range_do_eq<$R: drop>($start: u16, $stop: u16, $f: |u16| -> $R)
@@ -343,7 +343,7 @@ Loops applying $f
to each number from $start
to
Implementation
-public macro fun range_do_eq($start: u16, $stop: u16, $f: |u16|) {
+public macro fun range_do_eq<$R: drop>($start: u16, $stop: u16, $f: |u16| -> $R) {
std::macros::range_do_eq!($start, $stop, $f)
}
@@ -359,7 +359,7 @@ Loops applying $f
to each number from $start
to
Loops applying $f
to each number from 0
to $stop
(exclusive)
-public macro fun do($stop: u16, $f: |u16| -> ())
+public macro fun do<$R: drop>($stop: u16, $f: |u16| -> $R)
@@ -368,7 +368,7 @@ Loops applying $f
to each number from 0
to $stop
Implementation
-public macro fun do($stop: u16, $f: |u16|) {
+public macro fun do<$R: drop>($stop: u16, $f: |u16| -> $R) {
std::macros::do!($stop, $f)
}
@@ -384,7 +384,7 @@ Loops applying $f
to each number from 0
to $stop
Loops applying $f
to each number from 0
to $stop
(inclusive)
-public macro fun do_eq($stop: u16, $f: |u16| -> ())
+public macro fun do_eq<$R: drop>($stop: u16, $f: |u16| -> $R)
@@ -393,7 +393,7 @@ Loops applying $f
to each number from 0
to $stop
Implementation
-public macro fun do_eq($stop: u16, $f: |u16|) {
+public macro fun do_eq<$R: drop>($stop: u16, $f: |u16| -> $R) {
std::macros::do_eq!($stop, $f)
}
diff --git a/crates/sui-framework/docs/std/u256.md b/crates/sui-framework/docs/std/u256.md
index 9cf3301b37fac..6675fd94a99f6 100644
--- a/crates/sui-framework/docs/std/u256.md
+++ b/crates/sui-framework/docs/std/u256.md
@@ -363,7 +363,7 @@ Maximum value for a u256
Loops applying $f
to each number from $start
to $stop
(exclusive)
-public macro fun range_do($start: u256, $stop: u256, $f: |u256| -> ())
+public macro fun range_do<$R: drop>($start: u256, $stop: u256, $f: |u256| -> $R)
@@ -372,7 +372,7 @@ Loops applying $f
to each number from $start
to
Implementation
-public macro fun range_do($start: u256, $stop: u256, $f: |u256|) {
+public macro fun range_do<$R: drop>($start: u256, $stop: u256, $f: |u256| -> $R) {
std::macros::range_do!($start, $stop, $f)
}
@@ -388,7 +388,7 @@ Loops applying $f
to each number from $start
to
Loops applying $f
to each number from $start
to $stop
(inclusive)
-public macro fun range_do_eq($start: u256, $stop: u256, $f: |u256| -> ())
+public macro fun range_do_eq<$R: drop>($start: u256, $stop: u256, $f: |u256| -> $R)
@@ -397,7 +397,7 @@ Loops applying $f
to each number from $start
to
Implementation
-public macro fun range_do_eq($start: u256, $stop: u256, $f: |u256|) {
+public macro fun range_do_eq<$R: drop>($start: u256, $stop: u256, $f: |u256| -> $R) {
std::macros::range_do_eq!($start, $stop, $f)
}
@@ -413,7 +413,7 @@ Loops applying $f
to each number from $start
to
Loops applying $f
to each number from 0
to $stop
(exclusive)
-public macro fun do($stop: u256, $f: |u256| -> ())
+public macro fun do<$R: drop>($stop: u256, $f: |u256| -> $R)
@@ -422,7 +422,7 @@ Loops applying $f
to each number from 0
to $stop
Implementation
-public macro fun do($stop: u256, $f: |u256|) {
+public macro fun do<$R: drop>($stop: u256, $f: |u256| -> $R) {
std::macros::do!($stop, $f)
}
@@ -438,7 +438,7 @@ Loops applying $f
to each number from 0
to $stop
Loops applying $f
to each number from 0
to $stop
(inclusive)
-public macro fun do_eq($stop: u256, $f: |u256| -> ())
+public macro fun do_eq<$R: drop>($stop: u256, $f: |u256| -> $R)
@@ -447,7 +447,7 @@ Loops applying $f
to each number from 0
to $stop
Implementation
-public macro fun do_eq($stop: u256, $f: |u256|) {
+public macro fun do_eq<$R: drop>($stop: u256, $f: |u256| -> $R) {
std::macros::do_eq!($stop, $f)
}
diff --git a/crates/sui-framework/docs/std/u32.md b/crates/sui-framework/docs/std/u32.md
index cd56956aa2701..d15330d1886c2 100644
--- a/crates/sui-framework/docs/std/u32.md
+++ b/crates/sui-framework/docs/std/u32.md
@@ -335,7 +335,7 @@ Maximum value for a u32
Loops applying $f
to each number from $start
to $stop
(exclusive)
-public macro fun range_do($start: u32, $stop: u32, $f: |u32| -> ())
+public macro fun range_do<$R: drop>($start: u32, $stop: u32, $f: |u32| -> $R)
@@ -344,7 +344,7 @@ Loops applying $f
to each number from $start
to
Implementation
-public macro fun range_do($start: u32, $stop: u32, $f: |u32|) {
+public macro fun range_do<$R: drop>($start: u32, $stop: u32, $f: |u32| -> $R) {
std::macros::range_do!($start, $stop, $f)
}
@@ -360,7 +360,7 @@ Loops applying $f
to each number from $start
to
Loops applying $f
to each number from $start
to $stop
(inclusive)
-public macro fun range_do_eq($start: u32, $stop: u32, $f: |u32| -> ())
+public macro fun range_do_eq<$R: drop>($start: u32, $stop: u32, $f: |u32| -> $R)
@@ -369,7 +369,7 @@ Loops applying $f
to each number from $start
to
Implementation
-public macro fun range_do_eq($start: u32, $stop: u32, $f: |u32|) {
+public macro fun range_do_eq<$R: drop>($start: u32, $stop: u32, $f: |u32| -> $R) {
std::macros::range_do_eq!($start, $stop, $f)
}
@@ -385,7 +385,7 @@ Loops applying $f
to each number from $start
to
Loops applying $f
to each number from 0
to $stop
(exclusive)
-public macro fun do($stop: u32, $f: |u32| -> ())
+public macro fun do<$R: drop>($stop: u32, $f: |u32| -> $R)
@@ -394,7 +394,7 @@ Loops applying $f
to each number from 0
to $stop
Implementation
-public macro fun do($stop: u32, $f: |u32|) {
+public macro fun do<$R: drop>($stop: u32, $f: |u32| -> $R) {
std::macros::do!($stop, $f)
}
@@ -410,7 +410,7 @@ Loops applying $f
to each number from 0
to $stop
Loops applying $f
to each number from 0
to $stop
(inclusive)
-public macro fun do_eq($stop: u32, $f: |u32| -> ())
+public macro fun do_eq<$R: drop>($stop: u32, $f: |u32| -> $R)
@@ -419,7 +419,7 @@ Loops applying $f
to each number from 0
to $stop
Implementation
-public macro fun do_eq($stop: u32, $f: |u32|) {
+public macro fun do_eq<$R: drop>($stop: u32, $f: |u32| -> $R) {
std::macros::do_eq!($stop, $f)
}
diff --git a/crates/sui-framework/docs/std/u64.md b/crates/sui-framework/docs/std/u64.md
index 64a029c908651..f9e391d109f64 100644
--- a/crates/sui-framework/docs/std/u64.md
+++ b/crates/sui-framework/docs/std/u64.md
@@ -361,7 +361,7 @@ Maximum value for a u64
Loops applying $f
to each number from $start
to $stop
(exclusive)
-public macro fun range_do($start: u64, $stop: u64, $f: |u64| -> ())
+public macro fun range_do<$R: drop>($start: u64, $stop: u64, $f: |u64| -> $R)
@@ -370,7 +370,7 @@ Loops applying $f
to each number from $start
to
Implementation
-public macro fun range_do($start: u64, $stop: u64, $f: |u64|) {
+public macro fun range_do<$R: drop>($start: u64, $stop: u64, $f: |u64| -> $R) {
std::macros::range_do!($start, $stop, $f)
}
@@ -386,7 +386,7 @@ Loops applying $f
to each number from $start
to
Loops applying $f
to each number from $start
to $stop
(inclusive)
-public macro fun range_do_eq($start: u64, $stop: u64, $f: |u64| -> ())
+public macro fun range_do_eq<$R: drop>($start: u64, $stop: u64, $f: |u64| -> $R)
@@ -395,7 +395,7 @@ Loops applying $f
to each number from $start
to
Implementation
-public macro fun range_do_eq($start: u64, $stop: u64, $f: |u64|) {
+public macro fun range_do_eq<$R: drop>($start: u64, $stop: u64, $f: |u64| -> $R) {
std::macros::range_do_eq!($start, $stop, $f)
}
@@ -411,7 +411,7 @@ Loops applying $f
to each number from $start
to
Loops applying $f
to each number from 0
to $stop
(exclusive)
-public macro fun do($stop: u64, $f: |u64| -> ())
+public macro fun do<$R: drop>($stop: u64, $f: |u64| -> $R)
@@ -420,7 +420,7 @@ Loops applying $f
to each number from 0
to $stop
Implementation
-public macro fun do($stop: u64, $f: |u64|) {
+public macro fun do<$R: drop>($stop: u64, $f: |u64| -> $R) {
std::macros::do!($stop, $f)
}
@@ -436,7 +436,7 @@ Loops applying $f
to each number from 0
to $stop
Loops applying $f
to each number from 0
to $stop
(inclusive)
-public macro fun do_eq($stop: u64, $f: |u64| -> ())
+public macro fun do_eq<$R: drop>($stop: u64, $f: |u64| -> $R)
@@ -445,7 +445,7 @@ Loops applying $f
to each number from 0
to $stop
Implementation
-public macro fun do_eq($stop: u64, $f: |u64|) {
+public macro fun do_eq<$R: drop>($stop: u64, $f: |u64| -> $R) {
std::macros::do_eq!($stop, $f)
}
diff --git a/crates/sui-framework/docs/std/u8.md b/crates/sui-framework/docs/std/u8.md
index e58a4ce503977..510a4518ecb04 100644
--- a/crates/sui-framework/docs/std/u8.md
+++ b/crates/sui-framework/docs/std/u8.md
@@ -283,7 +283,7 @@ Maximum value for a u8
Loops applying $f
to each number from $start
to $stop
(exclusive)
-public macro fun range_do($start: u8, $stop: u8, $f: |u8| -> ())
+public macro fun range_do<$R: drop>($start: u8, $stop: u8, $f: |u8| -> $R)
@@ -292,7 +292,7 @@ Loops applying $f
to each number from $start
to
Implementation
-public macro fun range_do($start: u8, $stop: u8, $f: |u8|) {
+public macro fun range_do<$R: drop>($start: u8, $stop: u8, $f: |u8| -> $R) {
std::macros::range_do!($start, $stop, $f)
}
@@ -308,7 +308,7 @@ Loops applying $f
to each number from $start
to
Loops applying $f
to each number from $start
to $stop
(inclusive)
-public macro fun range_do_eq($start: u8, $stop: u8, $f: |u8| -> ())
+public macro fun range_do_eq<$R: drop>($start: u8, $stop: u8, $f: |u8| -> $R)
@@ -317,7 +317,7 @@ Loops applying $f
to each number from $start
to
Implementation
-public macro fun range_do_eq($start: u8, $stop: u8, $f: |u8|) {
+public macro fun range_do_eq<$R: drop>($start: u8, $stop: u8, $f: |u8| -> $R) {
std::macros::range_do_eq!($start, $stop, $f)
}
@@ -333,7 +333,7 @@ Loops applying $f
to each number from $start
to
Loops applying $f
to each number from 0
to $stop
(exclusive)
-public macro fun do($stop: u8, $f: |u8| -> ())
+public macro fun do<$R: drop>($stop: u8, $f: |u8| -> $R)
@@ -342,7 +342,7 @@ Loops applying $f
to each number from 0
to $stop
Implementation
-public macro fun do($stop: u8, $f: |u8|) {
+public macro fun do<$R: drop>($stop: u8, $f: |u8| -> $R) {
std::macros::do!($stop, $f)
}
@@ -358,7 +358,7 @@ Loops applying $f
to each number from 0
to $stop
Loops applying $f
to each number from 0
to $stop
(inclusive)
-public macro fun do_eq($stop: u8, $f: |u8| -> ())
+public macro fun do_eq<$R: drop>($stop: u8, $f: |u8| -> $R)
@@ -367,7 +367,7 @@ Loops applying $f
to each number from 0
to $stop
Implementation
-public macro fun do_eq($stop: u8, $f: |u8|) {
+public macro fun do_eq<$R: drop>($stop: u8, $f: |u8| -> $R) {
std::macros::do_eq!($stop, $f)
}
diff --git a/crates/sui-framework/docs/std/vector.md b/crates/sui-framework/docs/std/vector.md
index 2ec6d3090d83d..3627e96ecde32 100644
--- a/crates/sui-framework/docs/std/vector.md
+++ b/crates/sui-framework/docs/std/vector.md
@@ -565,7 +565,7 @@ Destroy the vector v
by calling f
on each element and
Does not preserve the order of elements in the vector (starts from the end of the vector).
-public macro fun destroy<$T>($v: vector<$T>, $f: |$T| -> ())
+public macro fun destroy<$T, $R: drop>($v: vector<$T>, $f: |$T| -> $R)
@@ -574,9 +574,9 @@ Does not preserve the order of elements in the vector (starts from the end of th
Implementation
-public macro fun destroy<$T>($v: vector<$T>, $f: |$T|) {
+public macro fun destroy<$T, $R: drop>($v: vector<$T>, $f: |$T| -> $R) {
let mut v = $v;
- while (v.length() != 0) $f(v.pop_back());
+ v.length().do!(|_| $f(v.pop_back()));
v.destroy_empty();
}
@@ -593,7 +593,7 @@ Destroy the vector v
by calling f
on each element and
Preserves the order of elements in the vector.
-public macro fun do<$T>($v: vector<$T>, $f: |$T| -> ())
+public macro fun do<$T, $R: drop>($v: vector<$T>, $f: |$T| -> $R)
@@ -602,7 +602,7 @@ Preserves the order of elements in the vector.
Implementation
-public macro fun do<$T>($v: vector<$T>, $f: |$T|) {
+public macro fun do<$T, $R: drop>($v: vector<$T>, $f: |$T| -> $R) {
let mut v = $v;
v.reverse();
v.length().do!(|_| $f(v.pop_back()));
@@ -621,7 +621,7 @@ Preserves the order of elements in the vector.
Perform an action f
on each element of the vector v
. The vector is not modified.
-public macro fun do_ref<$T>($v: &vector<$T>, $f: |&$T| -> ())
+public macro fun do_ref<$T, $R: drop>($v: &vector<$T>, $f: |&$T| -> $R)
@@ -630,7 +630,7 @@ Perform an action f
on each element of the vector v
. T
Implementation
-public macro fun do_ref<$T>($v: &vector<$T>, $f: |&$T|) {
+public macro fun do_ref<$T, $R: drop>($v: &vector<$T>, $f: |&$T| -> $R) {
let v = $v;
v.length().do!(|i| $f(&v[i]))
}
@@ -648,7 +648,7 @@ Perform an action f
on each element of the vector v
.
The function f
takes a mutable reference to the element.
-public macro fun do_mut<$T>($v: &mut vector<$T>, $f: |&mut $T| -> ())
+public macro fun do_mut<$T, $R: drop>($v: &mut vector<$T>, $f: |&mut $T| -> $R)
@@ -657,7 +657,7 @@ The function f
takes a mutable reference to the element.
Implementation
-public macro fun do_mut<$T>($v: &mut vector<$T>, $f: |&mut $T|) {
+public macro fun do_mut<$T, $R: drop>($v: &mut vector<$T>, $f: |&mut $T| -> $R) {
let v = $v;
v.length().do!(|i| $f(&mut v[i]))
}
@@ -968,7 +968,7 @@ Aborts if the vectors are not of the same length.
The order of elements in the vectors is preserved.
-public macro fun zip_do<$T1, $T2>($v1: vector<$T1>, $v2: vector<$T2>, $f: |$T1, $T2| -> ())
+public macro fun zip_do<$T1, $T2, $R: drop>($v1: vector<$T1>, $v2: vector<$T2>, $f: |$T1, $T2| -> $R)
@@ -977,13 +977,18 @@ The order of elements in the vectors is preserved.
Implementation
-public macro fun zip_do<$T1, $T2>($v1: vector<$T1>, $v2: vector<$T2>, $f: |$T1, $T2|) {
+public macro fun zip_do<$T1, $T2, $R: drop>(
+ $v1: vector<$T1>,
+ $v2: vector<$T2>,
+ $f: |$T1, $T2| -> $R,
+) {
let v1 = $v1;
let mut v2 = $v2;
v2.reverse();
let len = v1.length();
assert!(len == v2.length());
v1.do!(|el1| $f(el1, v2.pop_back()));
+ v2.destroy_empty();
}
@@ -1000,7 +1005,7 @@ Aborts if the vectors are not of the same length.
Starts from the end of the vectors.
-public macro fun zip_do_reverse<$T1, $T2>($v1: vector<$T1>, $v2: vector<$T2>, $f: |$T1, $T2| -> ())
+public macro fun zip_do_reverse<$T1, $T2, $R: drop>($v1: vector<$T1>, $v2: vector<$T2>, $f: |$T1, $T2| -> $R)
@@ -1009,7 +1014,11 @@ Starts from the end of the vectors.
Implementation
-public macro fun zip_do_reverse<$T1, $T2>($v1: vector<$T1>, $v2: vector<$T2>, $f: |$T1, $T2|) {
+public macro fun zip_do_reverse<$T1, $T2, $R: drop>(
+ $v1: vector<$T1>,
+ $v2: vector<$T2>,
+ $f: |$T1, $T2| -> $R,
+) {
let v1 = $v1;
let mut v2 = $v2;
let len = v1.length();
@@ -1032,7 +1041,7 @@ Aborts if the vectors are not of the same length.
The order of elements in the vectors is preserved.
-public macro fun zip_do_ref<$T1, $T2>($v1: &vector<$T1>, $v2: &vector<$T2>, $f: |&$T1, &$T2| -> ())
+public macro fun zip_do_ref<$T1, $T2, $R: drop>($v1: &vector<$T1>, $v2: &vector<$T2>, $f: |&$T1, &$T2| -> $R)
@@ -1041,7 +1050,11 @@ The order of elements in the vectors is preserved.
Implementation
-public macro fun zip_do_ref<$T1, $T2>($v1: &vector<$T1>, $v2: &vector<$T2>, $f: |&$T1, &$T2|) {
+public macro fun zip_do_ref<$T1, $T2, $R: drop>(
+ $v1: &vector<$T1>,
+ $v2: &vector<$T2>,
+ $f: |&$T1, &$T2| -> $R,
+) {
let v1 = $v1;
let v2 = $v2;
let len = v1.length();
@@ -1064,7 +1077,7 @@ Aborts if the vectors are not of the same length.
The order of elements in the vectors is preserved.
-public macro fun zip_do_mut<$T1, $T2>($v1: &mut vector<$T1>, $v2: &mut vector<$T2>, $f: |&mut $T1, &mut $T2| -> ())
+public macro fun zip_do_mut<$T1, $T2, $R: drop>($v1: &mut vector<$T1>, $v2: &mut vector<$T2>, $f: |&mut $T1, &mut $T2| -> $R)
@@ -1073,10 +1086,10 @@ The order of elements in the vectors is preserved.
Implementation
-public macro fun zip_do_mut<$T1, $T2>(
+public macro fun zip_do_mut<$T1, $T2, $R: drop>(
$v1: &mut vector<$T1>,
$v2: &mut vector<$T2>,
- $f: |&mut $T1, &mut $T2|,
+ $f: |&mut $T1, &mut $T2| -> $R,
) {
let v1 = $v1;
let v2 = $v2;