Skip to content

Commit

Permalink
Allow passing a byte slice as a string field (#45)
Browse files Browse the repository at this point in the history
  • Loading branch information
hanzei authored Nov 14, 2023
1 parent a02d145 commit a9cb1dc
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
2 changes: 1 addition & 1 deletion fieldapi.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ func Float[T ~float32 | ~float64](key string, val T) Field {
}

// String constructs a field containing a key and String value.
func String[T ~string](key string, val T) Field {
func String[T ~string | ~[]byte](key string, val T) Field {
return Field{Key: key, Type: StringType, String: string(val)}
}

Expand Down
4 changes: 4 additions & 0 deletions fieldapi_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,10 @@ func TestFieldString(t *testing.T) {
_ = String("string", "foo")
type myString string
_ = String("string", myString("foo"))

type myByteSlice string
_ = String("string", []byte{})
_ = String("string", myByteSlice([]byte{}))
}

func TestFieldStringer(t *testing.T) {
Expand Down

0 comments on commit a9cb1dc

Please sign in to comment.