mirror of
https://github.com/tailscale/tailscale.git
synced 2025-10-28 14:51:32 +01:00
I got sidetracked apparently and never finished writing this Clone code in 316afe7d02babc (#17448). (It really should use views instead.) And then I missed one of the users of "routerChanged" that was broken up into "routerChanged" vs "dnsChanged". This broke integration tests elsewhere. Fixes #17506 Change-Id: I533bf0fcf3da9ac6eb4a6cdef03b8df2c1fb4c8e Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
26 lines
704 B
Go
26 lines
704 B
Go
// Copyright (c) Tailscale Inc & AUTHORS
|
|
// SPDX-License-Identifier: BSD-3-Clause
|
|
|
|
// Package checkchange defines a utility for determining whether a value
|
|
// has changed since the last time it was checked.
|
|
package checkchange
|
|
|
|
// EqualCloner is an interface for types that can be compared for equality
|
|
// and can be cloned.
|
|
type EqualCloner[T any] interface {
|
|
Equal(T) bool
|
|
Clone() T
|
|
}
|
|
|
|
// Update sets *old to a clone of new if they are not equal, returning whether
|
|
// they were different.
|
|
//
|
|
// It only modifies *old if they are different. old must be non-nil.
|
|
func Update[T EqualCloner[T]](old *T, new T) (changed bool) {
|
|
if (*old).Equal(new) {
|
|
return false
|
|
}
|
|
*old = new.Clone()
|
|
return true
|
|
}
|