rust-system-calls

Guide Rust code to use bun_sys for cross-platform file I/O and system calls.

95.8k|5.0k|Updated Apr 14, 2021
One-click install
npx skills add https://github.com/oven-sh/bun --skill rust-system-calls
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: rust-system-calls
Source: https://github.com/oven-sh/bun/tree/main/.claude/skills/rust-system-calls
Command: npx skills add https://github.com/oven-sh/bun --skill rust-system-calls

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Writing cross-platform file I/O in Bun's Rust codebase is error-prone when using std::fs or raw libc, leading to lossy errors, missing Windows support, and manual EINTR handling. This Skill enforces a consistent syscall layer.

Core Features & Use Cases

  • bun_sys::File wrapper: Owns the file descriptor and closes on Drop, replacing std::fs::File with Node-compatible error metadata.
  • Rich Error type: Carries errno, syscall tag, and path so failures can be converted to JS exceptions via ErrorJsc::to_js.
  • Path buffer pooling: Uses bun_paths path_buffer_pool to avoid 64 KB stack allocations on Windows.
  • Use Case: When implementing a new Bun native module that reads or writes files, follow this Skill to choose the correct open flags, propagate errors with ?, and avoid double-close pitfalls.

Quick Start

Implement file I/O in Bun's Rust code using bun_sys::File with openat and propagate errors via Maybe<T> instead of std::fs.

Frequently Asked Questions about rust-system-calls

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I open a file in Bun's Rust code?

Use bun_sys::File::openat(Fd::cwd(), path, O::RDONLY, 0) instead of std::fs::File::open. The File wrapper owns the fd, closes on Drop, and returns Maybe<T> with errno, syscall tag, and path attached to errors.

bun_sys vs std::fs for Rust file operations?

bun_sys returns Maybe<T> with rich Error metadata including errno and syscall tag, supports Windows via libuv fallback, retries on EINTR automatically, and accepts &[u8] WTF-8 paths. std::fs returns lossy io::Error and lacks full Windows coverage.

Does bun_sys support Windows file operations?

Yes, bun_sys provides full Windows support through a libuv fallback layer. Use path_buffer_pool::get() to avoid 64 KB stack allocations that occur with PathBuffer on Windows hot paths.

Why should I avoid std::fs::File in Bun's Rust code?

std::fs::File loses the syscall tag and path needed to construct Node-compatible error objects. It also lacks automatic EINTR retry and produces lossy io::Error values that cannot be cleanly converted to JS exceptions.

How to convert bun_sys errors to JavaScript exceptions?

Use bun_sys_jsc::ErrorJsc::to_js on a bun_sys::Error to produce a JS exception. Match on the Result from File::openat and return err.to_js(global)? to propagate the error with errno and path preserved.