format
Some checks failed
github pages / deploy (push) Has been cancelled
build / build (4.08.x, ubuntu-latest) (push) Has been cancelled
build / build (4.14.x, ubuntu-latest) (push) Has been cancelled
build / build (5.03.x, ubuntu-latest) (push) Has been cancelled

This commit is contained in:
Simon Cruanes 2025-06-06 22:25:48 -04:00
parent 03c3e09f12
commit 0f917ddf72
No known key found for this signature in database
GPG key ID: EBFFF6F283F3A2B4
3 changed files with 39 additions and 27 deletions

View file

@ -1,4 +1,4 @@
version = 0.26.2 version = 0.27.0
profile=conventional profile=conventional
margin=80 margin=80
if-then-else=k-r if-then-else=k-r

View file

@ -73,9 +73,9 @@ let rec pp_ : type a b. Buffer.t -> (a, b) t -> unit =
| Rest { url_encoded } -> | Rest { url_encoded } ->
bpf out "<rest_of_url%s>" bpf out "<rest_of_url%s>"
(if url_encoded then (if url_encoded then
"_urlencoded" "_urlencoded"
else else
"") "")
| Compose (Exact s, tl) -> bpf out "%s/%a" s pp_ tl | Compose (Exact s, tl) -> bpf out "%s/%a" s pp_ tl
| Compose (Int, tl) -> bpf out "<int>/%a" pp_ tl | Compose (Int, tl) -> bpf out "<int>/%a" pp_ tl
| Compose (String, tl) -> bpf out "<str>/%a" pp_ tl | Compose (String, tl) -> bpf out "<str>/%a" pp_ tl
@ -96,17 +96,29 @@ let rec to_url_rec : type b. Buffer.t -> (b, string) t -> b =
fun buf route -> fun buf route ->
match route with match route with
| Fire -> Buffer.contents buf | Fire -> Buffer.contents buf
| Rest {url_encoded=_} -> | Rest { url_encoded = _ } ->
(fun str -> Buffer.add_string buf str; Buffer.contents buf) fun str ->
Buffer.add_string buf str;
Buffer.contents buf
| Compose (comp, rest) -> | Compose (comp, rest) ->
(match comp with (match comp with
| Exact s -> Buffer.add_string buf s; Buffer.add_char buf '/'; to_url_rec buf rest | Exact s ->
| Int -> (fun i -> Printf.bprintf buf "%d/" i; to_url_rec buf rest) Buffer.add_string buf s;
Buffer.add_char buf '/';
to_url_rec buf rest
| Int ->
fun i ->
Printf.bprintf buf "%d/" i;
to_url_rec buf rest
| String -> | String ->
(fun s -> Printf.bprintf buf "%s/" s; to_url_rec buf rest) fun s ->
| String_urlencoded -> Printf.bprintf buf "%s/" s;
(fun s -> Printf.bprintf buf "%s/" (Util.percent_encode s); to_url_rec buf rest)) to_url_rec buf rest
| String_urlencoded ->
fun s ->
Printf.bprintf buf "%s/" (Util.percent_encode s);
to_url_rec buf rest)
let to_url (h: ('a, string) t) : 'a = let to_url (h : ('a, string) t) : 'a =
let buf = Buffer.create 16 in let buf = Buffer.create 16 in
to_url_rec buf h to_url_rec buf h

View file

@ -1,8 +1,8 @@
(** Routing (** Routing
Basic type-safe routing of handlers based on URL paths. This is optional, Basic type-safe routing of handlers based on URL paths. This is optional, it
it is possible to only define the root handler with something like is possible to only define the root handler with something like
{{: https://github.com/anuragsoni/routes/} Routes}. {{:https://github.com/anuragsoni/routes/} Routes}.
@since 0.6 *) @since 0.6 *)
type ('a, 'b) comp type ('a, 'b) comp
@ -27,31 +27,31 @@ val return : ('a, 'a) t
(** Matches the empty path. *) (** Matches the empty path. *)
val rest_of_path : (string -> 'a, 'a) t val rest_of_path : (string -> 'a, 'a) t
(** Matches a string, even containing ['/']. This will match (** Matches a string, even containing ['/']. This will match the entirety of the
the entirety of the remaining route. remaining route.
@since 0.7 *) @since 0.7 *)
val rest_of_path_urlencoded : (string -> 'a, 'a) t val rest_of_path_urlencoded : (string -> 'a, 'a) t
(** Matches a string, even containing ['/'], and URL-decode it (piecewise). (** Matches a string, even containing ['/'], and URL-decode it (piecewise). This
This will match the entirety of the remaining route. will match the entirety of the remaining route.
@since 0.7 *) @since 0.7 *)
val ( @/ ) : ('a, 'b) comp -> ('b, 'c) t -> ('a, 'c) t val ( @/ ) : ('a, 'b) comp -> ('b, 'c) t -> ('a, 'c) t
(** [comp / route] matches ["foo/bar/…"] iff [comp] matches ["foo"], (** [comp / route] matches ["foo/bar/…"] iff [comp] matches ["foo"], and [route]
and [route] matches ["bar/…"]. *) matches ["bar/…"]. *)
val exact_path : string -> ('a, 'b) t -> ('a, 'b) t val exact_path : string -> ('a, 'b) t -> ('a, 'b) t
(** [exact_path "foo/bar/..." r] is equivalent to (** [exact_path "foo/bar/..." r] is equivalent to
[exact "foo" @/ exact "bar" @/ ... @/ r] [exact "foo" @/ exact "bar" @/ ... @/ r]
@since 0.11 **) @since 0.11 **)
val pp : Format.formatter -> _ t -> unit val pp : Format.formatter -> _ t -> unit
(** Print the route. (** Print the route.
@since 0.7 *) @since 0.7 *)
val to_string : _ t -> string val to_string : _ t -> string
(** Print the route. (** Print the route.
@since 0.7 *) @since 0.7 *)
val to_url : ('a, string) t -> 'a val to_url : ('a, string) t -> 'a