Skip to content

Commit

Permalink
Added static assertions for JSON
Browse files Browse the repository at this point in the history
  • Loading branch information
ankane committed Jun 4, 2024
1 parent 88d27fa commit fd87ec6
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
6 changes: 6 additions & 0 deletions halfvec.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,11 +77,17 @@ func (v HalfVector) Value() (driver.Value, error) {
return v.String(), nil
}

// statically assert that HalfVector implements json.Marshaler.
var _ json.Marshaler = (*HalfVector)(nil)

// MarshalJSON implements the json.Marshaler interface.
func (v HalfVector) MarshalJSON() ([]byte, error) {
return json.Marshal(v.vec)
}

// statically assert that HalfVector implements json.Unmarshaler.
var _ json.Unmarshaler = (*HalfVector)(nil)

// UnmarshalJSON implements the json.Unmarshaler interface.
func (v *HalfVector) UnmarshalJSON(data []byte) error {
return json.Unmarshal(data, &v.vec)
Expand Down
6 changes: 6 additions & 0 deletions vector.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,11 +77,17 @@ func (v Vector) Value() (driver.Value, error) {
return v.String(), nil
}

// statically assert that Vector implements json.Marshaler.
var _ json.Marshaler = (*Vector)(nil)

// MarshalJSON implements the json.Marshaler interface.
func (v Vector) MarshalJSON() ([]byte, error) {
return json.Marshal(v.vec)
}

// statically assert that Vector implements json.Unmarshaler.
var _ json.Unmarshaler = (*Vector)(nil)

// UnmarshalJSON implements the json.Unmarshaler interface.
func (v *Vector) UnmarshalJSON(data []byte) error {
return json.Unmarshal(data, &v.vec)
Expand Down

0 comments on commit fd87ec6

Please sign in to comment.