lisette-stdlib 0.1.13

Little language inspired by Rust that compiles to Go
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
// Generated by Lisette bindgen
// Source: io (Go stdlib)
// Go: 1.25.5
// Lisette: 0.1.12

/// Copy copies from src to dst until either EOF is reached
/// on src or an error occurs. It returns the number of bytes
/// copied and the first error encountered while copying, if any.
/// 
/// A successful Copy returns err == nil, not err == EOF.
/// Because Copy is defined to read from src until EOF, it does
/// not treat an EOF from Read as an error to be reported.
/// 
/// If src implements [WriterTo],
/// the copy is implemented by calling src.WriteTo(dst).
/// Otherwise, if dst implements [ReaderFrom],
/// the copy is implemented by calling dst.ReadFrom(src).
pub fn Copy(dst: Writer, src: Reader) -> Result<int64, error>

/// CopyBuffer is identical to Copy except that it stages through the
/// provided buffer (if one is required) rather than allocating a
/// temporary one. If buf is nil, one is allocated; otherwise if it has
/// zero length, CopyBuffer panics.
/// 
/// If either src implements [WriterTo] or dst implements [ReaderFrom],
/// buf will not be used to perform the copy.
pub fn CopyBuffer(dst: Writer, src: Reader, mut buf: Slice<uint8>) -> Result<int64, error>

/// CopyN copies n bytes (or until an error) from src to dst.
/// It returns the number of bytes copied and the earliest
/// error encountered while copying.
/// On return, written == n if and only if err == nil.
/// 
/// If dst implements [ReaderFrom], the copy is implemented using it.
pub fn CopyN(dst: Writer, src: Reader, n: int64) -> Result<int64, error>

pub fn LimitReader(r: Reader, n: int64) -> Reader

pub fn MultiReader(readers: VarArgs<Reader>) -> Reader

pub fn MultiWriter(writers: VarArgs<Writer>) -> Writer

pub fn NewOffsetWriter(w: WriterAt, off: int64) -> Ref<OffsetWriter>

pub fn NewSectionReader(r: ReaderAt, off: int64, n: int64) -> Ref<SectionReader>

pub fn NopCloser(r: Reader) -> ReadCloser

/// Pipe creates a synchronous in-memory pipe.
/// It can be used to connect code expecting an [io.Reader]
/// with code expecting an [io.Writer].
/// 
/// Reads and Writes on the pipe are matched one to one
/// except when multiple Reads are needed to consume a single Write.
/// That is, each Write to the [PipeWriter] blocks until it has satisfied
/// one or more Reads from the [PipeReader] that fully consume
/// the written data.
/// The data is copied directly from the Write to the corresponding
/// Read (or Reads); there is no internal buffering.
/// 
/// It is safe to call Read and Write in parallel with each other or with Close.
/// Parallel calls to Read and parallel calls to Write are also safe:
/// the individual calls will be gated sequentially.
pub fn Pipe() -> (Ref<PipeReader>, Ref<PipeWriter>)

/// ReadAll reads from r until an error or EOF and returns the data it read.
/// A successful call returns err == nil, not err == EOF. Because ReadAll is
/// defined to read from src until EOF, it does not treat an EOF from Read
/// as an error to be reported.
pub fn ReadAll(r: Reader) -> Result<Slice<uint8>, error>

/// ReadAtLeast reads from r into buf until it has read at least min bytes.
/// It returns the number of bytes copied and an error if fewer bytes were read.
/// The error is EOF only if no bytes were read.
/// If an EOF happens after reading fewer than min bytes,
/// ReadAtLeast returns [ErrUnexpectedEOF].
/// If min is greater than the length of buf, ReadAtLeast returns [ErrShortBuffer].
/// On return, n >= min if and only if err == nil.
/// If r returns an error having read at least min bytes, the error is dropped.
pub fn ReadAtLeast(r: Reader, mut buf: Slice<uint8>, min: int) -> Partial<int, error>

/// ReadFull reads exactly len(buf) bytes from r into buf.
/// It returns the number of bytes copied and an error if fewer bytes were read.
/// The error is EOF only if no bytes were read.
/// If an EOF happens after reading some but not all the bytes,
/// ReadFull returns [ErrUnexpectedEOF].
/// On return, n == len(buf) if and only if err == nil.
/// If r returns an error having read at least len(buf) bytes, the error is dropped.
pub fn ReadFull(r: Reader, mut buf: Slice<uint8>) -> Partial<int, error>

pub fn TeeReader(r: Reader, w: Writer) -> Reader

/// WriteString writes the contents of the string s to w, which accepts a slice of bytes.
/// If w implements [StringWriter], [StringWriter.WriteString] is invoked directly.
/// Otherwise, [Writer.Write] is called exactly once.
pub fn WriteString(w: Writer, s: string) -> Result<int, error>

/// ByteReader is the interface that wraps the ReadByte method.
/// 
/// ReadByte reads and returns the next byte from the input or
/// any error encountered. If ReadByte returns an error, no input
/// byte was consumed, and the returned byte value is undefined.
/// 
/// ReadByte provides an efficient interface for byte-at-time
/// processing. A [Reader] that does not implement  ByteReader
/// can be wrapped using bufio.NewReader to add this method.
pub interface ByteReader {
  fn ReadByte() -> Result<uint8, error>
}

/// ByteScanner is the interface that adds the UnreadByte method to the
/// basic ReadByte method.
/// 
/// UnreadByte causes the next call to ReadByte to return the last byte read.
/// If the last operation was not a successful call to ReadByte, UnreadByte may
/// return an error, unread the last byte read (or the byte prior to the
/// last-unread byte), or (in implementations that support the [Seeker] interface)
/// seek to one byte before the current offset.
pub interface ByteScanner {
  fn ReadByte() -> Result<uint8, error>
  fn UnreadByte() -> Result<(), error>
}

/// ByteWriter is the interface that wraps the WriteByte method.
pub interface ByteWriter {
  fn WriteByte(c: uint8) -> Result<(), error>
}

/// Closer is the interface that wraps the basic Close method.
/// 
/// The behavior of Close after the first call is undefined.
/// Specific implementations may document their own behavior.
pub interface Closer {
  fn Close() -> Result<(), error>
}

/// A LimitedReader reads from R but limits the amount of
/// data returned to just N bytes. Each call to Read
/// updates N to reflect the new amount remaining.
/// Read returns EOF when N <= 0 or when the underlying R returns EOF.
pub struct LimitedReader {
  pub R: Option<Reader>,
  pub N: int64,
}

/// An OffsetWriter maps writes at offset base to offset base+off in the underlying writer.
pub type OffsetWriter

/// A PipeReader is the read half of a pipe.
pub type PipeReader

/// A PipeWriter is the write half of a pipe.
pub type PipeWriter

/// ReadCloser is the interface that groups the basic Read and Close methods.
pub interface ReadCloser {
  fn Close() -> Result<(), error>
  fn Read(mut p: Slice<uint8>) -> Partial<int, error>
}

/// ReadSeekCloser is the interface that groups the basic Read, Seek and Close
/// methods.
pub interface ReadSeekCloser {
  fn Close() -> Result<(), error>
  fn Read(mut p: Slice<uint8>) -> Partial<int, error>
  fn Seek(offset: int64, whence: int) -> Result<int64, error>
}

/// ReadSeeker is the interface that groups the basic Read and Seek methods.
pub interface ReadSeeker {
  fn Read(mut p: Slice<uint8>) -> Partial<int, error>
  fn Seek(offset: int64, whence: int) -> Result<int64, error>
}

/// ReadWriteCloser is the interface that groups the basic Read, Write and Close methods.
pub interface ReadWriteCloser {
  fn Close() -> Result<(), error>
  fn Read(mut p: Slice<uint8>) -> Partial<int, error>
  fn Write(p: Slice<uint8>) -> Partial<int, error>
}

/// ReadWriteSeeker is the interface that groups the basic Read, Write and Seek methods.
pub interface ReadWriteSeeker {
  fn Read(mut p: Slice<uint8>) -> Partial<int, error>
  fn Seek(offset: int64, whence: int) -> Result<int64, error>
  fn Write(p: Slice<uint8>) -> Partial<int, error>
}

/// ReadWriter is the interface that groups the basic Read and Write methods.
pub interface ReadWriter {
  fn Read(mut p: Slice<uint8>) -> Partial<int, error>
  fn Write(p: Slice<uint8>) -> Partial<int, error>
}

/// Reader is the interface that wraps the basic Read method.
/// 
/// Read reads up to len(p) bytes into p. It returns the number of bytes
/// read (0 <= n <= len(p)) and any error encountered. Even if Read
/// returns n < len(p), it may use all of p as scratch space during the call.
/// If some data is available but not len(p) bytes, Read conventionally
/// returns what is available instead of waiting for more.
/// 
/// When Read encounters an error or end-of-file condition after
/// successfully reading n > 0 bytes, it returns the number of
/// bytes read. It may return the (non-nil) error from the same call
/// or return the error (and n == 0) from a subsequent call.
/// An instance of this general case is that a Reader returning
/// a non-zero number of bytes at the end of the input stream may
/// return either err == EOF or err == nil. The next Read should
/// return 0, EOF.
/// 
/// Callers should always process the n > 0 bytes returned before
/// considering the error err. Doing so correctly handles I/O errors
/// that happen after reading some bytes and also both of the
/// allowed EOF behaviors.
/// 
/// If len(p) == 0, Read should always return n == 0. It may return a
/// non-nil error if some error condition is known, such as EOF.
/// 
/// Implementations of Read are discouraged from returning a
/// zero byte count with a nil error, except when len(p) == 0.
/// Callers should treat a return of 0 and nil as indicating that
/// nothing happened; in particular it does not indicate EOF.
/// 
/// Implementations must not retain p.
pub interface Reader {
  fn Read(mut p: Slice<uint8>) -> Partial<int, error>
}

/// ReaderAt is the interface that wraps the basic ReadAt method.
/// 
/// ReadAt reads len(p) bytes into p starting at offset off in the
/// underlying input source. It returns the number of bytes
/// read (0 <= n <= len(p)) and any error encountered.
/// 
/// When ReadAt returns n < len(p), it returns a non-nil error
/// explaining why more bytes were not returned. In this respect,
/// ReadAt is stricter than Read.
/// 
/// Even if ReadAt returns n < len(p), it may use all of p as scratch
/// space during the call. If some data is available but not len(p) bytes,
/// ReadAt blocks until either all the data is available or an error occurs.
/// In this respect ReadAt is different from Read.
/// 
/// If the n = len(p) bytes returned by ReadAt are at the end of the
/// input source, ReadAt may return either err == EOF or err == nil.
/// 
/// If ReadAt is reading from an input source with a seek offset,
/// ReadAt should not affect nor be affected by the underlying
/// seek offset.
/// 
/// Clients of ReadAt can execute parallel ReadAt calls on the
/// same input source.
/// 
/// Implementations must not retain p.
pub interface ReaderAt {
  fn ReadAt(mut p: Slice<uint8>, off: int64) -> Partial<int, error>
}

/// ReaderFrom is the interface that wraps the ReadFrom method.
/// 
/// ReadFrom reads data from r until EOF or error.
/// The return value n is the number of bytes read.
/// Any error except EOF encountered during the read is also returned.
/// 
/// The [Copy] function uses [ReaderFrom] if available.
pub interface ReaderFrom {
  fn ReadFrom(r: Reader) -> Result<int64, error>
}

/// RuneReader is the interface that wraps the ReadRune method.
/// 
/// ReadRune reads a single encoded Unicode character
/// and returns the rune and its size in bytes. If no character is
/// available, err will be set.
pub interface RuneReader {
  fn ReadRune() -> Result<(int32, int), error>
}

/// RuneScanner is the interface that adds the UnreadRune method to the
/// basic ReadRune method.
/// 
/// UnreadRune causes the next call to ReadRune to return the last rune read.
/// If the last operation was not a successful call to ReadRune, UnreadRune may
/// return an error, unread the last rune read (or the rune prior to the
/// last-unread rune), or (in implementations that support the [Seeker] interface)
/// seek to the start of the rune before the current offset.
pub interface RuneScanner {
  fn ReadRune() -> Result<(int32, int), error>
  fn UnreadRune() -> Result<(), error>
}

/// SectionReader implements Read, Seek, and ReadAt on a section
/// of an underlying [ReaderAt].
pub type SectionReader

/// Seeker is the interface that wraps the basic Seek method.
/// 
/// Seek sets the offset for the next Read or Write to offset,
/// interpreted according to whence:
/// [SeekStart] means relative to the start of the file,
/// [SeekCurrent] means relative to the current offset, and
/// [SeekEnd] means relative to the end
/// (for example, offset = -2 specifies the penultimate byte of the file).
/// Seek returns the new offset relative to the start of the
/// file or an error, if any.
/// 
/// Seeking to an offset before the start of the file is an error.
/// Seeking to any positive offset may be allowed, but if the new offset exceeds
/// the size of the underlying object the behavior of subsequent I/O operations
/// is implementation-dependent.
pub interface Seeker {
  fn Seek(offset: int64, whence: int) -> Result<int64, error>
}

/// StringWriter is the interface that wraps the WriteString method.
pub interface StringWriter {
  fn WriteString(s: string) -> Result<int, error>
}

/// WriteCloser is the interface that groups the basic Write and Close methods.
pub interface WriteCloser {
  fn Close() -> Result<(), error>
  fn Write(p: Slice<uint8>) -> Partial<int, error>
}

/// WriteSeeker is the interface that groups the basic Write and Seek methods.
pub interface WriteSeeker {
  fn Seek(offset: int64, whence: int) -> Result<int64, error>
  fn Write(p: Slice<uint8>) -> Partial<int, error>
}

/// Writer is the interface that wraps the basic Write method.
/// 
/// Write writes len(p) bytes from p to the underlying data stream.
/// It returns the number of bytes written from p (0 <= n <= len(p))
/// and any error encountered that caused the write to stop early.
/// Write must return a non-nil error if it returns n < len(p).
/// Write must not modify the slice data, even temporarily.
/// 
/// Implementations must not retain p.
pub interface Writer {
  fn Write(p: Slice<uint8>) -> Partial<int, error>
}

/// WriterAt is the interface that wraps the basic WriteAt method.
/// 
/// WriteAt writes len(p) bytes from p to the underlying data stream
/// at offset off. It returns the number of bytes written from p (0 <= n <= len(p))
/// and any error encountered that caused the write to stop early.
/// WriteAt must return a non-nil error if it returns n < len(p).
/// 
/// If WriteAt is writing to a destination with a seek offset,
/// WriteAt should not affect nor be affected by the underlying
/// seek offset.
/// 
/// Clients of WriteAt can execute parallel WriteAt calls on the same
/// destination if the ranges do not overlap.
/// 
/// Implementations must not retain p.
pub interface WriterAt {
  fn WriteAt(p: Slice<uint8>, off: int64) -> Partial<int, error>
}

/// WriterTo is the interface that wraps the WriteTo method.
/// 
/// WriteTo writes data to w until there's no more data to write or
/// when an error occurs. The return value n is the number of bytes
/// written. Any error encountered during the write is also returned.
/// 
/// The Copy function uses WriterTo if available.
pub interface WriterTo {
  fn WriteTo(w: Writer) -> Result<int64, error>
}

/// Seek whence values.
const SeekCurrent = 1

/// Seek whence values.
const SeekEnd = 2

/// Seek whence values.
const SeekStart = 0

pub var Discard: Writer

/// EOF is the error returned by Read when no more input is available.
/// (Read must return EOF itself, not an error wrapping EOF,
/// because callers will test for EOF using ==.)
/// Functions should return EOF only to signal a graceful end of input.
/// If the EOF occurs unexpectedly in a structured data stream,
/// the appropriate error is either [ErrUnexpectedEOF] or some other error
/// giving more detail.
pub var EOF: error

/// ErrClosedPipe is the error used for read or write operations on a closed pipe.
pub var ErrClosedPipe: error

/// ErrNoProgress is returned by some clients of a [Reader] when
/// many calls to Read have failed to return any data or error,
/// usually the sign of a broken [Reader] implementation.
pub var ErrNoProgress: error

/// ErrShortBuffer means that a read required a longer buffer than was provided.
pub var ErrShortBuffer: error

/// ErrShortWrite means that a write accepted fewer bytes than requested
/// but failed to return an explicit error.
pub var ErrShortWrite: error

/// ErrUnexpectedEOF means that EOF was encountered in the
/// middle of reading a fixed-size block or data structure.
pub var ErrUnexpectedEOF: error

impl LimitedReader {
  fn Read(self: Ref<LimitedReader>, mut p: Slice<uint8>) -> Partial<int, error>
}

impl OffsetWriter {
  fn Seek(self: Ref<OffsetWriter>, offset: int64, whence: int) -> Result<int64, error>

  fn Write(self: Ref<OffsetWriter>, p: Slice<uint8>) -> Partial<int, error>

  fn WriteAt(self: Ref<OffsetWriter>, p: Slice<uint8>, off: int64) -> Partial<int, error>
}

impl PipeReader {
  /// Close closes the reader; subsequent writes to the
  /// write half of the pipe will return the error [ErrClosedPipe].
  #[allow(unused_result)]
  fn Close(self: Ref<PipeReader>) -> Result<(), error>

  /// CloseWithError closes the reader; subsequent writes
  /// to the write half of the pipe will return the error err.
  /// 
  /// CloseWithError never overwrites the previous error if it exists
  /// and always returns nil.
  fn CloseWithError(self: Ref<PipeReader>, err: error) -> Result<(), error>

  /// Read implements the standard Read interface:
  /// it reads data from the pipe, blocking until a writer
  /// arrives or the write end is closed.
  /// If the write end is closed with an error, that error is
  /// returned as err; otherwise err is EOF.
  fn Read(self: Ref<PipeReader>, mut data: Slice<uint8>) -> Partial<int, error>
}

impl PipeWriter {
  /// Close closes the writer; subsequent reads from the
  /// read half of the pipe will return no bytes and EOF.
  #[allow(unused_result)]
  fn Close(self: Ref<PipeWriter>) -> Result<(), error>

  /// CloseWithError closes the writer; subsequent reads from the
  /// read half of the pipe will return no bytes and the error err,
  /// or EOF if err is nil.
  /// 
  /// CloseWithError never overwrites the previous error if it exists
  /// and always returns nil.
  fn CloseWithError(self: Ref<PipeWriter>, err: error) -> Result<(), error>

  /// Write implements the standard Write interface:
  /// it writes data to the pipe, blocking until one or more readers
  /// have consumed all the data or the read end is closed.
  /// If the read end is closed with an error, that err is
  /// returned as err; otherwise err is [ErrClosedPipe].
  fn Write(self: Ref<PipeWriter>, data: Slice<uint8>) -> Partial<int, error>
}

impl SectionReader {
  /// Outer returns the underlying [ReaderAt] and offsets for the section.
  /// 
  /// The returned values are the same that were passed to [NewSectionReader]
  /// when the [SectionReader] was created.
  fn Outer(self: Ref<SectionReader>) -> (ReaderAt, int64, int64)

  fn Read(self: Ref<SectionReader>, mut p: Slice<uint8>) -> Partial<int, error>

  fn ReadAt(self: Ref<SectionReader>, mut p: Slice<uint8>, off: int64) -> Partial<int, error>

  fn Seek(self: Ref<SectionReader>, offset: int64, whence: int) -> Result<int64, error>

  /// Size returns the size of the section in bytes.
  fn Size(self: Ref<SectionReader>) -> int64
}