Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[stdlib] Formats MoveStdlib package 1/N #19461

Merged
merged 4 commits into from
Sep 20, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
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
2 changes: 1 addition & 1 deletion crates/sui-framework/docs/move-stdlib/ascii.md
Original file line number Diff line number Diff line change
Expand Up @@ -508,7 +508,7 @@ Returns <code><b>false</b></code> otherwise.

<pre><code><b>public</b> <b>fun</b> <a href="../move-stdlib/ascii.md#0x1_ascii_is_printable_char">is_printable_char</a>(byte: u8): bool {
byte &gt;= 0x20 && // Disallow metacharacters
<a href="../move-stdlib/ascii.md#0x1_ascii_byte">byte</a> &lt;= 0x7E // Don't allow DEL metacharacter
<a href="../move-stdlib/ascii.md#0x1_ascii_byte">byte</a> &lt;= 0x7E // Don't allow DEL metacharacter
}
</code></pre>

Expand Down
2 changes: 1 addition & 1 deletion crates/sui-framework/docs/move-stdlib/bcs.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ Return the binary representation of <code>v</code> in BCS (Binary Canonical Seri
<summary>Implementation</summary>


<pre><code><b>native</b> <b>public</b> <b>fun</b> <a href="../move-stdlib/bcs.md#0x1_bcs_to_bytes">to_bytes</a>&lt;MoveValue&gt;(v: &MoveValue): <a href="../move-stdlib/vector.md#0x1_vector">vector</a>&lt;u8&gt;;
<pre><code><b>public</b> <b>native</b> <b>fun</b> <a href="../move-stdlib/bcs.md#0x1_bcs_to_bytes">to_bytes</a>&lt;MoveValue&gt;(v: &MoveValue): <a href="../move-stdlib/vector.md#0x1_vector">vector</a>&lt;u8&gt;;
</code></pre>


Expand Down
7 changes: 2 additions & 5 deletions crates/sui-framework/docs/move-stdlib/option.md
Original file line number Diff line number Diff line change
Expand Up @@ -285,10 +285,7 @@ Return <code>default</code> if <code>t</code> does not hold a value
<summary>Implementation</summary>


<pre><code><b>public</b> <b>fun</b> <a href="../move-stdlib/option.md#0x1_option_get_with_default">get_with_default</a>&lt;Element: <b>copy</b> + drop&gt;(
t: &<a href="../move-stdlib/option.md#0x1_option_Option">Option</a>&lt;Element&gt;,
default: Element,
): Element {
<pre><code><b>public</b> <b>fun</b> <a href="../move-stdlib/option.md#0x1_option_get_with_default">get_with_default</a>&lt;Element: <b>copy</b> + drop&gt;(t: &<a href="../move-stdlib/option.md#0x1_option_Option">Option</a>&lt;Element&gt;, default: Element): Element {
<b>let</b> vec_ref = &t.vec;
<b>if</b> (vec_ref.is_empty()) default
<b>else</b> vec_ref[0]
Expand Down Expand Up @@ -432,7 +429,7 @@ Different from swap(), swap_or_fill() allows for <code>t</code> not holding a va
<pre><code><b>public</b> <b>fun</b> <a href="../move-stdlib/option.md#0x1_option_swap_or_fill">swap_or_fill</a>&lt;Element&gt;(t: &<b>mut</b> <a href="../move-stdlib/option.md#0x1_option_Option">Option</a>&lt;Element&gt;, e: Element): <a href="../move-stdlib/option.md#0x1_option_Option">Option</a>&lt;Element&gt; {
<b>let</b> vec_ref = &<b>mut</b> t.vec;
<b>let</b> old_value = <b>if</b> (vec_ref.is_empty()) <a href="../move-stdlib/option.md#0x1_option_none">none</a>()
<b>else</b> <a href="../move-stdlib/option.md#0x1_option_some">some</a>(vec_ref.pop_back());
<b>else</b> <a href="../move-stdlib/option.md#0x1_option_some">some</a>(vec_ref.pop_back());
vec_ref.push_back(e);
old_value
}
Expand Down
11 changes: 4 additions & 7 deletions crates/sui-framework/docs/move-stdlib/string.md
Original file line number Diff line number Diff line change
Expand Up @@ -365,10 +365,7 @@ must be at a valid utf8 char boundary.

<pre><code><b>public</b> <b>fun</b> <a href="../move-stdlib/string.md#0x1_string_insert">insert</a>(s: &<b>mut</b> <a href="../move-stdlib/string.md#0x1_string_String">String</a>, at: <a href="../move-stdlib/u64.md#0x1_u64">u64</a>, o: <a href="../move-stdlib/string.md#0x1_string_String">String</a>) {
<b>let</b> bytes = &s.bytes;
<b>assert</b>!(
at &lt;= bytes.<a href="../move-stdlib/string.md#0x1_string_length">length</a>() && <a href="../move-stdlib/string.md#0x1_string_internal_is_char_boundary">internal_is_char_boundary</a>(bytes, at),
<a href="../move-stdlib/string.md#0x1_string_EInvalidIndex">EInvalidIndex</a>,
);
<b>assert</b>!(at &lt;= bytes.<a href="../move-stdlib/string.md#0x1_string_length">length</a>() && <a href="../move-stdlib/string.md#0x1_string_internal_is_char_boundary">internal_is_char_boundary</a>(bytes, at), <a href="../move-stdlib/string.md#0x1_string_EInvalidIndex">EInvalidIndex</a>);
<b>let</b> l = s.<a href="../move-stdlib/string.md#0x1_string_length">length</a>();
<b>let</b> <b>mut</b> front = s.<a href="../move-stdlib/string.md#0x1_string_substring">substring</a>(0, at);
<b>let</b> end = s.<a href="../move-stdlib/string.md#0x1_string_substring">substring</a>(at, l);
Expand Down Expand Up @@ -406,9 +403,9 @@ guaranteeing that the result is valid utf8.
<b>let</b> l = bytes.<a href="../move-stdlib/string.md#0x1_string_length">length</a>();
<b>assert</b>!(
j &lt;= l &&
i &lt;= j &&
<a href="../move-stdlib/string.md#0x1_string_internal_is_char_boundary">internal_is_char_boundary</a>(bytes, i) &&
<a href="../move-stdlib/string.md#0x1_string_internal_is_char_boundary">internal_is_char_boundary</a>(bytes, j),
i &lt;= j &&
<a href="../move-stdlib/string.md#0x1_string_internal_is_char_boundary">internal_is_char_boundary</a>(bytes, i) &&
<a href="../move-stdlib/string.md#0x1_string_internal_is_char_boundary">internal_is_char_boundary</a>(bytes, j),
<a href="../move-stdlib/string.md#0x1_string_EInvalidIndex">EInvalidIndex</a>,
);
<a href="../move-stdlib/string.md#0x1_string_String">String</a> { bytes: <a href="../move-stdlib/string.md#0x1_string_internal_sub_string">internal_sub_string</a>(bytes, i, j) }
Expand Down
32 changes: 16 additions & 16 deletions crates/sui-framework/docs/move-stdlib/type_name.md
Original file line number Diff line number Diff line change
Expand Up @@ -213,22 +213,22 @@ u8, u16, u32, u64, u128, u256, bool, address, vector.
<pre><code><b>public</b> <b>fun</b> <a href="../move-stdlib/type_name.md#0x1_type_name_is_primitive">is_primitive</a>(self: &<a href="../move-stdlib/type_name.md#0x1_type_name_TypeName">TypeName</a>): bool {
<b>let</b> bytes = self.name.as_bytes();
bytes == &b"bool" ||
bytes == &b"u8" ||
bytes == &b"u16" ||
bytes == &b"u32" ||
bytes == &b"<a href="../move-stdlib/u64.md#0x1_u64">u64</a>" ||
bytes == &b"u128" ||
bytes == &b"u256" ||
bytes == &b"<b>address</b>" ||
(
bytes.length() &gt;= 6 &&
bytes[0] == <a href="../move-stdlib/type_name.md#0x1_type_name_ASCII_V">ASCII_V</a> &&
bytes[1] == <a href="../move-stdlib/type_name.md#0x1_type_name_ASCII_E">ASCII_E</a> &&
bytes[2] == <a href="../move-stdlib/type_name.md#0x1_type_name_ASCII_C">ASCII_C</a> &&
bytes[3] == <a href="../move-stdlib/type_name.md#0x1_type_name_ASCII_T">ASCII_T</a> &&
bytes[4] == <a href="../move-stdlib/type_name.md#0x1_type_name_ASCII_O">ASCII_O</a> &&
bytes[5] == <a href="../move-stdlib/type_name.md#0x1_type_name_ASCII_R">ASCII_R</a>,
)
bytes == &b"u8" ||
bytes == &b"u16" ||
bytes == &b"u32" ||
bytes == &b"<a href="../move-stdlib/u64.md#0x1_u64">u64</a>" ||
bytes == &b"u128" ||
bytes == &b"u256" ||
bytes == &b"<b>address</b>" ||
(
bytes.length() &gt;= 6 &&
bytes[0] == <a href="../move-stdlib/type_name.md#0x1_type_name_ASCII_V">ASCII_V</a> &&
bytes[1] == <a href="../move-stdlib/type_name.md#0x1_type_name_ASCII_E">ASCII_E</a> &&
bytes[2] == <a href="../move-stdlib/type_name.md#0x1_type_name_ASCII_C">ASCII_C</a> &&
bytes[3] == <a href="../move-stdlib/type_name.md#0x1_type_name_ASCII_T">ASCII_T</a> &&
bytes[4] == <a href="../move-stdlib/type_name.md#0x1_type_name_ASCII_O">ASCII_O</a> &&
bytes[5] == <a href="../move-stdlib/type_name.md#0x1_type_name_ASCII_R">ASCII_R</a>,
)
}
</code></pre>

Expand Down
5 changes: 4 additions & 1 deletion crates/sui-framework/docs/move-stdlib/vector.md
Original file line number Diff line number Diff line change
Expand Up @@ -436,7 +436,10 @@ Aborts if <code>i</code> is out of bounds.
<b>if</b> (i &gt;= len) <b>abort</b> <a href="../move-stdlib/vector.md#0x1_vector_EINDEX_OUT_OF_BOUNDS">EINDEX_OUT_OF_BOUNDS</a>;

len = len - 1;
<b>while</b> (i &lt; len) v.<a href="../move-stdlib/vector.md#0x1_vector_swap">swap</a>(i, { i = i + 1; i });
<b>while</b> (i &lt; len) v.<a href="../move-stdlib/vector.md#0x1_vector_swap">swap</a>(i, {
i = i + 1;
i
});
v.<a href="../move-stdlib/vector.md#0x1_vector_pop_back">pop_back</a>()
}
</code></pre>
Expand Down
12 changes: 6 additions & 6 deletions crates/sui-framework/packages/move-stdlib/sources/address.move
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@

/// Provides a way to get address length since it's a
/// platform-specific parameter.
module std::address {
/// Should be converted to a native function.
/// Current implementation only works for Sui.
public fun length(): u64 {
32
}
module std::address;

/// Should be converted to a native function.
/// Current implementation only works for Sui.
public fun length(): u64 {
32
}
Loading
Loading