truncate

package
v0.17.0-alpha.4 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 31, 2026 License: MIT Imports: 1 Imported by: 0

Documentation

Overview

Package truncate carries the shared cut mechanics for bounded serving (d-tac-qwc): pure functions that cut strings and item slices against byte or count caps, and the Cut accounting record every bound firing produces. Data stays separated from meta — a carrier pairs the payload with its Cut, so consumers render the payload while the cut travels out of band and each surface phrases its notice in its own register. This package carries no notice wording.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Carrier

type Carrier interface {
	Payload() any
	CutMeta() Cut
}

Carrier pairs a payload with its cut meta. A seam that receives one hands the payload on unchanged and routes the meta out of band.

type Cut

type Cut struct {
	// Part names what was cut — a lane, an inject id, a store field. Left to
	// the seam that knows the name; producers leave it empty.
	Part string
	// Dropped and Total count whole items on item cuts; zero on byte cuts.
	Dropped, Total int
	// KeptBytes and TotalBytes account the byte weight after and before.
	KeptBytes, TotalBytes int
	// Pull is a ready-to-run expression for the remainder; empty when none
	// applies.
	Pull string
}

Cut is the accounting record of one bound firing: what remains, what was dropped, and how to pull the remainder. The zero value means clean.

func (Cut) Clean

func (c Cut) Clean() bool

Clean reports whether the bound dropped nothing.

type List

type List[T any] struct {
	Items []T
	Cut   Cut
}

List carries items and their cut meta; templates and projections consume Items, never the meta.

func Head[T any](items []T, maxItems int, pull string) List[T]

Head keeps the first maxItems items — the count cut for typed data whose rendered size is unknowable before a template renders it; byte safety comes from measured allowances and the serve-size regression harness. maxItems <= 0 means unbounded.

func Items

func Items[T any](items []T, size func(T) int, maxBytes int, pull string) List[T]

Items keeps whole items, in order, while their rendered sizes fit maxBytes — the byte-precise cut for producer-rendered chunks. size measures one item as it will be rendered. maxBytes <= 0 means unbounded.

func (List[T]) CutMeta

func (l List[T]) CutMeta() Cut

func (List[T]) Payload

func (l List[T]) Payload() any

type Text

type Text struct {
	Text string
	Cut  Cut
}

Text carries rendered text and its cut meta.

func Bytes

func Bytes(s string, maxBytes int, pull string) Text

Bytes cuts rendered text at a line boundary under maxBytes, backing up to a rune start when the first line alone exceeds the cap, so a multi-byte rune is never split. maxBytes <= 0 means unbounded.

func (Text) CutMeta

func (t Text) CutMeta() Cut

func (Text) Payload

func (t Text) Payload() any

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL