1///|
2/// ID is used to identify the request and tie it to the response.
3pub enum ID {
4  // ID is a number, used to identify the request.
5  
(Int64) -> ID
Number
(
Int64
Int64
)
6 // ID is a string, used to identify the request. 7
(String) -> ID
String
(
String
String
)
8} derive(
(ID, &Logger) -> Unit

Trait for types that can be converted to String

Show
,
(ID, ID) -> Bool

Trait for types whose elements can test for equality

Eq
)
9 10///| 11pub fn
enum ID {
  Number(Int64)
  String(String)
}

ID is used to identify the request and tie it to the response.

ID
::
(n : Int64) -> ID
number
(
Int64
n
:
Int64
Int64
) ->
enum ID {
  Number(Int64)
  String(String)
}

ID is used to identify the request and tie it to the response.

ID
{
12
(Int64) -> ID
Number
(
Int64
n
)
13} 14 15///| 16pub fn
enum ID {
  Number(Int64)
  String(String)
}

ID is used to identify the request and tie it to the response.

ID
::
(s : String) -> ID
string
(
String
s
:
String
String
) ->
enum ID {
  Number(Int64)
  String(String)
}

ID is used to identify the request and tie it to the response.

ID
{
17
(String) -> ID
String
(
String
s
)
18} 19 20///| 21pub impl
trait ToJson {
  to_json(Self) -> Json
}

Trait for types that can be converted to Json

ToJson
for
enum ID {
  Number(Int64)
  String(String)
}

ID is used to identify the request and tie it to the response.

ID
with
(self : ID) -> Json
to_json
(
ID
self
) {
22 match
ID
self
{
23
(Int64) -> ID
Number
(
Int64
n
) =>
Int64
n
.
(self : Int64) -> Double

Converts a 64-bit signed integer to a double-precision floating-point number.

Parameters:

  • self : The 64-bit signed integer to be converted.

Returns a double-precision floating-point number that represents the same value as the input integer.

Example:

test "Int64::to_double" {
  let big = 9223372036854775807L // max value of Int64
  inspect(big.to_double(), content="9223372036854776000")
  let neg = -42L
  inspect(neg.to_double(), content="-42")
}
to_double
().
(self : Double) -> Json
to_json
()
24
(String) -> ID
String
(
String
s
) =>
String
s
.
(self : String) -> Json
to_json
()
25 } 26} 27 28///| 29pub impl
trait @json.FromJson {
  from_json(Json, @json.JsonPath) -> Self!@json.JsonDecodeError
}

Trait for types that can be converted from Json

@json.FromJson
for
enum ID {
  Number(Int64)
  String(String)
}

ID is used to identify the request and tie it to the response.

ID
with
(json : Json, path : @json.JsonPath) -> ID!@json.JsonDecodeError
from_json
(
Json
json
,
@json.JsonPath
path
) {
30 let
Result[Double, @json.JsonDecodeError]
n
:
enum Result[A, B] {
  Err(B)
  Ok(A)
}
Result
[
Double
Double
,
type! @json.JsonDecodeError (@json.JsonPath, String)
@json.JsonDecodeError
] =
(json : Json, path~ : @json.JsonPath = ..) -> Double!@json.JsonDecodeError
@json.from_json
?(
Json
json
)
31 if
Result[Double, @json.JsonDecodeError]
n
is
(Double) -> Result[Double, @json.JsonDecodeError]
Ok
(
Double
n
) {
32 return
(Int64) -> ID
Number
(
Double
n
.
(self : Double) -> Int64

Converts a double-precision floating-point number to a 64-bit integer. Handles special cases including NaN and numbers outside the valid Int range.

Parameters:

  • self : The double-precision floating-point number to be converted.

Returns an 64-bit integer value according to the following rules:

  • Returns 0 if the input is NaN
  • Returns @int64.max_value (9223372036854775807L) if the input is greater than or equal to @int64.max_value
  • Returns @int64.min_value (-9223372036854775808L) if the input is less than or equal to @int64.min_value
  • Otherwise returns the integer part of the input by truncating towards zero

Example:

test "Double::to_int64" {
  inspect(42.0.to_int64(), content="42")
  inspect((-42.5).to_int64(), content="-42")
  inspect((0.0 / 0.0).to_int64(), content="0") // NaN
  inspect((1.0 / 0.0).to_int64(), content="9223372036854775807") // Infinity
  inspect((-1.0 / 0.0).to_int64(), content="-9223372036854775808") // -Infinity
}
to_int64
())
33 } 34 let
Result[String, @json.JsonDecodeError]
s
:
enum Result[A, B] {
  Err(B)
  Ok(A)
}
Result
[
String
String
,
type! @json.JsonDecodeError (@json.JsonPath, String)
@json.JsonDecodeError
] =
(json : Json, path~ : @json.JsonPath = ..) -> String!@json.JsonDecodeError
@json.from_json
?(
Json
json
)
35 if
Result[String, @json.JsonDecodeError]
s
is
(String) -> Result[String, @json.JsonDecodeError]
Ok
(
String
s
) {
36 return
(String) -> ID
String
(
String
s
)
37 } 38 raise @json.
((@json.JsonPath, String)) -> @json.JsonDecodeError
JsonDecodeError
((
@json.JsonPath
path
, "expected number or string"))
39} 40