Net
module Net
Shared networking values, capability discovery, and typed failures.
using Net
let https = Port.from(443).try
if Support.current.tls.usable? then https.string else "TLS unavailable" end
record Port
A validated TCP or UDP port number in 0..65535.
Use Port.from at input boundaries. Port zero requests an ephemeral port where a listening API permits it; after binding, ask the server or socket for the concrete port the operating system chose.
Fields
valueInteger
record SupportValue
Whether a feature was compiled into this backend and is usable now.
compiled? describes the build; usable? also accounts for the environment it is running in. A browser build may contain an HTTP client, for example, while browser policy still prevents a particular lower-level capability.
Fields
compiled?Boolusable?Bool
record SupportReport
Granular networking capabilities for the current backend and environment.
Read this before choosing a transport dynamically. Applications that require one capability can instead check that single field during startup and fail with a useful message.
Fields
dnsSupportValuetcpSupportValueudpSupportValueunixSupportValuetlsSupportValuehttpClientSupportValuehttpServerSupportValuewebSocketClientSupportValuewebSocketServerSupportValue
module Net.Port
Validated Port construction.
function from
Validates a port number.
from(value) : Integer -> Result<Port, NetError>
Parameters
valueInteger- a number in
0..65535
Returns: Result<Port, NetError> — the validated port, or Parse
Examples
Reading a listen port from the environment
let number = ENV.get("PORT").flatMap { |text| text.to(Integer) }.or(8080)
let port = Port.from(number).try
module Net.Support
Runtime discovery for optional network transports and protocols.
constant current SupportReport
Reports compiled and currently usable networking features.
type NetOperation
The subsystem or operation that produced a networking error.
Variants
DNSTCPUDPUnixTLSHTTPClientHTTPServerWebSocketClientWebSocketServer
type NetErrorKind
Stable, backend-independent networking failure categories.
Variants
ParseResolveConnectProtocolTimeoutCancelledLimitClosedReadInProgressUnsupportedBackendUnsupportedOptionBrowserRestrictedOpaqueRedirectMockEmptyBackend
record NetError
A typed networking failure shared by every network module.
kind is the stable category to branch on. message is for a person, while phase adds protocol context such as a TLS handshake and progress records bytes transferred before a partial-operation failure. Keeping those roles separate lets programs recover without matching backend-specific prose.
Fields
kindNetErrorKindoperationNetOperationmessageStringphaseString?progressInteger?
make Port
Submodules
Net.DNSTyped DNS lookup with explicit resolver ownership and bounded caching.Net.HTTPBuffered HTTP clients, responses, and a small declaration-ordered server router. Requests never follow redirects or perform generic retries implicitly.Net.HTTP.WebSocketHigh-level RFC 6455 client messages. The runtime handles fragmentation and ping/pong frames; reconnect and heartbeat policies remain application-owned.Net.IPValidated, canonical IP addresses and CIDR networks.Net.SocketProcess-owned TCP byte streams and listeners. All blocking operations return typedNetErrorvalues; close operations are idempotent.