forked from ipld/go-ipld-prime
-
Notifications
You must be signed in to change notification settings - Fork 0
/
type_link.go
51 lines (39 loc) · 1.13 KB
/
type_link.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
package schema
import (
"github.com/ipld/go-ipld-prime"
schemadmt "github.com/ipld/go-ipld-prime/schema/dmt"
)
type TypeLink struct {
name TypeName
dmt schemadmt.TypeLink
ts *TypeSystem
}
// -- schema.Type interface satisfaction -->
var _ Type = (*TypeLink)(nil)
func (t *TypeLink) _Type() {}
func (t *TypeLink) TypeSystem() *TypeSystem {
return t.ts
}
func (TypeLink) TypeKind() TypeKind {
return TypeKind_Link
}
func (t *TypeLink) Name() TypeName {
return t.name
}
func (t TypeLink) RepresentationBehavior() ipld.Kind {
return ipld.Kind_Link
}
// -- specific to TypeLink -->
// HasReferencedType returns true if the link has a hint about the type it references.
func (t *TypeLink) HasReferencedType() bool {
return t.dmt.FieldExpectedType().Exists()
}
// ReferencedType returns the type which is expected for the node on the other side of the link.
// Nil is returned if there is no information about the expected type
// (which may be interpreted as "any").
func (t *TypeLink) ReferencedType() Type {
if !t.dmt.FieldExpectedType().Exists() {
return nil
}
return t.ts.types[t.dmt.FieldExpectedType().Must().TypeReference()]
}