Files
oxc-project__oxc/crates/oxc_data_structures/README.md
overlookmotel 7e9b84a1dc feat(data_structures): add implements! macro (#24721)
Add an `implements!` macro which answers "does type X implement trait Y?".

Primarily this is useful in tests, but can also be used in macros to produce specialized code paths.

```rust
assert!(implements!(Ident: Send));
assert!(implements!(Ident: Sync));
assert!(implements!(Allocator: !Sync));
```

Also works in const context:

```rust
const U32_IS_COPY: bool = implements!(u32: Copy);
const _: () = assert!(U32_IS_COPY);
```

Particularly useful for checking that a type does _not_ implement a trait. Without this macro, that requires a `compile_fail` doctest, which is fragile - when code changes, the doctest can easily start failing for _different_ reasons, which means it's no longer testing what it's meant to, and there's no way to spot that.

This is a primitive required for forthcoming `MultiVec` SoA vec type. Putting it in `oxc_data_structures` as it can be useful in other places too.
2026-07-20 12:36:14 +00:00

1.9 KiB

Oxc Data Structures

Common data structures and utilities used across oxc crates.

Overview

This crate provides specialized data structures and utilities that are used throughout the oxc toolchain. These structures are optimized for the specific needs of compiler and tooling workloads.

Key Features

  • Stacks: Efficient stack types, optimized for fast push, pop, and last
  • Code buffer: Efficient string building with segment tracking
  • Inline strings: Memory-efficient string storage for short strings
  • Slice iterators: Enhanced iteration capabilities for slices
  • Rope data structure: Efficient text manipulation for large documents
  • Box macros: Macros for creating boxed arrays / slices (similar to vec! macro)
  • Fieldless enums macro: Macro for creating enums with a VARIANTS constant listing all variants
  • Non-null pointers: NonNullConst<T> and NonNullMut<T> - non-null pointer types with explicit const/mut permissions
  • Branch prediction hints: likely and unlikely functions to hint to the compiler whether a branch is likely to be taken (also re-exports std::hint::cold_path)
  • StringExt trait: Add methods to String to push without capacity checks
  • String utilities: const-compatible string helpers (e.g. const_str_eq for comparing strings in a const context)
  • Type utilities: implements! macro to determine if a type implements a trait

Architecture

These data structures are designed with specific compiler requirements in mind:

  • Performance: Optimized for common patterns in parsing and code generation
  • Memory efficiency: Minimize allocations and memory overhead
  • Safety: Provide safe abstractions over potentially unsafe operations
  • Ergonomics: Easy to use APIs that integrate well with other oxc components

The structures complement Rust's standard library with domain-specific optimizations for JavaScript/TypeScript tooling.