mirror of
https://github.com/nim-lang/Nim.git
synced 2026-04-19 05:50:30 +00:00
Use more lent in options (#15208)
This commit is contained in:
committed by
GitHub
parent
575697e1f4
commit
07d82b5cc4
@@ -363,14 +363,14 @@ proc `$`*[T](self: Option[T]): string =
|
||||
else:
|
||||
result = "None[" & name(T) & "]"
|
||||
|
||||
proc unsafeGet*[T](self: Option[T]): T {.inline.}=
|
||||
proc unsafeGet*[T](self: Option[T]): lent T {.inline.}=
|
||||
## Returns the value of a `some`. Behavior is undefined for `none`.
|
||||
##
|
||||
## **Note:** Use it only when you are **absolutely sure** the value is present
|
||||
## (e.g. after checking `isSome <#isSome,Option[T]>`_).
|
||||
## Generally, using `get proc <#get,Option[T]>`_ is preferred.
|
||||
assert self.isSome
|
||||
self.val
|
||||
result = self.val
|
||||
|
||||
|
||||
when isMainModule:
|
||||
|
||||
Reference in New Issue
Block a user