Skip to content
FutureBlitz

    Install

    Import std.core.load

    Loadable

    std.core.load

    interface

    Public Interface Loadable

    A type that makes itself from a Value, which Load<T> calls in place of filling its Fields.

    Examples

    // A temperature that loads from a number, and saves as one, rather than as an Object.
    Struct Celsius Implements Loadable, Saveable
        Field Degrees: Double
    
        Public Static Method FromValue(value: Value): Celsius Throws ParseError
            Local degrees = value.AsDouble()
            If degrees == Null
                Throw ParseError(ParseErrorKind.WRONG_TYPE, "a temperature is a number")
            End If
    
            Return Celsius(degrees)
        End Method
    
        Public Method ToValue(): Value => Value(Degrees)
    End Struct
    
    Expect(Save(Celsius(21.5)) == Value(21.5))
    Local loaded = Try Load<Celsius>(Value(30))
    Expect(loaded.Degrees == 30.0)

    std/core/load.fb, line 72

    • Static Method FromValue(value: Value): Self Throws ParseError static method #

      Makes one from a Value, as Load does.

    Report an issue with this page or with FutureBlitz on GitHub.