blob: 4f8334933e87e5fdb7d27fdeef5766ecd3baa8e8 [file] [log] [blame]
Alyssa Haroldsend5d207f2023-08-24 13:39:23 -07001// Protocol Buffers - Google's data interchange format
2// Copyright 2023 Google LLC. All rights reserved.
Alyssa Haroldsend5d207f2023-08-24 13:39:23 -07003//
Joshua Haberman4a513032023-09-08 17:12:50 -07004// Use of this source code is governed by a BSD-style
5// license that can be found in the LICENSE file or at
6// https://developers.google.com/open-source/licenses/bsd
Alyssa Haroldsend5d207f2023-08-24 13:39:23 -07007
8//! Runtime-internal macros
9
Alyssa Haroldsend5d207f2023-08-24 13:39:23 -070010/// Defines a `impl SettableValue<$proxied> for SomeType` body that forwards to
11/// another implementation.
12///
13/// # Example
14/// ```ignore
15/// impl<'a, const N: usize> SettableValue<[u8]> for &'a [u8; N] {
16/// // Use the `SettableValue<[u8]>` implementation for `&[u8]`:
17/// impl_forwarding_settable_value!([u8], self => &self[..]);
18/// }
19/// ```
20macro_rules! impl_forwarding_settable_value {
21 ($proxied:ty, $self:ident => $self_forwarding_expr:expr) => {
Jakob Buchgraberab11a0d2023-11-27 08:14:21 -080022 fn set_on<'b>(
Alyssa Haroldsend5d207f2023-08-24 13:39:23 -070023 $self,
24 _private: $crate::__internal::Private,
Jakob Buchgraberab11a0d2023-11-27 08:14:21 -080025 mutator: $crate::Mut<'b, $proxied>,
26 ) where $proxied: 'b {
Alyssa Haroldsend5d207f2023-08-24 13:39:23 -070027 ($self_forwarding_expr).set_on(Private, mutator)
28 }
29
30 fn set_on_absent(
31 $self,
32 _private: $crate::__internal::Private,
33 absent_mutator: <$proxied as $crate::ProxiedWithPresence>::AbsentMutData<'_>,
34 ) -> <$proxied as $crate::ProxiedWithPresence>::PresentMutData<'_> {
35 ($self_forwarding_expr).set_on_absent($crate::__internal::Private, absent_mutator)
36 }
37
38 fn set_on_present(
39 $self,
40 _private: $crate::__internal::Private,
41 present_mutator: <$proxied as $crate::ProxiedWithPresence>::PresentMutData<'_>,
42 ) {
43 ($self_forwarding_expr).set_on_present($crate::__internal::Private, present_mutator)
44 }
45 };
46}
47pub(crate) use impl_forwarding_settable_value;