1///|
2type FsEvent
3
4///|
5pub impl trait ToHandle {
to_handle(Self) -> Handle
of_handle(Handle) -> Self
close(Self, (Self) -> Unit) -> Unit
is_closing(Self) -> Bool
}
ToHandle for type FsEvent
FsEvent with to_handle(self) = "%identity"
6
7///|
8pub impl trait ToHandle {
to_handle(Self) -> Handle
of_handle(Handle) -> Self
close(Self, (Self) -> Unit) -> Unit
is_closing(Self) -> Bool
}
ToHandle for type FsEvent
FsEvent with of_handle(handle : type Handle
Handle) -> type FsEvent
FsEvent = "%identity"
9
10///|
11extern "c" fn uv_fs_event_make() -> type FsEvent
FsEvent = "moonbit_uv_fs_event_make"
12
13///|
14extern "c" fn uv_fs_event_init(uv : type Loop Bytes
Loop, fs_event : type FsEvent
FsEvent) -> Int
Int = "moonbit_uv_fs_event_init"
15
16///|
17pub fn type FsEvent
FsEvent::(self : Loop) -> FsEvent!Errno
new(Loop
self : type Loop Bytes
Loop) -> type FsEvent
FsEvent!type! Errno Status
Errno {
18 let FsEvent
fs_event = () -> FsEvent
uv_fs_event_make()
19 let Int
status = (uv : Loop, fs_event : FsEvent) -> Int
uv_fs_event_init(Loop
self, FsEvent
fs_event)
20 if Int
status (self_ : Int, other : Int) -> Bool
< 0 {
21 raise type! Errno Status
Errno::(errno : Int) -> Errno
of_int(Int
status)
22 }
23 return FsEvent
fs_event
24}
25
26///|
27pub enum FsEventType {
28 FsEventType
Rename = 1
29 FsEventType
Change = 2
30} derive((FsEventType, &Logger) -> Unit
Trait for types that can be converted to String
Show)
31
32///|
33pub impl trait ToJson {
to_json(Self) -> Json
}
Trait for types that can be converted to Json
ToJson for enum FsEventType {
Rename
Change
}
FsEventType with (self : FsEventType) -> Json
to_json(FsEventType
self) {
34 match FsEventType
self {
35 FsEventType
Rename => "Rename"
36 FsEventType
Change => "Change"
37 }
38}
39
40///|
41const Int
UV_RENAME = 1
42
43///|
44const Int
UV_CHANGE = 2
45
46///|
47extern "c" fn uv_fs_event_start(
48 fs_event : type FsEvent
FsEvent,
49 cb : (type FsEvent
FsEvent, @c.Pointer[Byte
Byte], Int
Int, Int
Int) -> Unit
Unit,
50 path : Bytes
Bytes,
51 flags : Int
Int
52) -> Int
Int = "moonbit_uv_fs_event_start"
53
54///|
55type FsEventFlags Int
Int
56
57///|
58const Int
UV_FS_EVENT_RECURSIVE = 4
59
60///|
61pub fn type FsEventFlags Int
FsEventFlags::(recursive~ : Bool = ..) -> FsEventFlags
new(Bool
recursive~ : Bool
Bool = false) -> type FsEventFlags Int
FsEventFlags {
62 let mut Int
flags = 0
63 if Bool
recursive {
64 Int
flags = Int
flags (Int, Int) -> Int
| Int
UV_FS_EVENT_RECURSIVE
65 }
66 return Int
flags
67}
68
69///|
70pub fn type FsEvent
FsEvent::(self : FsEvent, path : String, flags : FsEventFlags, event_cb : (FsEvent, String?, Array[FsEventType]) -> Unit, error_cb : (FsEvent, String?, Errno) -> Unit) -> Unit!Errno
start(
71 FsEvent
self : type FsEvent
FsEvent,
72 String
path : String
String,
73 FsEventFlags
flags : type FsEventFlags Int
FsEventFlags,
74 (FsEvent, String?, Array[FsEventType]) -> Unit
event_cb : (type FsEvent
FsEvent, String
String?, type Array[T]
An Array is a collection of values that supports random access and can
grow in size.
Array[enum FsEventType {
Rename
Change
}
FsEventType]) -> Unit
Unit,
75 (FsEvent, String?, Errno) -> Unit
error_cb : (type FsEvent
FsEvent, String
String?, type! Errno Status
Errno) -> Unit
Unit
76) -> Unit
Unit!type! Errno Status
Errno {
77 fn (FsEvent, ?, Int, Int) -> Unit
uv_cb(
78 FsEvent
fs_event : type FsEvent
FsEvent,
79 ?
filename : @c.Pointer[Byte
Byte],
80 Int
events : Int
Int,
81 Int
status : Int
Int
82 ) {
83 let String?
filename = if ?
filename.() -> Bool
is_null() {
84 String?
None
85 } else {
86 let @buffer.T
buffer = (size_hint~ : Int = ..) -> @buffer.T
Creates a new extensible buffer with specified initial capacity. If the
initial capacity is less than 1, the buffer will be initialized with capacity
1.
Parameters:
size_hint : Initial capacity of the buffer in bytes. Defaults to 0.
Returns a new buffer of type T.
Example:
test "new" {
let buf = @buffer.new(size_hint=10)
inspect(buf.length(), content="0")
buf.write_string("test")
inspect(buf.length(), content="8")
}
@buffer.new()
87 for Int
i = 0; ?
filename(Int) -> Int
[i] (x : Int, y : Int) -> Bool
!= 0; Int
i = Int
i (self : Int, other : Int) -> Int
Adds two 32-bit signed integers. Performs two's complement arithmetic, which
means the operation will wrap around if the result exceeds the range of a
32-bit integer.
Parameters:
self : The first integer operand.
other : The second integer operand.
Returns a new integer that is the sum of the two operands. If the
mathematical sum exceeds the range of a 32-bit integer (-2,147,483,648 to
2,147,483,647), the result wraps around according to two's complement rules.
Example:
test "Int::op_add" {
inspect(42 + 1, content="43")
inspect(2147483647 + 1, content="-2147483648") // Overflow wraps around to minimum value
}
+ 1 {
88 @buffer.T
buffer.(self : @buffer.T, value : Byte) -> Unit
Writes a single byte to the end of the buffer. The buffer will automatically
grow if necessary to accommodate the new byte.
Parameters:
buffer : The buffer to write to.
byte : The byte value to be written.
Example:
test "write_byte" {
let buf = @buffer.new()
buf.write_byte(b'\x41')
inspect(buf.contents(), content="b\"\\x41\"")
}
write_byte(?
filename(Int) -> Byte
[i])
89 }
90 (String) -> String?
Some((input : @bytes.View, encoding~ : @encoding.Encoding) -> String
@encoding.decode_lossy(@buffer.T
buffer.(self : @buffer.T) -> Bytes
Returns a copy of the buffer's content as a sequence of bytes.
Parameters:
buffer : The buffer to read from.
Returns a Bytes object containing all bytes written to the buffer.
Example:
test "contents" {
let buf = @buffer.new()
buf.write_string("Test")
inspect(
buf.contents(),
content=
#|b"\x54\x00\x65\x00\x73\x00\x74\x00"
,
)
}
contents(), @encoding.Encoding
encoding=@encoding.Encoding
UTF8))
91 }
92 if Int
status (self_ : Int, other : Int) -> Bool
< 0 {
93 (FsEvent, String?, Errno) -> Unit
error_cb(FsEvent
fs_event, String?
filename, type! Errno Status
Errno::(errno : Int) -> Errno
of_int(Int
status))
94 } else {
95 let Array[FsEventType]
event_types = []
96 if (Int
events (Int, Int) -> Int
& Int
UV_RENAME) (x : Int, y : Int) -> Bool
!= 0 {
97 Array[FsEventType]
event_types.(self : Array[FsEventType], value : FsEventType) -> Unit
Adds an element to the end of the array.
If the array is at capacity, it will be reallocated.
Example
let v = []
v.push(3)
push(FsEventType
Rename)
98 }
99 if (Int
events (Int, Int) -> Int
& Int
UV_CHANGE) (x : Int, y : Int) -> Bool
!= 0 {
100 Array[FsEventType]
event_types.(self : Array[FsEventType], value : FsEventType) -> Unit
Adds an element to the end of the array.
If the array is at capacity, it will be reallocated.
Example
let v = []
v.push(3)
push(FsEventType
Change)
101 }
102 (FsEvent, String?, Array[FsEventType]) -> Unit
event_cb(FsEvent
fs_event, String?
filename, Array[FsEventType]
event_types)
103 }
104 }
105
106 let Bytes
path = String
path.(self : String) -> Bytes
to_ntbs()
107 let Int
status = (fs_event : FsEvent, cb : (FsEvent, ?, Int, Int) -> Unit, path : Bytes, flags : Int) -> Int
uv_fs_event_start(FsEvent
self, (FsEvent, ?, Int, Int) -> Unit
uv_cb, Bytes
path, FsEventFlags
flags.Int
_)
108 if Int
status (self_ : Int, other : Int) -> Bool
< 0 {
109 raise type! Errno Status
Errno::(errno : Int) -> Errno
of_int(Int
status)
110 }
111}
112
113///|
114extern "c" fn uv_fs_event_stop(fs_event : type FsEvent
FsEvent) -> Int
Int = "moonbit_uv_fs_event_stop"
115
116///|
117pub fn type FsEvent
FsEvent::(self : FsEvent) -> Unit!Errno
stop(FsEvent
self : type FsEvent
FsEvent) -> Unit
Unit!type! Errno Status
Errno {
118 let Int
status = (fs_event : FsEvent) -> Int
uv_fs_event_stop(FsEvent
self)
119 if Int
status (self_ : Int, other : Int) -> Bool
< 0 {
120 raise type! Errno Status
Errno::(errno : Int) -> Errno
of_int(Int
status)
121 }
122}
123
124///|
125extern "c" fn uv_fs_event_getpath(
126 fs_event : type FsEvent
FsEvent,
127 buffer : Bytes
Bytes,
128 length : type FixedArray[A]
FixedArray[Int
Int]
129) -> Int
Int = "moonbit_uv_fs_event_getpath"
130
131///|
132pub fn type FsEvent
FsEvent::(self : FsEvent) -> String!Errno
get_path(FsEvent
self : type FsEvent
FsEvent) -> String
String!type! Errno Status
Errno {
133 let Bytes
buffer = (Int, Byte) -> Bytes
Bytes::(len : Int, init : Byte) -> Bytes
Creates a new byte sequence of the specified length, where each byte is
initialized to the given value. Returns an empty byte sequence if the
length is negative.
Parameters:
length : The length of the byte sequence to create. Must be non-negative.
initial_value : The byte value used to initialize each position in the
sequence.
Example:
test "Bytes::make" {
let bytes = Bytes::make(3, b'\xFF')
inspect(bytes, content=
#|b"\xff\xff\xff"
)
let empty = Bytes::make(0, b'\x00')
inspect(empty, content="b\"\"")
}
make(64, 0)
134 let FixedArray[Int]
length : type FixedArray[A]
FixedArray[Int
Int] = [Bytes
buffer.(self : Bytes) -> Int
Returns the number of bytes in a byte sequence.
Parameters:
bytes : The byte sequence whose length is to be determined.
Returns an integer representing the length (number of bytes) of the sequence.
Example:
test "Bytes::length" {
let bytes = b"\x01\x02\x03"
inspect(bytes.length(), content="3")
let empty = b""
inspect(empty.length(), content="0")
}
length()]
135 let mut Int
status = (fs_event : FsEvent, buffer : Bytes, length : FixedArray[Int]) -> Int
uv_fs_event_getpath(FsEvent
self, Bytes
buffer, FixedArray[Int]
length)
136 if Int
status (self : Int, other : Int) -> Bool
Compares two integers for equality.
Parameters:
self : The first integer to compare.
other : The second integer to compare.
Returns true if both integers have the same value, false otherwise.
Example:
test "Int::op_equal" {
inspect(42 == 42, content="true")
inspect(42 == -42, content="false")
}
== () -> Int
uv_ENOBUFS() {
137 let Bytes
buffer = (Int, Byte) -> Bytes
Bytes::(len : Int, init : Byte) -> Bytes
Creates a new byte sequence of the specified length, where each byte is
initialized to the given value. Returns an empty byte sequence if the
length is negative.
Parameters:
length : The length of the byte sequence to create. Must be non-negative.
initial_value : The byte value used to initialize each position in the
sequence.
Example:
test "Bytes::make" {
let bytes = Bytes::make(3, b'\xFF')
inspect(bytes, content=
#|b"\xff\xff\xff"
)
let empty = Bytes::make(0, b'\x00')
inspect(empty, content="b\"\"")
}
make(FixedArray[Int]
length[0], 0)
138 Int
status = (fs_event : FsEvent, buffer : Bytes, length : FixedArray[Int]) -> Int
uv_fs_event_getpath(FsEvent
self, Bytes
buffer, FixedArray[Int]
length)
139 }
140 if Int
status (self_ : Int, other : Int) -> Bool
< 0 {
141 raise type! Errno Status
Errno::(errno : Int) -> Errno
of_int(Int
status)
142 }
143 (input : @bytes.View, encoding~ : @encoding.Encoding) -> String
@encoding.decode_lossy(Bytes
buffer, @encoding.Encoding
encoding=@encoding.Encoding
UTF8)
144}
145