From b8cc61d1aeffd2dc4f3a1864ba44c4e682a4e5b1 Mon Sep 17 00:00:00 2001 From: Ashley Date: Wed, 2 Jul 2025 05:31:53 +0100 Subject: [PATCH] feat(options): add second `unsafeGet` that operates on `var Option[T]` --- lib/pure/options.nim | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/lib/pure/options.nim b/lib/pure/options.nim index b34ff72c0dfb7..59a580ccde5fd 100644 --- a/lib/pure/options.nim +++ b/lib/pure/options.nim @@ -379,3 +379,12 @@ proc unsafeGet*[T](self: Option[T]): lent T {.inline.}= ## Generally, using the `get proc <#get,Option[T]>`_ is preferred. assert self.isSome result = self.val + +proc unsafeGet*[T](self: var Option[T]): var T {.inline.}= + ## Returns the value of a `some` mutably. The behavior is undefined for `none`. + ## + ## **Note:** Use this only when you are **absolutely sure** the value is present + ## (e.g. after checking with `isSome <#isSome,Option[T]>`_). + ## Generally, using the `get proc <#get,Option[T]_2>`_ is preferred. + assert self.isSome + result = self.val