Skip to content

Commit 3bb4350

Browse files
richard-vineylpil
authored andcommitted
Update to stdlib 0.50 and use dynamic/decode
This fixes deprecation warnings on stdlib 0.53
1 parent df025f6 commit 3bb4350

File tree

12 files changed

+76
-67
lines changed

12 files changed

+76
-67
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
# Changelog
22

3+
## Unreleased
4+
5+
- Fixed deprecation warnings with the Gleam standard library v0.53.0 or later.
6+
- Increased minimum required Gleam standard library version to v0.50.0.
7+
38
## v0.33.1 - 2024-12-07
49

510
- Fixed a bug where `process.demonitor_process` would return the incorrect

gleam.toml

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

1414
[dependencies]
15-
gleam_stdlib = ">= 0.33.0 and < 2.0.0"
15+
gleam_stdlib = ">= 0.50.0 and < 2.0.0"
1616

1717
[dev-dependencies]
18-
gleeunit = "~> 1.0"
18+
gleeunit = ">= 1.3.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.33.1", build_tools = ["gleam"], requirements = [], otp_app = "gleam_stdlib", source = "hex", outer_checksum = "3CEAD7B153D896499C78390B22CC968620C27500C922AED3A5DD7B536F922B25" },
6-
{ name = "gleeunit", version = "1.0.0", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "gleeunit", source = "hex", outer_checksum = "D3682ED8C5F9CAE1C928F2506DE91625588CC752495988CBE0F5653A42A6F334" },
5+
{ name = "gleam_stdlib", version = "0.53.0", build_tools = ["gleam"], requirements = [], otp_app = "gleam_stdlib", source = "hex", outer_checksum = "53F3E1E56F692C20FA3E0A23650AC46592464E40D8EF3EC7F364FB328E73CDF5" },
6+
{ name = "gleeunit", version = "1.3.0", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "gleeunit", source = "hex", outer_checksum = "0E6C83834BA65EDCAAF4FE4FB94AC697D9262D83E6F58A750D63C9F6C8A9D9FF" },
77
]
88

99
[requirements]
10-
gleam_stdlib = { version = ">= 0.33.0 and < 2.0.0" }
11-
gleeunit = { version = "~> 1.0" }
10+
gleam_stdlib = { version = ">= 0.50.0 and < 2.0.0" }
11+
gleeunit = { version = ">= 1.3.0 and < 2.0.0" }

src/gleam/erlang.gleam

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
import gleam/dynamic.{type DecodeErrors, type Dynamic}
1+
import gleam/dynamic.{type Dynamic}
2+
import gleam/dynamic/decode.{type DecodeError}
23
import gleam/erlang/atom.{type Atom}
34
import gleam/erlang/charlist.{type Charlist}
45
import gleam/list
@@ -190,7 +191,7 @@ pub fn make_reference() -> Reference
190191
@external(erlang, "gleam_erlang_ffi", "reference_from_dynamic")
191192
pub fn reference_from_dynamic(
192193
from from: Dynamic,
193-
) -> Result(Reference, DecodeErrors)
194+
) -> Result(Reference, List(DecodeError))
194195

195196
/// Returns the path of a package's `priv` directory, where extra non-Gleam
196197
/// or Erlang files are typically kept.

src/gleam/erlang/atom.gleam

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
import gleam/dynamic.{type DecodeErrors, type Dynamic}
1+
import gleam/dynamic.{type Dynamic}
2+
import gleam/dynamic/decode.{type DecodeError}
23

34
/// Atom is a special string-like data-type that is most commonly used for
45
/// interfacing with code written in other BEAM languages such as Erlang and
@@ -81,4 +82,4 @@ pub fn to_string(a: Atom) -> String
8182
/// ```
8283
///
8384
@external(erlang, "gleam_erlang_ffi", "atom_from_dynamic")
84-
pub fn from_dynamic(from from: Dynamic) -> Result(Atom, DecodeErrors)
85+
pub fn from_dynamic(from from: Dynamic) -> Result(Atom, List(DecodeError))

src/gleam/erlang/port.gleam

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
import gleam/dynamic.{type DecodeErrors, type Dynamic}
1+
import gleam/dynamic.{type Dynamic}
2+
import gleam/dynamic/decode.{type DecodeError}
23

34
/// Ports are how code running on the Erlang virtual machine interacts with
45
/// the outside world. Bytes of data can be sent to and read from ports,
@@ -16,11 +17,11 @@ pub type Port
1617
/// ## Examples
1718
///
1819
/// > import gleam/dynamic
19-
/// > from_dynamic(dynamic.from(process.self()))
20+
/// > port_from_dynamic(dynamic.from(process.self()))
2021
/// Ok(process.self())
2122
///
22-
/// > from_dynamic(dynamic.from(123))
23+
/// > port_from_dynamic(dynamic.from(123))
2324
/// Error([DecodeError(expected: "Port", found: "Int", path: [])])
2425
///
2526
@external(erlang, "gleam_erlang_ffi", "port_from_dynamic")
26-
pub fn port_from_dynamic(from from: Dynamic) -> Result(Port, DecodeErrors)
27+
pub fn port_from_dynamic(from from: Dynamic) -> Result(Port, List(DecodeError))

src/gleam/erlang/process.gleam

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
import gleam/dynamic.{type DecodeErrors, type Dynamic}
1+
import gleam/dynamic.{type Dynamic}
2+
import gleam/dynamic/decode.{type DecodeError}
23
import gleam/erlang.{type Reference}
34
import gleam/erlang/atom.{type Atom}
45
import gleam/string
@@ -238,7 +239,7 @@ pub fn selecting_trapped_exits(
238239
let reason = message.2
239240
let normal = dynamic.from(Normal)
240241
let killed = dynamic.from(Killed)
241-
let reason = case dynamic.string(reason) {
242+
let reason = case decode.run(reason, decode.string) {
242243
_ if reason == normal -> Normal
243244
_ if reason == killed -> Killed
244245
Ok(reason) -> Abnormal(reason)
@@ -743,7 +744,7 @@ pub type Cancelled {
743744
/// Cancel a given timer, causing it not to trigger if it has not done already.
744745
///
745746
pub fn cancel_timer(timer: Timer) -> Cancelled {
746-
case dynamic.int(erlang_cancel_timer(timer)) {
747+
case decode.run(erlang_cancel_timer(timer), decode.int) {
747748
Ok(i) -> Cancelled(i)
748749
Error(_) -> TimerNotFound
749750
}
@@ -847,13 +848,13 @@ pub fn named(name: Atom) -> Result(Pid, Nil)
847848
///
848849
/// ```gleam
849850
/// import gleam/dynamic
850-
/// from_dynamic(dynamic.from(process.self()))
851+
/// pid_from_dynamic(dynamic.from(process.self()))
851852
/// // -> Ok(process.self())
852853
/// ```
853854
///
854855
/// ```gleam
855-
/// from_dynamic(dynamic.from(123))
856+
/// pid_from_dynamic(dynamic.from(123))
856857
/// // -> Error([DecodeError(expected: "Pid", found: "Int", path: [])])
857858
/// ```
858859
@external(erlang, "gleam_erlang_ffi", "pid_from_dynamic")
859-
pub fn pid_from_dynamic(from from: Dynamic) -> Result(Pid, DecodeErrors)
860+
pub fn pid_from_dynamic(from from: Dynamic) -> Result(Pid, List(DecodeError))

test/gleam/erlang/atom_test.gleam

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
import gleam/dynamic.{DecodeError}
1+
import gleam/dynamic
2+
import gleam/dynamic/decode.{DecodeError}
23
import gleam/erlang/atom
34

45
pub fn from_string_test() {

test/gleam/erlang/charlist_test.gleam

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,15 @@ pub fn empty_string_test() {
2222
let assert "" =
2323
[]
2424
|> dynamic.from
25-
|> dynamic.unsafe_coerce
25+
|> unsafe_coerce
2626
|> charlist.to_string
2727

2828
let assert [] =
2929
""
3030
|> charlist.from_string()
3131
|> dynamic.from
32-
|> dynamic.unsafe_coerce
32+
|> unsafe_coerce
3333
}
34+
35+
@external(erlang, "gleam_erlang_ffi", "identity")
36+
fn unsafe_coerce(a: dynamic.Dynamic) -> anything

test/gleam/erlang/port_test.gleam

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
import gleam/dynamic.{DecodeError}
1+
import gleam/dynamic
2+
import gleam/dynamic/decode.{DecodeError}
23
import gleam/erlang/port
34
import gleeunit/should
45

0 commit comments

Comments
 (0)