Skip to main content

surfer_translation_types/
field_ref.rs

1use crate::variable_ref::VariableRef;
2use serde::{Deserialize, Serialize};
3use std::hash::{Hash, Hasher};
4
5/// A reference to a field of a larger variable, such as a field in a struct.
6///
7/// The fields are the recursive path to the fields inside the (translated) root
8#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
9pub struct FieldRef<VarId, ScopeId> {
10    pub root: VariableRef<VarId, ScopeId>,
11    pub field: Vec<String>,
12}
13
14// Manual implementation because of https://github.com/rust-lang/rust/issues/26925
15impl<VarId, ScopeId> Hash for FieldRef<VarId, ScopeId> {
16    fn hash<H: Hasher>(&self, state: &mut H) {
17        let FieldRef { root, field } = self;
18        root.hash(state);
19        field.hash(state);
20    }
21}