Version: 1.1.0

Conversions cheat sheet

Make a value, convert a value, or borrow a value. Those are different operations.

Essentials

  • Constructors build a new value: String("hi").
  • Numeric casts change representation and can lose range.
  • Span borrows a contiguous buffer without copying.
  • Python conversions go through PythonObject.
  • Implicit conversion only happens for initializers marked @implicit.

Example

def main():
    var n = Int(3.9)
    var text = String("3")
    print(n, text)

Keep in mind

Casts are visible on purpose. A silent narrowing conversion is how numeric bugs hide.