Turkey library
Algorithm.Hash
FNV-1a over 64 bits.
Base64
Base64 as RFC 4648 §4 defines it: the standard alphabet,
A-Z a-z 0-9 + /,
with = padding.Bits
The bitwise operators, a class each like the arithmetic ones, so that a type
can have some of them without the rest: a set has union, intersection and
symmetric difference, and nothing to shift.
Bytes
A
ByteView is a run of bytes that can be read and not written: it has
Index, Length and Iterator, and no SetIndex. Nothing here gives
back the storage it reads.Data.BitSet
A set of the integers
0 .. capacity - 1, one bit each, in 64-bit words.Data.Float.Text
Float to text and back: the shortest decimal that reads back as the same
Float, and the correctly rounded Float nearest a decimal.Data.Int
The 64-bit signed integer, which the compiler provides.
Data.Num
The arithmetic operators, a class each, so that a type can have
+ without
having /.Data.String
A
String is an immutable sequence of bytes that is guaranteed to be
well-formed UTF-8. That is the whole model, and every operation here is
judged by whether it preserves the invariant. It is not "a sequence of
characters" and not "a sequence of code points" -- the code points are a
view, and so are the bytes.Data.Vec
The growable array:
push and pop change its length.Debug
Text for a programmer to read: a value as Turkey syntax would build it.
Deque
A double-ended queue: elements are pushed and popped at either end in
constant time, amortized over the growth of its storage, and read at any
index in constant time. Index 0 is the front.
Hash.FoldHash
foldhash's fast variant (foldhash-f), the default hasher of Rust's
hashbrown: every step is one folded multiply of the input xored with the
state and a secret.
Hash.FxHash
rustc-hash 2.x, the hasher inside the Rust compiler: one add and one
multiply per word, and a rotation at the end.
Hash.SHA256
SHA-256, as FIPS 180-4 specifies it: a Merkle-Damgard construction over
512-bit blocks, with a 256-bit state of eight 32-bit words.
Hash.SipHash
SipHash-1-3 (Aumasson and Bernstein): one compression round per 8-byte
block and three at the end, the variant Rust's
HashMap, Python and Swift
use. Unlike the others in Hash it is a keyed pseudorandom function, so an
attacker who sees no hash values cannot build keys that collide.Hash.Words
The word operations the hash functions in
Hash share. All of them wrap: a
hash is supposed to overflow.Net
Names to addresses, and where a program may connect: what a host name
stands for, as the system's resolver says, and which of those addresses a
policy lets a connection reach.
Net.TCP connects to what resolve
answers.Net.HTTP
HTTP's protocol values: methods, statuses, header fields, URLs, requests,
and the bodies and responses that go with them, shared by the HTTP/1
codec, the client and the server. Nothing here opens a connection.
Net.HTTP.Body
What a client can send as a request body, and the methods that carry one.
Net.HTTP.Client
An HTTP/1.1 client: requests sent over a pool of connections, each one
reaching only what a
ConnectPolicy allows.Net.HTTP.Cookie
A cookie as a
Set-Cookie header sets it (RFC 6265 §4.1): a name, a value,
and attributes such as Path=/, Secure and HttpOnly.Net.HTTP.Credentials
What an
Authorization header carries (RFC 9110 §11.4): a scheme, and the
scheme's own data.Net.HTTP.Date
HTTP dates in the preferred format of RFC 9110 §5.6.7, IMF-fixdate:
Sun, 06 Nov 1994 08:49:37 GMT, always in UTC, always 29 bytes.Net.HTTP.Duplex
A connection after it switched protocols: what the peer sends next, and
what this side writes back, in the protocol both agreed to. A server's
switch and a client's upgrade both hand one over.Net.HTTP.Error
What goes wrong in HTTP, and how a caller's own error type takes it in.
Net.HTTP.H1.Body
An HTTP/1 message body as a
Read: the bytes after a head, decoded from
their framing, ending exactly where the message ends, so that what follows
is the next message.Net.HTTP.H1.Classes
The byte classes of RFC 9110 and RFC 9112 as 256-entry tables, and the scan
loop every part of the HTTP/1 codec reads them with. A table is an array
indexed by the byte, so a class test is one load.
Net.HTTP.H1.Head
Stage 2 of the HTTP/1 head parser: one pass over a complete head, by hand,
with the byte classes of
Net.HTTP.H1.Classes. Net.HTTP.H1.Input is
stage 1, which finds where the head ends.Net.HTTP.H1.Input
The reading side of an HTTP/1 connection: the bytes read from a stream and
not yet consumed, and stage 1 of the head parser, which finds where a head
ends.
Net.HTTP.H1.Output
The writing side of HTTP/1: heads written from the HTTP values, and a body
writer that frames what a program writes.
Net.HTTP.H1.Pool
A client's connections: plain or TLS, read and written under its limits,
and kept between requests in a pool per origin.
Net.HTTP.HTTPURL
A URL an HTTP request can be sent to:
http or https, with a host.Net.HTTP.HeaderName
The name of a header field: a token, stored lowercase, since field names
are case-insensitive and HTTP/2 sends them lowercase.
Net.HTTP.HeaderValue
The value of a header field, as it is sent: visible bytes, with spaces and
tabs between them but not around them (RFC 9110 §5.5).
Net.HTTP.Headers
Header fields, typed.
Net.HTTP.Incoming
A message body that has arrived and not been read: a request's, for a
server's handler, or a response's, for a client's callback.
Net.HTTP.Limits
How much of a peer's message HTTP reads before it refuses or gives up, and
how long it waits.
Net.HTTP.MediaType
A media type (RFC 9110 §8.3.1):
text/html; charset=utf-8, what a
Content-Type says a body is, and what an Accept asks for.Net.HTTP.Method
A request method, carrying the request's body where the method has one.
Net.HTTP.Payload
A request body as the client sends it: whether it can be sent again, and
a function that makes the
Stream to send each time. The client sends a
ClientRequest Payload; the Body instances (Net.HTTP.Body) make one
with text, bytes, file, incoming and stream.Net.HTTP.Request
Requests, as a server receives them and as a client sends them: a method,
which carries the body, a target, and header fields.
Net.HTTP.Response
A response a client received: its status, its header fields, its body,
which a client's callback reads as an
Incoming, the URL it came from,
and how long each part of getting it took.Net.HTTP.Server
An HTTP/1 server: connections taken from a
Net.Listener, each served by
a task of its own, its requests read and responded to in order, one at a
time.Net.HTTP.ServerResponse
What a server sends in response to a request: a status, header fields,
and a body, which
Net.HTTP.Server's respond writes.Net.HTTP.Status
A response's status. Every code the IANA registry gives a current name
has a constructor, named after its reason phrase as RFC 9110 gives it
(
ContentTooLarge for 413, UnprocessableContent for 422), so a response
is matched by name:Net.HTTP.Stream
A body that a program writes as it goes, for a server's response or a
client's request: its length, if it knows it, and a function that writes
the bytes into a
Sink.Net.HTTP.Syntax
The small grammars of RFC 9110 that header values are written in: tokens,
quoted strings, parameters and comma-separated lists.
Net.HTTP.Token
A token (RFC 9110 §5.6.2): one or more of the bytes HTTP allows in a name,
the letters, digits and
!#$%&'*+-.^_`|~. Method names, media types,
authentication schemes and parameter names are tokens.Net.Memory
Connections that never leave the program: two ends of a
Pipe, each a
Net.Connection as a TCP socket is, and a Listener that hands out the
far end of each connect. For testing a server or a protocol without a
socket, a port, or a network.Net.TCP
TCP connections: a
Socket to read and write, and a Listener that
accepts them.Net.TLS
TLS over any connection: a client that verifies the server it reaches, a
server that presents a certificate chosen by the name the client asks for,
and a
TLS connection that is read and written like the one under it.PriorityQueue
A queue that pops its least element first:
push and pop take
O(log n) time, peek O(1), and fromArray builds a queue in O(n).Process
Running another program and collecting what it says: its standard output
and standard error as bytes, kept apart, and how it ended.
Regex
A
Builder describes a pattern, compile assembles one into a Pattern,
and fullMatch runs a Pattern against a whole string. Capture values are
recipes, evaluated only after a successful match.
See examples/regex/README.md for semantics, examples, and current limits.ScopedValue
Scoped values: a value bound for the extent of a call, which every call
inside it can read without being passed it.
Signal
Waiting for a signal: a task asks for the signals it wants with
listen,
and waits for the next of them as it waits for anything else, suspended
while its worker runs other tasks. No code of the program runs in signal
context, so what the task does about a signal -- stop a server, reopen a
log, read the terminal's new size -- is ordinary code.System.Args
A command line, read one argument at a time.
System.Env
The process's own environment: what it was asked to do, and how it answers.
System.File
Files, open: a
Read and a Write over a descriptor, with what can be
done to one in its type.System.IO
Streams of bytes, and the standard streams.
System.Parallel
Work spread over the workers that run tasks (
System.Task): a function of
each element of an array, and a graph of steps each run once the steps it
depends on have finished.System.Sync
What tasks that share data need when they run at once (
System.Task): a
mutex around a value, an integer changed atomically, a value computed once
however many tasks ask for it, a count of permits that bounds how many
tasks do something at once, a flag that tasks wait to see raised, and a
condition on a mutex's value that tasks wait to see hold.System.Task
Tasks: functions that run concurrently with the code that started them,
each suspending where it waits -- in
join, in yield, at any depth of
ordinary calls -- so that others run meanwhile. They run on a worker per
core, or on as many as the environment's TURKEY_WORKERS asks for: with
one, tasks interleave but never run in parallel, and nothing else runs
between two suspension points of one task, except while it waits in a call
the poller cannot carry -- a file read, flock -- long enough that another
thread takes over running the rest; with more, tasks run in parallel, and
what two of them share needs synchronizing.Target
The platform the program is being compiled for, as values a program can
match on:
Time
Dates and times. Each type has a module of its own, imported under the
type's name:
import Time.Date as Date (Date) gives Date.new and the bare
type, and likewise Time.DateTime, Time.Instant, Time.Duration,
Time.Period and the rest. This module is what they share.Time.Calendar
Day numbers of the proleptic Gregorian calendar: the conversion between a
(year, month, day) and the count of days since 1970-01-01, which is how
Date is stored. Everything here is total arithmetic; validating a date is
the caller's job.Time.Clock
The two clocks the system keeps. The library reads them here and nowhere
else, and each reading comes out as a type that says which clock it was: an
Instant for the first, a Reading for the second, which Stopwatch and
Deadline are made of.Time.Date
A date of the ISO calendar, with no time and no time zone: a birthday, a due
date, a holiday. Years run from -9999 to 9999.
Time.DateTime
An instant in a time zone: when something happens at a place. It has both
a position on the timeline and a reading of the calendar and the clock, and
moves both ways -- by elapsed time with
after, and by the calendar with
shift, which keeps the wall-clock time across a change to daylight saving
time.Time.Deadline
A point ahead on the monotonic clock, for a limit on how long something may
take: made once, from a
Duration, and then asked how much time is left,
so that a limit on a whole operation can be handed to each step of it.
Like a Stopwatch, it reads the clock that only moves forward, so setting
the system clock neither cuts it short nor stretches it, and it does not
turn into an Instant.Time.Duration
An exact amount of elapsed time, to the nanosecond: the distance between two
points on the timeline. Stored as a count of nanoseconds, so it spans about
292 years either way, and arithmetic on it panics on overflow as
Int's
does.Time.Frame
Seconds counted in the two frames a time zone moves between. A zone's rules
say when its transitions happen in UTC and what its clocks read at each, and
the arithmetic that relates the two is where an hour goes missing, so the
frames are separate types and an offset is the only way between them.
Time.ISO
The pieces of ISO 8601 text that more than one type reads or writes.
Time.Instant
A point on the global timeline, with no calendar and no time zone: when a
log line was written or a file changed. It has no year or hour of its own;
those depend on a zone.
Time.Month
A month of the ISO calendar. A sum rather than an
Int, so that a month
out of range is a type error where it is written rather than a check at run
time.Time.Offset
A difference from UTC, to the second:
-04:00 for New York in summer. East
of Greenwich is positive. Less than 26 hours either way, the range a POSIX
time zone rule can state.Time.Period
An amount of calendar time: whole months and whole days, each counted on
the calendar rather than as a fixed length. One month from January 31 is
February 28 or 29; one day across a change to daylight saving time is 23 or
25 hours. An amount of elapsed time is a
Duration instead.Time.PlainDateTime
A date and a wall-clock time with no time zone: "the 15th of next month at
09:00", wherever that turns out to be.
Time.Posix
POSIX time zone rules, the
TZ form: EST5EDT,M3.2.0,M11.1.0 is five hours
west of UTC, and an hour less from 02:00 on the second Sunday of March to
02:00 on the first Sunday of November. A TZif file ends with one of these,
which gives every transition after its table runs out; files written in the
default "slim" form rely on it for every year with a recurring rule.Time.Sleep
Pausing for a time:
sleep for a duration from now, sleepUntil for a
deadline. A sleeping task does not hold its worker, so other tasks run
meanwhile; from the program's own code, outside any task, the wait runs
other tasks until the time has passed. The time is read on the monotonic
clock, so setting the system clock neither shortens nor lengthens a sleep.Time.Stopwatch
A reading of the monotonic clock, for measuring how long something takes.
That clock only moves forward, at a steady rate, from an arbitrary start;
the system clock an
Instant reads can be set back or forward while a
program runs, so the difference between two instants is not a measurement.
A stopwatch has no date and does not turn into an instant.Time.TimeOfDay
A time on a wall clock, with no date and no time zone: "opens at 09:00".
From 00:00 up to but not including 24:00, to the nanosecond.
Time.Tzif
Time zone files, as the system keeps them under
/usr/share/zoneinfo: the
TZif format, version 2 or later.Time.Weekday
A day of the week. Weeks start on Monday, as in ISO 8601.
Time.Zone
A time zone: the rules that say what the clocks read at each instant in a
place. Either a fixed offset, a POSIX rule, or a table of transitions read
from the system's time zone files, followed by a POSIX rule.
URL
URLs as RFC 3986 defines them, for any scheme:
https://example.com/a?b,
mailto:someone@example.com, urn:isbn:0451450523.