Add chat session

This commit is contained in:
Tnze
2023-01-01 13:17:07 +08:00
parent 77857a1a85
commit fa83b762bf
15 changed files with 244 additions and 25 deletions

View File

@ -205,6 +205,14 @@ func (o *Option[T, P]) ReadFrom(r io.Reader) (n int64, err error) {
return n1 + n2, err
}
// Pointer returns the pointer of Val if Has is true, otherwise return nil.
func (o *Option[T, P]) Pointer() (p *T) {
if o.Has {
p = &o.Val
}
return
}
// OptionDecoder is basically same with [Option], but support [FieldDecoder] only.
// This allowed wrapping a [FieldDecoder] type (which isn't a [FieldEncoder]) to an Option.
type OptionDecoder[T any, P fieldPointer[T]] struct {