package mixins import ( ld "gitlab.dms3.io/ld/go-ld-prime" ) // Float can be embedded in a struct to provide all the methods that // have fixed output for any int-kinded nodes. // (Mostly this includes all the methods which simply return ErrWrongKind.) // Other methods will still need to be implemented to finish conforming to Node. // // To conserve memory and get a TypeName in errors without embedding, // write methods on your type with a body that simply initializes this struct // and immediately uses the relevant method; // this is more verbose in source, but compiles to a tighter result: // in memory, there's no embed; and in runtime, the calls will be inlined // and thus have no cost in execution time. type Float struct { TypeName string } func (Float) Kind() ld.Kind { return ld.Kind_Float } func (x Float) LookupByString(string) (ld.Node, error) { return nil, ld.ErrWrongKind{TypeName: x.TypeName, MethodName: "LookupByString", AppropriateKind: ld.KindSet_JustMap, ActualKind: ld.Kind_Float} } func (x Float) LookupByNode(key ld.Node) (ld.Node, error) { return nil, ld.ErrWrongKind{TypeName: x.TypeName, MethodName: "LookupByNode", AppropriateKind: ld.KindSet_JustMap, ActualKind: ld.Kind_Float} } func (x Float) LookupByIndex(idx int64) (ld.Node, error) { return nil, ld.ErrWrongKind{TypeName: x.TypeName, MethodName: "LookupByIndex", AppropriateKind: ld.KindSet_JustList, ActualKind: ld.Kind_Float} } func (x Float) LookupBySegment(ld.PathSegment) (ld.Node, error) { return nil, ld.ErrWrongKind{TypeName: x.TypeName, MethodName: "LookupBySegment", AppropriateKind: ld.KindSet_Recursive, ActualKind: ld.Kind_Float} } func (Float) MapIterator() ld.MapIterator { return nil } func (Float) ListIterator() ld.ListIterator { return nil } func (Float) Length() int64 { return -1 } func (Float) IsAbsent() bool { return false } func (Float) IsNull() bool { return false } func (x Float) AsBool() (bool, error) { return false, ld.ErrWrongKind{TypeName: x.TypeName, MethodName: "AsBool", AppropriateKind: ld.KindSet_JustBool, ActualKind: ld.Kind_Float} } func (x Float) AsInt() (int64, error) { return 0, ld.ErrWrongKind{TypeName: x.TypeName, MethodName: "AsInt", AppropriateKind: ld.KindSet_JustInt, ActualKind: ld.Kind_Float} } func (x Float) AsString() (string, error) { return "", ld.ErrWrongKind{TypeName: x.TypeName, MethodName: "AsString", AppropriateKind: ld.KindSet_JustString, ActualKind: ld.Kind_Float} } func (x Float) AsBytes() ([]byte, error) { return nil, ld.ErrWrongKind{TypeName: x.TypeName, MethodName: "AsBytes", AppropriateKind: ld.KindSet_JustBytes, ActualKind: ld.Kind_Float} } func (x Float) AsLink() (ld.Link, error) { return nil, ld.ErrWrongKind{TypeName: x.TypeName, MethodName: "AsLink", AppropriateKind: ld.KindSet_JustLink, ActualKind: ld.Kind_Float} } // FloatAssembler has similar purpose as Float, but for (you guessed it) // the NodeAssembler interface rather than the Node interface. type FloatAssembler struct { TypeName string } func (x FloatAssembler) BeginMap(sizeHint int64) (ld.MapAssembler, error) { return nil, ld.ErrWrongKind{TypeName: x.TypeName, MethodName: "BeginMap", AppropriateKind: ld.KindSet_JustMap, ActualKind: ld.Kind_Float} } func (x FloatAssembler) BeginList(sizeHint int64) (ld.ListAssembler, error) { return nil, ld.ErrWrongKind{TypeName: x.TypeName, MethodName: "BeginList", AppropriateKind: ld.KindSet_JustList, ActualKind: ld.Kind_Float} } func (x FloatAssembler) AssignNull() error { return ld.ErrWrongKind{TypeName: x.TypeName, MethodName: "AssignNull", AppropriateKind: ld.KindSet_JustNull, ActualKind: ld.Kind_Float} } func (x FloatAssembler) AssignBool(bool) error { return ld.ErrWrongKind{TypeName: x.TypeName, MethodName: "AssignBool", AppropriateKind: ld.KindSet_JustBool, ActualKind: ld.Kind_Float} } func (x FloatAssembler) AssignInt(int64) error { return ld.ErrWrongKind{TypeName: x.TypeName, MethodName: "AssignInt", AppropriateKind: ld.KindSet_JustInt, ActualKind: ld.Kind_Float} } func (x FloatAssembler) AssignString(string) error { return ld.ErrWrongKind{TypeName: x.TypeName, MethodName: "AssignString", AppropriateKind: ld.KindSet_JustString, ActualKind: ld.Kind_Float} } func (x FloatAssembler) AssignBytes([]byte) error { return ld.ErrWrongKind{TypeName: x.TypeName, MethodName: "AssignBytes", AppropriateKind: ld.KindSet_JustBytes, ActualKind: ld.Kind_Float} } func (x FloatAssembler) AssignLink(ld.Link) error { return ld.ErrWrongKind{TypeName: x.TypeName, MethodName: "AssignLink", AppropriateKind: ld.KindSet_JustLink, ActualKind: ld.Kind_Float} }