Extend options stdlib
This changes adds more procs to the options stdlib. These are convenience functions that make life easier when interacting with Options -- I've wound up adding them to just about every app I have written with Nim.
The failure being reported in CI is:
tests/stdlib/thttpclient_ssl.nim c
Failure: reExitcodesDiffer
Expected:
exitcode: 0
Gotten:
exitcode: 1
Output:
[Suite] SSL self signed certificate check
[1746287859.487293] server: ready
[1746287859.5890162] client: connect
[1746287859.5897272] server: incoming connection
[1746287859.5898144] server: accepting connection
C0F6BF7BB47F0000:error:0A000418:SSL routines:ssl3_read_bytes:tlsv1 alert unknown ca:../ssl/record/rec_layer_s3.c:1599:SSL alert number 48
[1746287859.6046548] server: receiving a line
[1746287859.705398] client: connect
[1746287859.7056324] client: unexpected exception: Connection refused
[FAILED] HttpClient default: no check
[1746287859.811127] server: ready
[1746287859.9555795] server: ready
[1746287859.9844153] client: connect
[1746287859.9847176] server: incoming connection
[1746287859.9848032] server: accepting connection
[1746287859.9955516] client: exception: error:0A000086:SSL routines::certificate verify failed
C0F63F7BB47F0000:error:0A000418:SSL routines:ssl3_read_bytes:tlsv1 alert unknown ca:../ssl/record/rec_layer_s3.c:1599:SSL alert number 48
[1746287859.9997697] server: receiving a line
[1746287859.9997885] server: received 0 bytes
[1746287859.999796] closing
[1746287859.99985] server: exited
[1746287860.1011178] client: connect
[1746287860.1013148] client: exception: Connection refused
[1746287860.1013272] getContent should not have raised an exception
[FAILED] HttpClient with CVerifyPeerUseEnvVars
I may be missing something, but that seems unrelated to the change in this PR
I may be missing something, but that seems unrelated to the change in this PR
Correct, don't worry.
for results, I've been planning to reuse tricks like https://github.com/nim-lang/Nim/blob/version-2-2/lib/pure/collections/sequtils.nim#L97 to avoid most of the extra copies that are unnecessary - this implementation is very heavy on copies in general, often in a way that is tricky for the compiler to get rid of.
a second trick to use is to verify that the code efficiently moves data around and/or uses cursors where applicable, ie in Option[string], withValue should not copy the string inside the some case when it already has a stack copy of the Option instance, or this implementation will defeat one of the main purposes of using it, namely to work with values without said overhead. Imagine using it with a 10mb string.
In particular, see https://github.com/arnetheduck/nim-results/blob/df8113dda4c2d74d460a8fa98252b0b771bf1f27/results.nim#L1430 for a much more efficient way to inject a variable into a template - there is also a variation on the same theme when genericsopensym is not enabled.
Sorry for the delayed update. Rebased and pushed a new version that should prevent copies. CI failures look unrelated to my changes.
Note that I removed the ‘valueOr’ template as I couldn’t figure out how to implement it without requiring a copy. I didn’t want to block the other changes on that one snag, though