Thanks to visit codestin.com
Credit goes to github.com

Skip to content

swift-primitives/swift-buffer-primitives

Buffer Primitives

Development Status CI

Buffer<S> — the buffer-discipline namespace, parameterized by the storage substrate S (any Storage.Protocol conformer). It is the shared root the buffer disciplines build on: Buffer.Linear (contiguous, front-to-back), Buffer.Ring (circular, wrap-around), Buffer.Slots (metadata-parametric random-access slots), and Buffer.Linked (generational linked list) — each shipped in its own package over this namespace.

This package carries the namespace and the capability protocol, not the disciplines themselves. Buffer.Protocol is the shared logical surface — count, plus a derived isEmpty — that every discipline exposes. It is a capability marker, not op-dispatch: the hot append / remove / subscript operations stay on the concrete discipline types, so the protocol adds no dispatch cost. It is also orthogonal to Storage.Protocol — a buffer has-a storage, it is not a kind-of storage — so physical surface (pointer(at:), capacity) stays in the storage layer. Code written against Buffer.Protocol reads occupancy uniformly across every discipline.


Key Features

  • One namespace, four disciplinesBuffer.Linear / Ring / Slots / Linked all live under Buffer<S>, each parameterized by the same storage substrate, so a substrate choice (heap, inline, shared) flows through unchanged.
  • count capability, dispatch-freeBuffer.Protocol exposes the logical count (in the discipline's natural counting domain) and a single default isEmpty; conforming costs nothing at the call site.
  • ~Copyable elements end to end — the namespace is ~Copyable-generic over its substrate; move-only elements are carried without an implicit copy.
  • Substrate-explicit composition — a discipline's full spelling names its substrate (Buffer<Storage<…>.Contiguous<Element>>.Ring), keeping the storage strategy visible rather than hidden behind a default.

Quick Start

Buffer.Protocol lets one algorithm range over every discipline:

import Buffer_Protocol_Primitives

// Works across Linear, Ring, Slots, and Linked alike.
func summary(of buffer: borrowing some Buffer.`Protocol` & ~Copyable) -> String {
    buffer.isEmpty ? "empty" : "\(buffer.count) element(s)"
}

The concrete disciplines live in their own packages — see Related Packages.


Installation

Add the dependency to your Package.swift:

dependencies: [
    .package(url: "https://github.com/swift-primitives/swift-buffer-primitives.git", branch: "main")
]

Add a product to your target:

.target(
    name: "App",
    dependencies: [
        .product(name: "Buffer Primitives", package: "swift-buffer-primitives")
    ]
)

The package is pre-1.0 — depend on branch: "main" until 0.1.0 is tagged. Requires Swift 6.3 and macOS 26 / iOS 26 / tvOS 26 / watchOS 26 / visionOS 26 (or the corresponding Linux / Windows toolchain).


Architecture

Product Contents When to import
Buffer Primitives Umbrella — re-exports the namespace and the protocol Most consumers
Buffer Primitive Buffer<S> — the discipline namespace over a storage substrate Naming the namespace directly
Buffer Protocol Primitives Buffer.Protocol — the shared count / isEmpty capability Writing code generic over disciplines

Platform Support

Platform CI Status
macOS 26 Yes Full support
Linux Yes Full support
Windows Yes Full support
iOS/tvOS/watchOS Supported
Swift Embedded Pending (nightly-toolchain follow-up)

Related Packages


Community

License

Apache 2.0. See LICENSE.md.

About

Dispatch-free capability protocol and shared namespace unifying Linear, Ring, Slots, and Linked buffer disciplines over a common storage substrate for Swift.

Topics

Resources

License

Code of conduct

Contributing

Security policy

Stars

0 stars

Watchers

0 watching

Forks

Releases

No releases published

Sponsor this project

 

Packages

 
 
 

Contributors

Languages