Skip to main content

pb_jelly/
reflection.rs

1use crate::erased;
2
3/// A mutable borrow of a field, or `Empty` if the field does not have a value.
4#[non_exhaustive]
5pub enum FieldMut<'a> {
6    /// Mutable borrow of the field.
7    Value(&'a mut dyn Reflection),
8    // TODO: Would be nice to support this, but some more thought would need to be put into what
9    // the API for it looks like.
10    // Repeated(&'a mut Vec<dyn Reflection>),
11    /// An empty oneof variant.
12    Empty,
13}
14
15pub trait Reflection: erased::Message {
16    /// Returns the name of the field that is set inside a oneof group.
17    ///
18    /// If no field is set, returns None.
19    ///
20    /// # Panics
21    /// If the name given is not the name of a oneof field in this message.
22    fn which_one_of(&self, _oneof_name: &str) -> Option<&'static str> {
23        unimplemented!("proto reflection is not implemented for this type")
24    }
25
26    /// Returns a mutable borrow of the given field.
27    ///
28    /// If the field given is part of a oneof group, and that oneof group is not currently set to
29    /// this variant, this will mutate the current message, setting the oneof group to the variant
30    /// given by this field name with the default value.
31    ///
32    /// # Panics
33    /// If the name given is not the name of a field in this message.
34    fn get_field_mut(&mut self, _field_name: &str) -> FieldMut<'_> {
35        unimplemented!("proto reflection is not implemented for this type")
36    }
37}