1// Copyright 2025 International Digital Economy Academy
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15///|
16type Handle
17
18///|
19extern "c" fn uv_close(handle : type Handle
Handle, cb : (type Handle
Handle) -> Unit
Unit) = "moonbit_uv_close"
20
21///|
22pub fn type Handle
Handle::(self : Handle, cb : (Handle) -> Unit) -> Unit
close(Handle
self : type Handle
Handle, (Handle) -> Unit
cb : (type Handle
Handle) -> Unit
Unit) -> Unit
Unit {
23 (handle : Handle, cb : (Handle) -> Unit) -> Unit
uv_close(Handle
self, (Handle) -> Unit
cb)
24}
25
26///|
27#deprecated("Use Handle::close() instead")
28pub fn[Handle : trait ToHandle {
to_handle(Self) -> Handle
of_handle(Handle) -> Self
close(Self, (Self) -> Unit) -> Unit
is_closing(Self) -> Bool
loop_(Self) -> Loop
}
ToHandle] (handle : Handle, cb : (Handle) -> Unit) -> Unit
close(Handle
handle : type parameter Handle
Handle, (Handle) -> Unit
cb : (type parameter Handle
Handle) -> Unit
Unit) -> Unit
Unit {
29 Handle
handle.(Handle, (Handle) -> Unit) -> Unit
close((Handle) -> Unit
cb)
30}
31
32///|
33extern "c" fn uv_is_closing(handle : type Handle
Handle) -> Bool
Bool = "moonbit_uv_is_closing"
34
35///|
36pub fn type Handle
Handle::(self : Handle) -> Bool
is_closing(Handle
self : type Handle
Handle) -> Bool
Bool {
37 (handle : Handle) -> Bool
uv_is_closing(Handle
self)
38}
39
40///|
41#deprecated("Use Handle::is_closing() instead")
42pub fn[Handle : trait ToHandle {
to_handle(Self) -> Handle
of_handle(Handle) -> Self
close(Self, (Self) -> Unit) -> Unit
is_closing(Self) -> Bool
loop_(Self) -> Loop
}
ToHandle] (handle : Handle) -> Bool
is_closing(Handle
handle : type parameter Handle
Handle) -> Bool
Bool {
43 Handle
handle.(Handle) -> Bool
is_closing()
44}
45
46///|
47pub trait trait ToHandle {
to_handle(Self) -> Handle
of_handle(Handle) -> Self
close(Self, (Self) -> Unit) -> Unit
is_closing(Self) -> Bool
loop_(Self) -> Loop
}
ToHandle {
48 (Self) -> Handle
to_handle(type parameter Self
Self) -> type Handle
Handle
49 (Handle) -> Self
of_handle(type Handle
Handle) -> type parameter Self
Self
50 (Self, (Self) -> Unit) -> Unit
close(type parameter Self
Self, (type parameter Self
Self) -> Unit
Unit) -> Unit
Unit = _
51 (Self) -> Bool
is_closing(type parameter Self
Self) -> Bool
Bool = _
52 (Self) -> Loop
loop_(type parameter Self
Self) -> type Loop Bytes
Loop = _
53}
54
55///|
56impl trait ToHandle {
to_handle(Self) -> Handle
of_handle(Handle) -> Self
close(Self, (Self) -> Unit) -> Unit
is_closing(Self) -> Bool
loop_(Self) -> Loop
}
ToHandle with (self : Self, cb : (Self) -> Unit) -> Unit
close(Self
self, (Self) -> Unit
cb) {
57 fn (Handle) -> Unit
uv_cb(Handle
handle : type Handle
Handle) {
58 (Self) -> Unit
cb(trait ToHandle {
to_handle(Self) -> Handle
of_handle(Handle) -> Self
close(Self, (Self) -> Unit) -> Unit
is_closing(Self) -> Bool
loop_(Self) -> Loop
}
ToHandle(_ : Handle) -> Self
::of_handle(Handle
handle))
59 }
60
61 Self
self.(Self) -> Handle
to_handle().(self : Handle, cb : (Handle) -> Unit) -> Unit
close((Handle) -> Unit
uv_cb)
62}
63
64///|
65impl trait ToHandle {
to_handle(Self) -> Handle
of_handle(Handle) -> Self
close(Self, (Self) -> Unit) -> Unit
is_closing(Self) -> Bool
loop_(Self) -> Loop
}
ToHandle with (self : Self) -> Bool
is_closing(Self
self) {
66 Self
self.(Self) -> Handle
to_handle().(self : Handle) -> Bool
is_closing()
67}
68
69///|
70extern "c" fn uv_handle_loop(handle : type Handle
Handle) -> type Loop Bytes
Loop = "moonbit_uv_handle_loop"
71
72///|
73impl trait ToHandle {
to_handle(Self) -> Handle
of_handle(Handle) -> Self
close(Self, (Self) -> Unit) -> Unit
is_closing(Self) -> Bool
loop_(Self) -> Loop
}
ToHandle with (self : Self) -> Loop
loop_(Self
self) {
74 (handle : Handle) -> Loop
uv_handle_loop(Self
self.(Self) -> Handle
to_handle())
75}
76
77///|
78pub enum HandleType {
79 HandleType
Unknown = 0
80 HandleType
Async = 1
81 HandleType
Check = 2
82 HandleType
FsEvent = 3
83 HandleType
FsPoll = 4
84 HandleType
Handle = 5
85 HandleType
Idle = 6
86 HandleType
Pipe = 7
87 HandleType
Poll = 8
88 HandleType
Prepare = 9
89 HandleType
Process = 10
90 HandleType
Stream = 11
91 HandleType
Tcp = 12
92 HandleType
Timer = 13
93 HandleType
Tty = 14
94 HandleType
Udp = 15
95 HandleType
Signal = 16
96 HandleType
File = 17
97} derive(trait Eq {
op_equal(Self, Self) -> Bool
}
Trait for types whose elements can test for equality
Eq, trait Hash {
hash_combine(Self, Hasher) -> Unit
hash(Self) -> Int
}
Trait for types that can be hashed
Hash)
98