Name the lifetime in the signature of SettableValue.set_on()
This change names the lifetime of Mut<'a, T> and requires that T outlives 'a. The motivation for this change came up while implementing `Map<K, ProtoStr>`. The Map implementation makes it so that `V` needs to implement the `MapWithKeyOps` trait which has an associated type with a lifetime (`Value<'a>`. The lifetime bound on `T` ensures that e.g. for `MapWithKeyOps<Value<'b>=&'b ProtoStr>` `'a` outlives `'b`.
PiperOrigin-RevId: 585657154
diff --git a/rust/string.rs b/rust/string.rs
index 401dfc3..aece6ba 100644
--- a/rust/string.rs
+++ b/rust/string.rs
@@ -185,7 +185,10 @@
}
impl SettableValue<[u8]> for &'_ [u8] {
- fn set_on(self, _private: Private, mutator: BytesMut<'_>) {
+ fn set_on<'a>(self, _private: Private, mutator: Mut<'a, [u8]>)
+ where
+ [u8]: 'a,
+ {
// SAFETY: this is a `bytes` field with no restriction on UTF-8.
unsafe { mutator.inner.set(self) }
}
@@ -695,7 +698,10 @@
}
impl SettableValue<ProtoStr> for &'_ ProtoStr {
- fn set_on(self, _private: Private, mutator: ProtoStrMut<'_>) {
+ fn set_on<'b>(self, _private: Private, mutator: Mut<'b, ProtoStr>)
+ where
+ ProtoStr: 'b,
+ {
// SAFETY: A `ProtoStr` has the same UTF-8 validity requirement as the runtime.
unsafe { mutator.bytes.inner.set(self.as_bytes()) }
}