-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathoption.go
More file actions
50 lines (41 loc) · 1.11 KB
/
option.go
File metadata and controls
50 lines (41 loc) · 1.11 KB
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
package strconvx
// Option adjusts the hybrid behaviour when creating a `StringCodec` instance with `New()` method.
type Option func(o *options)
// NoHybrid prevents `New()` from creating a hybrid `StringCodec` instance.
// Which means when calling `New()` with an object that doesn't implement
// `StringCodec` interface, `ErrUnsupportedType` will be returned.
//
// Example:
//
// // if v implemented StringCodec, returns StringCodec
// // if v didn't implement StringCodec, returns ErrUnsupportedType
// New(v, NoHybrid())
func NoHybrid() Option {
return func(o *options) {
o.Opt(optionNoHybrid)
}
}
// CompleteHybrid ensures that the hybrid instance created by `New()`
// has a full implementation of interface `StringCodec`.
func CompleteHybrid() Option {
return func(o *options) {
o.Opt(optionCompleteHybrid)
}
}
type options struct {
Value uint8
}
func defaultOptions() *options {
return &options{}
}
func (o *options) Opt(v option) {
o.Value |= uint8(v)
}
func (o *options) Has(v option) bool {
return (o.Value & uint8(v)) > 0
}
type option int
const (
optionNoHybrid option = 1 << iota
optionCompleteHybrid
)