Silk

silk/native_descriptor

Profiles: aarch64-unknown-linux-gnu, x86_64-unknown-linux-gnu.

Borrowed native descriptor transfers through selected libc declarations.

When to use

Use NativeDescriptor to build native byte-stream providers without owning the descriptor. Use silk.writer.Writer and silk.standard_input.StandardInput for replaceable portable services.

Details

The selected Darwin and GNU providers use 32-bit descriptors and pointer-width transfer counts. Transfers are bounded to 0x7ffff000 bytes per call. Interrupted calls retry without advancing; only a failed call reads native error state. Empty operations make no foreign call.

Gotchas

The caller controls descriptor lifetime and synchronization. These operations never close it. Native declarations are absent on WebAssembly and no-libc profiles. A failed complete write may already have committed a prefix; failure does not roll it back.

Examples

Complete an empty write without touching standard output

import silk.native_descriptor { NativeDescriptor }
pub fn main() -> i32 {
  let mut nativeError = 0
  let completed = run NativeDescriptor.writeAll(1, b"", &mut nativeError)
  if completed { return 42 }
  return 1
}

Import as NativeDescriptor with import silk.native_descriptor { NativeDescriptor }.

Public declarations: 4.

read

pub unsafe extern "C" fn read(fd: i32, buffer: ?[*]mut u8, count: usize) -> isize as "read" with Intrinsic.foreign(noCapture: ("buffer",))

Reads at most count bytes through a borrowed process descriptor.

Gotchas

The caller must keep count writable bytes live for the call. A negative result requires immediate native error capture; a nonnegative result is the initialized prefix length.

write

pub unsafe extern "C" fn write(fd: i32, buffer: ?[*]const u8, count: usize) -> isize as "write" with Intrinsic.foreign(noCapture: ("buffer",))

Writes at most count readable bytes through a borrowed process descriptor.

Gotchas

The caller must keep count readable bytes live for the call. A negative result requires immediate native error capture. A positive result may be shorter than count.

__errno_location

pub unsafe extern "C" fn __errno_location() -> *mut i32 as "__errno_location"

Returns the current thread's GNU error slot; read it immediately after a failed call.

NativeDescriptor

pub struct NativeDescriptor

Byte-transfer policy for borrowed native descriptors with no resource ownership.

Associated function NativeDescriptor.read

pub effect<'env> fn read<'life0: 'env, 'life1: 'env, 'life2: 'env, 'env>(fd: i32, buffer: &'life0 mut [u8], count: &'life1 mut usize, error: &'life2 mut i32) -> bool

Reads one committed prefix, retrying interrupted calls without advancing the buffer.

Details

Success stores the exact prefix length in count; zero capacity succeeds with zero bytes. Failure stores zero in count and captures a native error in error, or zero for an invalid transfer count. Bytes beyond a successful prefix retain their initial values.

Associated function NativeDescriptor.writeAll

pub effect<'env> fn writeAll<'life0: 'env, 'life1: 'env, 'env>(fd: i32, buffer: &'life0 [u8], error: &'life1 mut i32) -> bool

Completes a byte sequence by advancing only after positive transfers.

Details

Success leaves error zero. Failure stores the native error, or zero for zero progress or an invalid transfer count. Empty input succeeds without a call.

Gotchas

Failure can follow a committed prefix. The caller must not retry the whole message blindly.

On this page