Skip to content

Commit aba5ea5

Browse files
committed
fix: rework example to be more in line with FLS style
1 parent 900088b commit aba5ea5

File tree

1 file changed

+19
-30
lines changed

1 file changed

+19
-30
lines changed

src/ownership-and-deconstruction.rst

Lines changed: 19 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -754,37 +754,26 @@ proceeds as follows:
754754
let c = PrintOnDrop("2");
755755
756756
:dp:`fls_THzA0QFdMMJB`
757-
When an :t:`or pattern` is used, the drop order of :t:`[Binding]s` is
758-
determined by the first :t:`pattern-without-alternation`, regardless of which
759-
alternative matches at runtime.
757+
When an :t:`or pattern` is used, the drop order of :t:`[binding]s` is determined by the first :t:`pattern-without-alternation`, regardless of which matches at runtime.
758+
759+
:dp:`fls_dhfIPP4yR3Tt`
760+
In the following example, the drop order is ``b``, ``a`` for both calls.
761+
Dropping proceeds as follows:
762+
763+
#. :dp:`fls_zxFM7EoE2Xq8`
764+
The first :t:`pattern-without-alternation` ``Ok([a, b])`` declares ``a`` before ``b``.
765+
766+
#. :dp:`fls_zxFM7EoE2Xq8`
767+
When the first call matches ``Ok([a, b])``, the :t:`[binding]s` are dropped in reverse declaration order: ``b`` then ``a``.
768+
769+
#. :dp:`fls_gNWXh61ZXXt8`
770+
When the second call matches ``Err([b, a])``, the drop order remains ``b`` then ``a``, determined by the first :t:`pattern-without-alternation`.
760771

761772
.. code-block:: rust
762773
763-
// Drops `x` before `y`.
764-
fn or_pattern_drop_order<T>(
765-
(Ok([x, y]) | Err([y, x])): Result<[T; 2], [T; 2]>
766-
// ^^^^^^^^^^ ^^^^^^^^^^^ This is the second pattern-without-alternation.
767-
// |
768-
// This is the first pattern-without-alternation.
769-
//
770-
// In the first pattern-without-alternation, `x` is declared before `y`.
771-
// Since it is the first pattern-without-alternation, that is the order
772-
// used even if the second pattern-without-alternation, where the bindings
773-
// are declared in the opposite order, is matched.
774-
) {}
775-
776-
// Here we match the first pattern-without-alternation, and the drops happen
777-
// according to the declaration order in the first pattern-without-alternation.
778-
or_pattern_drop_order(Ok([
779-
PrintOnDrop("Declared first, dropped last"),
780-
PrintOnDrop("Declared last, dropped first"),
781-
]));
782-
783-
// Here we match the second pattern-without-alternation, and the drops still
784-
// happen according to the declaration order in the first
785-
// pattern-without-alternation.
786-
or_pattern_drop_order(Err([
787-
PrintOnDrop("Declared last, dropped first"),
788-
PrintOnDrop("Declared first, dropped last"),
789-
]));
774+
fn drop_order<T>((Ok([a, b]) | Err([b, a])): Result<[T; 2], [T; 2]>) {}
775+
776+
drop_order(Ok([PrintOnDrop("1"), PrintOnDrop("2")]));
777+
778+
drop_order(Err([PrintOnDrop("2"), PrintOnDrop("1")]));
790779

0 commit comments

Comments
 (0)