Skip to content

Commit 9da3ab2

Browse files
richard-vineylpil
authored andcommitted
Fix deprecation warnings on latest stdlib version
1 parent 8c05a41 commit 9da3ab2

File tree

4 files changed

+29
-15
lines changed

4 files changed

+29
-15
lines changed

gleam.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ links = [
1212
]
1313

1414
[dependencies]
15-
gleam_stdlib = ">= 0.19.0 and < 2.0.0"
15+
gleam_stdlib = ">= 0.43.0 and < 2.0.0"
1616

1717
[dev-dependencies]
18-
gleeunit = "~> 1.0"
18+
gleeunit = ">= 1.2.0 and < 2.0.0"

manifest.toml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22
# You typically do not need to edit this file
33

44
packages = [
5-
{ name = "gleam_stdlib", version = "0.37.0", build_tools = ["gleam"], requirements = [], otp_app = "gleam_stdlib", source = "hex", outer_checksum = "5398BD6C2ABA17338F676F42F404B9B7BABE1C8DC7380031ACB05BBE1BCF3742" },
6-
{ name = "gleeunit", version = "1.1.2", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "gleeunit", source = "hex", outer_checksum = "72CDC3D3F719478F26C4E2C5FED3E657AC81EC14A47D2D2DEBB8693CA3220C3B" },
5+
{ name = "gleam_stdlib", version = "0.43.0", build_tools = ["gleam"], requirements = [], otp_app = "gleam_stdlib", source = "hex", outer_checksum = "69EF22E78FDCA9097CBE7DF91C05B2A8B5436826D9F66680D879182C0860A747" },
6+
{ name = "gleeunit", version = "1.2.0", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "gleeunit", source = "hex", outer_checksum = "F7A7228925D3EE7D0813C922E062BFD6D7E9310F0BEE585D3A42F3307E3CFD13" },
77
]
88

99
[requirements]
10-
gleam_stdlib = { version = ">= 0.19.0 and < 2.0.0" }
11-
gleeunit = { version = "~> 1.0" }
10+
gleam_stdlib = { version = ">= 0.43.0 and < 2.0.0" }
11+
gleeunit = { version = ">= 1.2.0 and < 2.0.0" }

src/gleam/json.gleam

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import gleam/dynamic.{type Dynamic}
33
import gleam/list
44
import gleam/option.{type Option, None, Some}
55
import gleam/result
6-
import gleam/string_builder.{type StringBuilder}
6+
import gleam/string_tree.{type StringTree}
77

88
pub type Json
99

@@ -102,8 +102,8 @@ fn decode_to_dynamic(json: BitArray) -> Result(Dynamic, DecodeError) {
102102

103103
/// Convert a JSON value into a string.
104104
///
105-
/// Where possible prefer the `to_string_builder` function as it is faster than
106-
/// this function, and BEAM VM IO is optimised for sending `StringBuilder` data.
105+
/// Where possible prefer the `to_string_tree` function as it is faster than
106+
/// this function, and BEAM VM IO is optimised for sending `StringTree` data.
107107
///
108108
/// ## Examples
109109
///
@@ -133,13 +133,27 @@ fn do_to_string(a: Json) -> String
133133
/// string_builder.from_string("[1,2,3]")
134134
/// ```
135135
///
136-
pub fn to_string_builder(json: Json) -> StringBuilder {
137-
do_to_string_builder(json)
136+
@deprecated("Use `json.to_string_tree` instead.")
137+
pub fn to_string_builder(json: Json) -> StringTree {
138+
to_string_tree(json)
138139
}
139140

141+
/// Convert a JSON value into a string tree.
142+
///
143+
/// Where possible prefer this function to the `to_string` function as it is
144+
/// slower than this function, and BEAM VM IO is optimised for sending
145+
/// `StringTree` data.
146+
///
147+
/// ## Examples
148+
///
149+
/// ```gleam
150+
/// > to_string_tree(array([1, 2, 3], of: int))
151+
/// string_tree.from_string("[1,2,3]")
152+
/// ```
153+
///
140154
@external(erlang, "gleam_json_ffi", "json_to_iodata")
141155
@external(javascript, "../gleam_json_ffi.mjs", "json_to_string")
142-
fn do_to_string_builder(a: Json) -> StringBuilder
156+
pub fn to_string_tree(json: Json) -> StringTree
143157

144158
/// Encode a string into JSON, using normal JSON escaping.
145159
///

test/gleam_json_test.gleam

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import gleam/dynamic
22
import gleam/json.{type Json}
33
import gleam/option.{None, Some}
44
import gleam/string
5-
import gleam/string_builder
5+
import gleam/string_tree
66
import gleeunit
77
import gleeunit/should
88

@@ -146,8 +146,8 @@ fn should_encode(data: Json, expected: String) {
146146
|> should.equal(expected)
147147

148148
data
149-
|> json.to_string_builder
150-
|> string_builder.to_string
149+
|> json.to_string_tree
150+
|> string_tree.to_string
151151
|> should.equal(json.to_string(data))
152152
}
153153

0 commit comments

Comments
 (0)