make get for options use lent T (#14442)
Co-authored-by: cooldome <ariabushenko@bk.ru>
This commit is contained in:
parent
58282547f6
commit
6635874a85
1 changed files with 2 additions and 2 deletions
|
|
@ -167,7 +167,7 @@ proc isNone*[T](self: Option[T]): bool {.inline.} =
|
||||||
else:
|
else:
|
||||||
not self.has
|
not self.has
|
||||||
|
|
||||||
proc get*[T](self: Option[T]): T {.inline.} =
|
proc get*[T](self: Option[T]): lent T {.inline.} =
|
||||||
## Returns contents of an `Option`. If it is `None`, then an exception is
|
## Returns contents of an `Option`. If it is `None`, then an exception is
|
||||||
## thrown.
|
## thrown.
|
||||||
##
|
##
|
||||||
|
|
@ -183,7 +183,7 @@ proc get*[T](self: Option[T]): T {.inline.} =
|
||||||
|
|
||||||
if self.isNone:
|
if self.isNone:
|
||||||
raise newException(UnpackError, "Can't obtain a value from a `none`")
|
raise newException(UnpackError, "Can't obtain a value from a `none`")
|
||||||
self.val
|
result = self.val
|
||||||
|
|
||||||
proc get*[T](self: Option[T], otherwise: T): T {.inline.} =
|
proc get*[T](self: Option[T], otherwise: T): T {.inline.} =
|
||||||
## Returns the contents of the `Option` or an `otherwise` value if
|
## Returns the contents of the `Option` or an `otherwise` value if
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue