Use more lent in options (#15208)
This commit is contained in:
parent
575697e1f4
commit
07d82b5cc4
1 changed files with 2 additions and 2 deletions
|
|
@ -363,14 +363,14 @@ proc `$`*[T](self: Option[T]): string =
|
||||||
else:
|
else:
|
||||||
result = "None[" & name(T) & "]"
|
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`.
|
## Returns the value of a `some`. Behavior is undefined for `none`.
|
||||||
##
|
##
|
||||||
## **Note:** Use it only when you are **absolutely sure** the value is present
|
## **Note:** Use it only when you are **absolutely sure** the value is present
|
||||||
## (e.g. after checking `isSome <#isSome,Option[T]>`_).
|
## (e.g. after checking `isSome <#isSome,Option[T]>`_).
|
||||||
## Generally, using `get proc <#get,Option[T]>`_ is preferred.
|
## Generally, using `get proc <#get,Option[T]>`_ is preferred.
|
||||||
assert self.isSome
|
assert self.isSome
|
||||||
self.val
|
result = self.val
|
||||||
|
|
||||||
|
|
||||||
when isMainModule:
|
when isMainModule:
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue