1 use crate::reflect::acc::v2::singular::SingularFieldAccessorHolder;
2 use crate::reflect::acc::v2::AccessorV2;
3 use crate::reflect::acc::FieldAccessor;
4 use crate::reflect::runtime_types::RuntimeTypeWithDeref;
5 use crate::reflect::ProtobufValue;
6 use crate::EnumFull;
7 use crate::EnumOrUnknown;
8 use crate::MessageFull;
9
10 /// Make accessor for `oneof` `message` field
make_oneof_message_has_get_mut_set_accessor<M, F>( name: &'static str, has_field: fn(&M) -> bool, get_field: for<'a> fn(&'a M) -> &'a F, mut_field: for<'a> fn(&'a mut M) -> &'a mut F, set_field: fn(&mut M, F), ) -> FieldAccessor where M: MessageFull, F: MessageFull,11 pub fn make_oneof_message_has_get_mut_set_accessor<M, F>(
12 name: &'static str,
13 has_field: fn(&M) -> bool,
14 get_field: for<'a> fn(&'a M) -> &'a F,
15 mut_field: for<'a> fn(&'a mut M) -> &'a mut F,
16 set_field: fn(&mut M, F),
17 ) -> FieldAccessor
18 where
19 M: MessageFull,
20 F: MessageFull,
21 {
22 FieldAccessor::new(
23 name,
24 AccessorV2::Singular(SingularFieldAccessorHolder::new_has_get_mut_set(
25 has_field, get_field, mut_field, set_field,
26 )),
27 )
28 }
29
30 /// Make accessor for `Copy` field
make_oneof_copy_has_get_set_simpler_accessors<M, V>( name: &'static str, has: fn(&M) -> bool, get: fn(&M) -> V, set: fn(&mut M, V), ) -> FieldAccessor where M: MessageFull, V: ProtobufValue + Copy,31 pub fn make_oneof_copy_has_get_set_simpler_accessors<M, V>(
32 name: &'static str,
33 has: fn(&M) -> bool,
34 get: fn(&M) -> V,
35 set: fn(&mut M, V),
36 ) -> FieldAccessor
37 where
38 M: MessageFull,
39 V: ProtobufValue + Copy,
40 {
41 FieldAccessor::new(
42 name,
43 AccessorV2::Singular(SingularFieldAccessorHolder::new_has_get_set(has, get, set)),
44 )
45 }
46
47 /// Make accessor for `Copy` field
make_oneof_enum_accessors<M, E>( name: &'static str, get: fn(&M) -> Option<EnumOrUnknown<E>>, set: fn(&mut M, EnumOrUnknown<E>), _default_value: E, ) -> FieldAccessor where M: MessageFull, E: EnumFull,48 pub fn make_oneof_enum_accessors<M, E>(
49 name: &'static str,
50 get: fn(&M) -> Option<EnumOrUnknown<E>>,
51 set: fn(&mut M, EnumOrUnknown<E>),
52 // TODO: remove this
53 _default_value: E,
54 ) -> FieldAccessor
55 where
56 M: MessageFull,
57 E: EnumFull,
58 {
59 FieldAccessor::new(
60 name,
61 AccessorV2::Singular(SingularFieldAccessorHolder::new_get_option_set_enum(
62 get, set,
63 )),
64 )
65 }
66
67 /// Make accessor for `oneof` field
make_oneof_deref_has_get_set_simpler_accessor<M, F>( name: &'static str, has: fn(&M) -> bool, get: for<'a> fn(&'a M) -> &'a <F::RuntimeType as RuntimeTypeWithDeref>::DerefTarget, set: fn(&mut M, F), ) -> FieldAccessor where M: MessageFull + 'static, F: ProtobufValue, F::RuntimeType: RuntimeTypeWithDeref,68 pub fn make_oneof_deref_has_get_set_simpler_accessor<M, F>(
69 name: &'static str,
70 has: fn(&M) -> bool,
71 get: for<'a> fn(&'a M) -> &'a <F::RuntimeType as RuntimeTypeWithDeref>::DerefTarget,
72 set: fn(&mut M, F),
73 ) -> FieldAccessor
74 where
75 M: MessageFull + 'static,
76 F: ProtobufValue,
77 F::RuntimeType: RuntimeTypeWithDeref,
78 {
79 FieldAccessor::new(
80 name,
81 AccessorV2::Singular(SingularFieldAccessorHolder::new_has_get_set_deref(
82 has, get, set,
83 )),
84 )
85 }
86