Skip to content

Commit dfbe7e1

Browse files
authored
results: avoid stew in import name (#107)
1 parent 2b1c5eb commit dfbe7e1

File tree

6 files changed

+49
-36
lines changed

6 files changed

+49
-36
lines changed

json_serialization.nimble

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ skipDirs = @["tests", "fuzzer"]
1818

1919
requires "nim >= 1.6.0",
2020
"serialization",
21-
"stew",
21+
"stew >= 0.2.0",
2222
"results"
2323

2424
let nimc = getEnv("NIMC", "nim") # Which nim compiler to use

json_serialization/pkg/results.nim

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# json-serialization
2+
# Copyright (c) 2019-2025 Status Research & Development GmbH
3+
# Licensed under either of
4+
# * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE))
5+
# * MIT license ([LICENSE-MIT](LICENSE-MIT))
6+
# at your option.
7+
# This file may not be copied, modified, or distributed except according to
8+
# those terms.
9+
10+
import
11+
pkg/results, ../../json_serialization/[reader, writer, lexer]
12+
13+
export
14+
results
15+
16+
template shouldWriteObjectField*[T](field: Result[T, void]): bool =
17+
field.isOk
18+
19+
proc writeValue*[T](
20+
writer: var JsonWriter, value: Result[T, void]) {.raises: [IOError].} =
21+
mixin writeValue
22+
23+
if value.isOk:
24+
writer.writeValue value.get
25+
else:
26+
writer.writeValue JsonString("null")
27+
28+
proc readValue*[T](reader: var JsonReader, value: var Result[T, void]) =
29+
mixin readValue
30+
31+
if reader.tokKind == JsonValueKind.Null:
32+
reset value
33+
reader.parseNull()
34+
else:
35+
value.ok reader.readValue(T)
36+
37+
func isFieldExpected*[T, E](_: type[Result[T, E]]): bool {.compileTime.} =
38+
false
Lines changed: 4 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,13 @@
11
# json-serialization
2-
# Copyright (c) 2019-2023 Status Research & Development GmbH
2+
# Copyright (c) 2019-2025 Status Research & Development GmbH
33
# Licensed under either of
44
# * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE))
55
# * MIT license ([LICENSE-MIT](LICENSE-MIT))
66
# at your option.
77
# This file may not be copied, modified, or distributed except according to
88
# those terms.
99

10-
import
11-
pkg/results, ../../json_serialization/[reader, writer, lexer]
10+
{.deprecated: "json_serialization/pkg/results".}
1211

13-
export
14-
results
15-
16-
template shouldWriteObjectField*[T](field: Result[T, void]): bool =
17-
field.isOk
18-
19-
proc writeValue*[T](
20-
writer: var JsonWriter, value: Result[T, void]) {.raises: [IOError].} =
21-
mixin writeValue
22-
23-
if value.isOk:
24-
writer.writeValue value.get
25-
else:
26-
writer.writeValue JsonString("null")
27-
28-
proc readValue*[T](reader: var JsonReader, value: var Result[T, void]) =
29-
mixin readValue
30-
31-
if reader.tokKind == JsonValueKind.Null:
32-
reset value
33-
reader.parseNull()
34-
else:
35-
value.ok reader.readValue(T)
36-
37-
func isFieldExpected*[T, E](_: type[Result[T, E]]): bool {.compileTime.} =
38-
false
12+
import json_serialization/pkg/results
13+
export results

tests/test_json_flavor.nim

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# json-serialization
2-
# Copyright (c) 2019-2023 Status Research & Development GmbH
2+
# Copyright (c) 2019-2025 Status Research & Development GmbH
33
# Licensed under either of
44
# * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE))
55
# * MIT license ([LICENSE-MIT](LICENSE-MIT))
@@ -12,7 +12,7 @@ import
1212
unittest2,
1313
results,
1414
serialization,
15-
../json_serialization/stew/results,
15+
../json_serialization/pkg/results,
1616
../json_serialization/std/options,
1717
../json_serialization
1818

tests/test_serialization.nim

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# json-serialization
2-
# Copyright (c) 2019-2023 Status Research & Development GmbH
2+
# Copyright (c) 2019-2025 Status Research & Development GmbH
33
# Licensed under either of
44
# * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE))
55
# * MIT license ([LICENSE-MIT](LICENSE-MIT))
@@ -14,7 +14,7 @@ import
1414
../json_serialization, ./utils,
1515
../json_serialization/lexer,
1616
../json_serialization/std/[options, sets, tables],
17-
../json_serialization/stew/results
17+
../json_serialization/pkg/results
1818

1919
type
2020
Foo = object

tests/test_writer.nim

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# json-serialization
2-
# Copyright (c) 2024 Status Research & Development GmbH
2+
# Copyright (c) 2024-2025 Status Research & Development GmbH
33
# Licensed under either of
44
# * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE))
55
# * MIT license ([LICENSE-MIT](LICENSE-MIT))
@@ -9,7 +9,7 @@
99

1010
import
1111
unittest2,
12-
../json_serialization/stew/results,
12+
../json_serialization/pkg/results,
1313
../json_serialization/std/options,
1414
../json_serialization
1515

0 commit comments

Comments
 (0)