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

[move-2024] Method syntax for move-stdlib #16466

Merged
merged 10 commits into from
Mar 21, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
21 changes: 9 additions & 12 deletions crates/sui-framework/docs/move-stdlib/ascii.md
Original file line number Diff line number Diff line change
Expand Up @@ -149,11 +149,8 @@ Convert a vector of bytes <code>bytes</code> into an <code><a href="../move-stdl

<pre><code><b>public</b> <b>fun</b> <a href="../move-stdlib/string.md#0x1_string">string</a>(bytes: <a href="../move-stdlib/vector.md#0x1_vector">vector</a>&lt;u8&gt;): <a href="../move-stdlib/ascii.md#0x1_ascii_String">String</a> {
<b>let</b> x = <a href="../move-stdlib/ascii.md#0x1_ascii_try_string">try_string</a>(bytes);
<b>assert</b>!(
<a href="../move-stdlib/option.md#0x1_option_is_some">option::is_some</a>(&x),
<a href="../move-stdlib/ascii.md#0x1_ascii_EINVALID_ASCII_CHARACTER">EINVALID_ASCII_CHARACTER</a>
);
<a href="../move-stdlib/option.md#0x1_option_destroy_some">option::destroy_some</a>(x)
<b>assert</b>!(x.is_some(), <a href="../move-stdlib/ascii.md#0x1_ascii_EINVALID_ASCII_CHARACTER">EINVALID_ASCII_CHARACTER</a>);
x.destroy_some()
}
</code></pre>

Expand All @@ -180,10 +177,10 @@ characters. Otherwise returns <code>None</code>.


<pre><code><b>public</b> <b>fun</b> <a href="../move-stdlib/ascii.md#0x1_ascii_try_string">try_string</a>(bytes: <a href="../move-stdlib/vector.md#0x1_vector">vector</a>&lt;u8&gt;): Option&lt;<a href="../move-stdlib/ascii.md#0x1_ascii_String">String</a>&gt; {
<b>let</b> len = <a href="../move-stdlib/vector.md#0x1_vector_length">vector::length</a>(&bytes);
<b>let</b> len = bytes.<a href="../move-stdlib/ascii.md#0x1_ascii_length">length</a>();
<b>let</b> <b>mut</b> i = 0;
<b>while</b> (i &lt; len) {
<b>let</b> possible_byte = *<a href="../move-stdlib/vector.md#0x1_vector_borrow">vector::borrow</a>(&bytes, i);
<b>let</b> possible_byte = bytes[i];
<b>if</b> (!<a href="../move-stdlib/ascii.md#0x1_ascii_is_valid_char">is_valid_char</a>(possible_byte)) <b>return</b> <a href="../move-stdlib/option.md#0x1_option_none">option::none</a>();
i = i + 1;
};
Expand Down Expand Up @@ -213,10 +210,10 @@ Returns <code><b>false</b></code> otherwise. Not all <code><a href="../move-stdl


<pre><code><b>public</b> <b>fun</b> <a href="../move-stdlib/ascii.md#0x1_ascii_all_characters_printable">all_characters_printable</a>(<a href="../move-stdlib/string.md#0x1_string">string</a>: &<a href="../move-stdlib/ascii.md#0x1_ascii_String">String</a>): bool {
<b>let</b> len = <a href="../move-stdlib/vector.md#0x1_vector_length">vector::length</a>(&<a href="../move-stdlib/string.md#0x1_string">string</a>.bytes);
<b>let</b> len = <a href="../move-stdlib/string.md#0x1_string">string</a>.bytes.<a href="../move-stdlib/ascii.md#0x1_ascii_length">length</a>();
<b>let</b> <b>mut</b> i = 0;
<b>while</b> (i &lt; len) {
<b>let</b> byte = *<a href="../move-stdlib/vector.md#0x1_vector_borrow">vector::borrow</a>(&<a href="../move-stdlib/string.md#0x1_string">string</a>.bytes, i);
<b>let</b> byte = <a href="../move-stdlib/string.md#0x1_string">string</a>.bytes[i];
<b>if</b> (!<a href="../move-stdlib/ascii.md#0x1_ascii_is_printable_char">is_printable_char</a>(byte)) <b>return</b> <b>false</b>;
i = i + 1;
};
Expand Down Expand Up @@ -244,7 +241,7 @@ Returns <code><b>false</b></code> otherwise. Not all <code><a href="../move-stdl


<pre><code><b>public</b> <b>fun</b> <a href="../move-stdlib/ascii.md#0x1_ascii_push_char">push_char</a>(<a href="../move-stdlib/string.md#0x1_string">string</a>: &<b>mut</b> <a href="../move-stdlib/ascii.md#0x1_ascii_String">String</a>, char: <a href="../move-stdlib/ascii.md#0x1_ascii_Char">Char</a>) {
<a href="../move-stdlib/vector.md#0x1_vector_push_back">vector::push_back</a>(&<b>mut</b> <a href="../move-stdlib/string.md#0x1_string">string</a>.bytes, char.byte);
<a href="../move-stdlib/string.md#0x1_string">string</a>.bytes.push_back(char.byte);
}
</code></pre>

Expand All @@ -268,7 +265,7 @@ Returns <code><b>false</b></code> otherwise. Not all <code><a href="../move-stdl


<pre><code><b>public</b> <b>fun</b> <a href="../move-stdlib/ascii.md#0x1_ascii_pop_char">pop_char</a>(<a href="../move-stdlib/string.md#0x1_string">string</a>: &<b>mut</b> <a href="../move-stdlib/ascii.md#0x1_ascii_String">String</a>): <a href="../move-stdlib/ascii.md#0x1_ascii_Char">Char</a> {
<a href="../move-stdlib/ascii.md#0x1_ascii_Char">Char</a> { byte: <a href="../move-stdlib/vector.md#0x1_vector_pop_back">vector::pop_back</a>(&<b>mut</b> <a href="../move-stdlib/string.md#0x1_string">string</a>.bytes) }
<a href="../move-stdlib/ascii.md#0x1_ascii_Char">Char</a> { byte: <a href="../move-stdlib/string.md#0x1_string">string</a>.bytes.pop_back() }
}
</code></pre>

Expand All @@ -292,7 +289,7 @@ Returns <code><b>false</b></code> otherwise. Not all <code><a href="../move-stdl


<pre><code><b>public</b> <b>fun</b> <a href="../move-stdlib/ascii.md#0x1_ascii_length">length</a>(<a href="../move-stdlib/string.md#0x1_string">string</a>: &<a href="../move-stdlib/ascii.md#0x1_ascii_String">String</a>): u64 {
<a href="../move-stdlib/vector.md#0x1_vector_length">vector::length</a>(<a href="../move-stdlib/ascii.md#0x1_ascii_as_bytes">as_bytes</a>(<a href="../move-stdlib/string.md#0x1_string">string</a>))
<a href="../move-stdlib/string.md#0x1_string">string</a>.<a href="../move-stdlib/ascii.md#0x1_ascii_as_bytes">as_bytes</a>().<a href="../move-stdlib/ascii.md#0x1_ascii_length">length</a>()
}
</code></pre>

Expand Down
54 changes: 27 additions & 27 deletions crates/sui-framework/docs/move-stdlib/option.md
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ Return true if <code>t</code> does not hold a value


<pre><code><b>public</b> <b>fun</b> <a href="../move-stdlib/option.md#0x1_option_is_none">is_none</a>&lt;Element&gt;(t: &<a href="../move-stdlib/option.md#0x1_option_Option">Option</a>&lt;Element&gt;): bool {
<a href="../move-stdlib/vector.md#0x1_vector_is_empty">vector::is_empty</a>(&t.vec)
t.vec.is_empty()
}
</code></pre>

Expand All @@ -180,7 +180,7 @@ Return true if <code>t</code> holds a value


<pre><code><b>public</b> <b>fun</b> <a href="../move-stdlib/option.md#0x1_option_is_some">is_some</a>&lt;Element&gt;(t: &<a href="../move-stdlib/option.md#0x1_option_Option">Option</a>&lt;Element&gt;): bool {
!<a href="../move-stdlib/vector.md#0x1_vector_is_empty">vector::is_empty</a>(&t.vec)
!t.vec.is_empty()
}
</code></pre>

Expand All @@ -206,7 +206,7 @@ Always returns <code><b>false</b></code> if <code>t</code> does not hold a value


<pre><code><b>public</b> <b>fun</b> <a href="../move-stdlib/option.md#0x1_option_contains">contains</a>&lt;Element&gt;(t: &<a href="../move-stdlib/option.md#0x1_option_Option">Option</a>&lt;Element&gt;, e_ref: &Element): bool {
<a href="../move-stdlib/vector.md#0x1_vector_contains">vector::contains</a>(&t.vec, e_ref)
t.vec.<a href="../move-stdlib/option.md#0x1_option_contains">contains</a>(e_ref)
}
</code></pre>

Expand All @@ -232,8 +232,8 @@ Aborts if <code>t</code> does not hold a value


<pre><code><b>public</b> <b>fun</b> <a href="../move-stdlib/option.md#0x1_option_borrow">borrow</a>&lt;Element&gt;(t: &<a href="../move-stdlib/option.md#0x1_option_Option">Option</a>&lt;Element&gt;): &Element {
<b>assert</b>!(<a href="../move-stdlib/option.md#0x1_option_is_some">is_some</a>(t), <a href="../move-stdlib/option.md#0x1_option_EOPTION_NOT_SET">EOPTION_NOT_SET</a>);
<a href="../move-stdlib/vector.md#0x1_vector_borrow">vector::borrow</a>(&t.vec, 0)
<b>assert</b>!(t.<a href="../move-stdlib/option.md#0x1_option_is_some">is_some</a>(), <a href="../move-stdlib/option.md#0x1_option_EOPTION_NOT_SET">EOPTION_NOT_SET</a>);
&t.vec[0]
}
</code></pre>

Expand All @@ -260,8 +260,8 @@ Return <code>default_ref</code> if <code>t</code> does not hold a value

<pre><code><b>public</b> <b>fun</b> <a href="../move-stdlib/option.md#0x1_option_borrow_with_default">borrow_with_default</a>&lt;Element&gt;(t: &<a href="../move-stdlib/option.md#0x1_option_Option">Option</a>&lt;Element&gt;, default_ref: &Element): &Element {
<b>let</b> vec_ref = &t.vec;
<b>if</b> (<a href="../move-stdlib/vector.md#0x1_vector_is_empty">vector::is_empty</a>(vec_ref)) default_ref
<b>else</b> <a href="../move-stdlib/vector.md#0x1_vector_borrow">vector::borrow</a>(vec_ref, 0)
<b>if</b> (vec_ref.is_empty()) default_ref
<b>else</b> &vec_ref[0]
}
</code></pre>

Expand Down Expand Up @@ -291,8 +291,8 @@ Return <code>default</code> if <code>t</code> does not hold a value
default: Element,
): Element {
<b>let</b> vec_ref = &t.vec;
<b>if</b> (<a href="../move-stdlib/vector.md#0x1_vector_is_empty">vector::is_empty</a>(vec_ref)) default
<b>else</b> *<a href="../move-stdlib/vector.md#0x1_vector_borrow">vector::borrow</a>(vec_ref, 0)
<b>if</b> (vec_ref.is_empty()) default
<b>else</b> vec_ref[0]
}
</code></pre>

Expand All @@ -319,7 +319,7 @@ Aborts if <code>t</code> already holds a value

<pre><code><b>public</b> <b>fun</b> <a href="../move-stdlib/option.md#0x1_option_fill">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) {
<b>let</b> vec_ref = &<b>mut</b> t.vec;
<b>if</b> (<a href="../move-stdlib/vector.md#0x1_vector_is_empty">vector::is_empty</a>(vec_ref)) <a href="../move-stdlib/vector.md#0x1_vector_push_back">vector::push_back</a>(vec_ref, e)
<b>if</b> (vec_ref.is_empty()) vec_ref.push_back(e)
<b>else</b> <b>abort</b> <a href="../move-stdlib/option.md#0x1_option_EOPTION_IS_SET">EOPTION_IS_SET</a>
}
</code></pre>
Expand All @@ -346,8 +346,8 @@ Aborts if <code>t</code> does not hold a value


<pre><code><b>public</b> <b>fun</b> <a href="../move-stdlib/option.md#0x1_option_extract">extract</a>&lt;Element&gt;(t: &<b>mut</b> <a href="../move-stdlib/option.md#0x1_option_Option">Option</a>&lt;Element&gt;): Element {
<b>assert</b>!(<a href="../move-stdlib/option.md#0x1_option_is_some">is_some</a>(t), <a href="../move-stdlib/option.md#0x1_option_EOPTION_NOT_SET">EOPTION_NOT_SET</a>);
<a href="../move-stdlib/vector.md#0x1_vector_pop_back">vector::pop_back</a>(&<b>mut</b> t.vec)
<b>assert</b>!(t.<a href="../move-stdlib/option.md#0x1_option_is_some">is_some</a>(), <a href="../move-stdlib/option.md#0x1_option_EOPTION_NOT_SET">EOPTION_NOT_SET</a>);
t.vec.pop_back()
}
</code></pre>

Expand All @@ -373,8 +373,8 @@ Aborts if <code>t</code> does not hold a value


<pre><code><b>public</b> <b>fun</b> <a href="../move-stdlib/option.md#0x1_option_borrow_mut">borrow_mut</a>&lt;Element&gt;(t: &<b>mut</b> <a href="../move-stdlib/option.md#0x1_option_Option">Option</a>&lt;Element&gt;): &<b>mut</b> Element {
<b>assert</b>!(<a href="../move-stdlib/option.md#0x1_option_is_some">is_some</a>(t), <a href="../move-stdlib/option.md#0x1_option_EOPTION_NOT_SET">EOPTION_NOT_SET</a>);
<a href="../move-stdlib/vector.md#0x1_vector_borrow_mut">vector::borrow_mut</a>(&<b>mut</b> t.vec, 0)
<b>assert</b>!(t.<a href="../move-stdlib/option.md#0x1_option_is_some">is_some</a>(), <a href="../move-stdlib/option.md#0x1_option_EOPTION_NOT_SET">EOPTION_NOT_SET</a>);
&<b>mut</b> t.vec[0]
}
</code></pre>

Expand All @@ -400,10 +400,10 @@ Aborts if <code>t</code> does not hold a value


<pre><code><b>public</b> <b>fun</b> <a href="../move-stdlib/option.md#0x1_option_swap">swap</a>&lt;Element&gt;(t: &<b>mut</b> <a href="../move-stdlib/option.md#0x1_option_Option">Option</a>&lt;Element&gt;, e: Element): Element {
<b>assert</b>!(<a href="../move-stdlib/option.md#0x1_option_is_some">is_some</a>(t), <a href="../move-stdlib/option.md#0x1_option_EOPTION_NOT_SET">EOPTION_NOT_SET</a>);
<b>assert</b>!(t.<a href="../move-stdlib/option.md#0x1_option_is_some">is_some</a>(), <a href="../move-stdlib/option.md#0x1_option_EOPTION_NOT_SET">EOPTION_NOT_SET</a>);
<b>let</b> vec_ref = &<b>mut</b> t.vec;
<b>let</b> old_value = <a href="../move-stdlib/vector.md#0x1_vector_pop_back">vector::pop_back</a>(vec_ref);
<a href="../move-stdlib/vector.md#0x1_vector_push_back">vector::push_back</a>(vec_ref, e);
<b>let</b> old_value = vec_ref.pop_back();
vec_ref.push_back(e);
old_value
}
</code></pre>
Expand Down Expand Up @@ -432,9 +432,9 @@ 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> (<a href="../move-stdlib/vector.md#0x1_vector_is_empty">vector::is_empty</a>(vec_ref)) <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>(<a href="../move-stdlib/vector.md#0x1_vector_pop_back">vector::pop_back</a>(vec_ref));
<a href="../move-stdlib/vector.md#0x1_vector_push_back">vector::push_back</a>(vec_ref, e);
<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());
vec_ref.push_back(e);
old_value
}
</code></pre>
Expand All @@ -461,8 +461,8 @@ Destroys <code>t.</code> If <code>t</code> holds a value, return it. Returns <co

<pre><code><b>public</b> <b>fun</b> <a href="../move-stdlib/option.md#0x1_option_destroy_with_default">destroy_with_default</a>&lt;Element: drop&gt;(t: <a href="../move-stdlib/option.md#0x1_option_Option">Option</a>&lt;Element&gt;, default: Element): Element {
<b>let</b> <a href="../move-stdlib/option.md#0x1_option_Option">Option</a> { <b>mut</b> vec } = t;
<b>if</b> (<a href="../move-stdlib/vector.md#0x1_vector_is_empty">vector::is_empty</a>(&vec)) default
<b>else</b> <a href="../move-stdlib/vector.md#0x1_vector_pop_back">vector::pop_back</a>(&<b>mut</b> vec)
<b>if</b> (vec.is_empty()) default
<b>else</b> vec.pop_back()
}
</code></pre>

Expand All @@ -488,10 +488,10 @@ Aborts if <code>t</code> does not hold a value


<pre><code><b>public</b> <b>fun</b> <a href="../move-stdlib/option.md#0x1_option_destroy_some">destroy_some</a>&lt;Element&gt;(t: <a href="../move-stdlib/option.md#0x1_option_Option">Option</a>&lt;Element&gt;): Element {
<b>assert</b>!(<a href="../move-stdlib/option.md#0x1_option_is_some">is_some</a>(&t), <a href="../move-stdlib/option.md#0x1_option_EOPTION_NOT_SET">EOPTION_NOT_SET</a>);
<b>assert</b>!(t.<a href="../move-stdlib/option.md#0x1_option_is_some">is_some</a>(), <a href="../move-stdlib/option.md#0x1_option_EOPTION_NOT_SET">EOPTION_NOT_SET</a>);
<b>let</b> <a href="../move-stdlib/option.md#0x1_option_Option">Option</a> { <b>mut</b> vec } = t;
<b>let</b> elem = <a href="../move-stdlib/vector.md#0x1_vector_pop_back">vector::pop_back</a>(&<b>mut</b> vec);
<a href="../move-stdlib/vector.md#0x1_vector_destroy_empty">vector::destroy_empty</a>(vec);
<b>let</b> elem = vec.pop_back();
vec.destroy_empty();
elem
}
</code></pre>
Expand All @@ -518,9 +518,9 @@ Aborts if <code>t</code> holds a value


<pre><code><b>public</b> <b>fun</b> <a href="../move-stdlib/option.md#0x1_option_destroy_none">destroy_none</a>&lt;Element&gt;(t: <a href="../move-stdlib/option.md#0x1_option_Option">Option</a>&lt;Element&gt;) {
<b>assert</b>!(<a href="../move-stdlib/option.md#0x1_option_is_none">is_none</a>(&t), <a href="../move-stdlib/option.md#0x1_option_EOPTION_IS_SET">EOPTION_IS_SET</a>);
<b>assert</b>!(t.<a href="../move-stdlib/option.md#0x1_option_is_none">is_none</a>(), <a href="../move-stdlib/option.md#0x1_option_EOPTION_IS_SET">EOPTION_IS_SET</a>);
<b>let</b> <a href="../move-stdlib/option.md#0x1_option_Option">Option</a> { vec } = t;
<a href="../move-stdlib/vector.md#0x1_vector_destroy_empty">vector::destroy_empty</a>(vec)
vec.destroy_empty()
}
</code></pre>

Expand Down
Loading
Loading