File: macros.rs

package info (click to toggle)
protobuf 3.25.7-1
  • links: PTS
  • area: main
  • in suites: experimental
  • size: 46,004 kB
  • sloc: cpp: 204,412; java: 88,198; ansic: 81,264; objc: 58,434; cs: 27,303; python: 22,841; php: 11,408; ruby: 8,637; pascal: 3,333; xml: 2,333; sh: 1,331; makefile: 538; lisp: 86; awk: 17
file content (47 lines) | stat: -rw-r--r-- 1,729 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
// Protocol Buffers - Google's data interchange format
// Copyright 2023 Google LLC.  All rights reserved.
//
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file or at
// https://developers.google.com/open-source/licenses/bsd

//! Runtime-internal macros

/// Defines a `impl SettableValue<$proxied> for SomeType` body that forwards to
/// another implementation.
///
/// # Example
/// ```ignore
/// impl<'a, const N: usize> SettableValue<[u8]> for &'a [u8; N] {
///     // Use the `SettableValue<[u8]>` implementation for `&[u8]`:
///     impl_forwarding_settable_value!([u8], self => &self[..]);
/// }
/// ```
macro_rules! impl_forwarding_settable_value {
    ($proxied:ty, $self:ident => $self_forwarding_expr:expr) => {
        fn set_on(
            $self,
            _private: $crate::__internal::Private,
            mutator: $crate::Mut<'_, $proxied>,
        ) {
            ($self_forwarding_expr).set_on(Private, mutator)
        }

        fn set_on_absent(
            $self,
            _private: $crate::__internal::Private,
            absent_mutator: <$proxied as $crate::ProxiedWithPresence>::AbsentMutData<'_>,
        ) -> <$proxied as $crate::ProxiedWithPresence>::PresentMutData<'_> {
            ($self_forwarding_expr).set_on_absent($crate::__internal::Private, absent_mutator)
        }

        fn set_on_present(
            $self,
            _private: $crate::__internal::Private,
            present_mutator: <$proxied as $crate::ProxiedWithPresence>::PresentMutData<'_>,
        ) {
            ($self_forwarding_expr).set_on_present($crate::__internal::Private, present_mutator)
        }
    };
}
pub(crate) use impl_forwarding_settable_value;