Repository navigation
Conversions
Use Target(value) for an explicit conversion. An annotation is a constraint,
with supported Integer-to-Float promotion and nominal wrapping; it is not a
request to parse arbitrary text.
let $quantity = Integer("14")
let $ratio = Float("2.5")
echo ($quantity + 1) $ratio Integer(6.0)
15 2.5 6
Integer conversion accepts integral finite Floats, decimal integer text, Boolean,
and numeric process statuses. Fractional Floats, out-of-range values, and decimal
text such as "2.5" are rejected. Number preserves an existing numeric kind.
String removes executable markers from its text result.
For Target(source), lookup tries:
-
Target::from_<source_type>(source). -
Source::to_<target_type>(), with a private receiver copy. - Built-in conversion rules.
An existing hook's failure propagates. It does not silently try another path.
Factories take one explicit source argument and have no $self. Source-owned
methods use $self and take no arguments.
struct Batch { pub count: Integer }
fn Batch::to_integer(): Integer { $self.count }
fn String::from_batch($batch: Batch): String
{
"batch=" + String($batch.count)
}
let $batch = Batch(count: 6)
echo Integer($batch) String($batch)
6 batch=6
Names use snake case: ExecResult becomes exec_result, HTTPResponse becomes
http_response. Incorrect forms such as to_execresult are rejected.
Collection names include their types: array_integer, hash_string_integer.
A typedef supplies an overridable factory from its immediate underlying type.
Named conversions and imported extensions participate in the same dispatch.
Source-side conversions operate on a copy so changing $self cannot mutate the
original value merely because it was converted.
The prelude converts colon-separated text to [String] and arrays to text using
Array::from_string / Array::to_string. let type remembers both directions for
an environment binding.
Pipeline format hooks are String::from_<format> and
<format>::from_string. Those are explicit byte/value boundaries; see
Pipeline formats.
Related: Named types · Environment · Pipeline formats
Begin here
Values and expressions
- Language basics
- Variables and scope
- Numbers and logic
- Strings and paths
- Arrays
- Hash maps
- Ranges and iteration
- Control flow
- Match and type guards
Functions and types
- Functions and calls
- Closures and function types
- Methods and properties
- Structs
- Enums
- Named types and unions
- Conversions
- Types and properties
Shell and modules
- Pipelines
- Pipeline splits
- Pipeline formats
- Commands and exit status
- Redirection
- Environment and exported variables
- Modules and visibility
- Nested modules and directory packages
- Conditional imports and declarations
- Errors and cleanup
- Supervised processes and terminals
Library guides
- Standard library
- The implicit prelude
- Bytes, files, readers, and writers
- Explicit item streams
- JSON documents and typed mapping
- Sockets, DNS, and TLS
- HTTP clients
- HTTP servers
- Framing, server-sent events, and JSON-RPC
- Terminal colors, styles, and geometry
- Build an application console
Interactive use