Module Res.Id

Numerical identifiers.

This module parses sequences of US-ASCII digits to non-negative int values. Leading zeros are not allowed, see Id.of_string for the full details.

Errors

type error = [
  1. | `Overflow
  2. | `Syntax
]

The type for parse errors. See of_string.

val error_message : error -> string

error_message e is an english error message for e.

val error_to_resp : error -> Webs.Http.Response.t

error_to_resp e is a 400 bad request for e. The response's reason is determined by error_message.

Identifiers

type t = int

The type for non-negative identifiers.

val to_string : t -> string

to_string id are the US-ASCII digits for id. Raises Invalid_argument if id is negative.

val of_string : string -> (t, error) Stdlib.result

of_string s is:

  • Ok id, if s is a sequence of US-ASCII digits and id its non-negative decimal interpretation.
  • Error `Overflow in case s is only made of US-ASCII digits but there are too many of them to fit in a non-negative int.
  • Error `Syntax in case s contains any non US-ASCII digits or if s has a leading 0 and is not "0".
val decode : string -> (t, Webs.Http.Response.t) Stdlib.result

decode s is Result.map_error error_to_resp (of_string s).