-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlib.go
44 lines (34 loc) · 781 Bytes
/
lib.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
package summoner
import (
"reflect"
)
func TypeOf[A any]() reflect.Type {
return reflect.TypeOf((*A)(nil)).Elem()
}
func IsRule[A any]() bool {
return TypeOf[A]().Kind() == reflect.Struct
}
func Rules() string {
return global.Rules()
}
func Summon[I any]() (I, error) {
return Transfrom[any, I](&global).Summon()
}
func SummonType(t reflect.Type) (any, error) {
return global.SummonType(t)
}
func Given[I any](instance I) error {
return Transfrom[any, I](&global).Given(instance)
}
func Inject(obj any) error {
return global.Inject(obj)
}
func GivenType(instance any, t reflect.Type) error {
return global.GivenType(instance, t)
}
func Transfrom[A, B any](s *Summoner[A]) *Summoner[B] {
return &Summoner[B]{
instances: s.instances,
rules: s.rules,
}
}