You are an expert in writing code in many different languages. Your goal is to perform code completion for the following code, keeping in mind the rest of the code and the file meta data.
    Metadata details:
    filename: metric.go
    path of file: ./repos/k6/vendor/github.com/prometheus/client_golang/prometheus
    
    the code of the file until where you have to start completion: // Copyright 2014 The Prometheus Authors
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in w
    
func (m *withExemplarsMetric) Write(pb *dto.Metric) error {
	if err := m.Metric.Write(pb); err != nil {
		return err
	}

	switch {
	case pb.Counter != nil:
		pb.Counter.Exemplar = m.exemplars[len(m.exemplars)-1]
	case pb.Histogram != nil:
		for _, e := range m.exemplars {
			// pb.Histogram.Bucket are sorted by UpperBound.
			i := sort.Search(len(pb.Histogram.Bucket), func(i int) bool {
				return pb.Histogram.Bucket[i].GetUpperBound() >= e.GetValue()
			})
			if i < len(pb.Histogram.Bucket) {
				pb.Histogram.Bucket[i].Exemplar = e
			} else {
				// The +Inf bucket should be explicitly added if there is an exemplar for it, similar to non-const histogram logic in https://github.com/prometheus/client_golang/blob/main/prometheus/histogram.go#L357-L365.
				b := &dto.Bucket{
					CumulativeCount: proto.Uint64(pb.Histogram.GetSampleCount()),
					UpperBound:      proto.Float64(math.Inf(1)),
					Exemplar:        e,
				}
				pb.Histogram.Bucket = append(pb.Histogram.Bucket, b)
			}
		}
	default:
		// TODO(bwplotka): Implement Gauge?
		return errors.New("cannot inject exemplar into Gauge, Summary or Untyped")
	}

	return nil
}