/// Approxiamte upper bound for IDLValue size of type t. Returns None if infinite.
Approxiamte upper bound for IDLValue size of type t. Returns None if infinite.
Approxiamte upper bound for IDLValue size of type t . Returns None if infinite .
fn size_helper(&self, seen: &mut HashSet<String>, t: &Type) -> Option<usize> {
        use Type::*;
        Some(match t {
            Var(id) => {
                if seen.insert(id.to_string()) {
                    let ty = self.rec_find_type(id).unwrap();
                    let res = self.size_helper(seen, ty)?;
                    seen.remove(id);
                    res
                } else {
                    return None;
                }
            }
            Empty => 0,
            Opt(t) => 1 + self.size_helper(seen, t)?,
            Vec(t) => 1 + self.size_helper(seen, t)? * 2,
            Record(fs) => {
                let mut sum = 0;
                for Field { ty, .. } in fs.iter() {
                    sum += self.size_helper(seen, ty)?;
                }
                1 + sum
            }
            Variant(fs) => {
                let mut max = 0;
                for Field { ty, .. } in fs.iter() {
                    let s = self.size_helper(seen, ty)?;
                    if s > max {
                        max = s;
                    };
                }
                1 + max
            }
            _ => 1,
        })
    }
fn size_helper ( & self , seen : & mut HashSet < String > , t : & Type ) -> Option < usize > { use Type :: * ; Some ( match t { Var ( id ) => { if seen . insert ( id . to_string ( ) ) { let ty = self . rec_find_type ( id ) . unwrap ( ) ; let res = self . size_helper ( seen , ty ) ? ; seen . remove ( id ) ; res } else { return None ; } } Empty => 0 , Opt ( t ) => 1 + self . size_helper ( seen , t ) ? , Vec ( t ) => 1 + self . size_helper ( seen , t ) ? * 2 , Record ( fs ) => { let mut sum = 0 ; for Field { ty , .. } in fs . iter ( ) { sum += self . size_helper ( seen , ty ) ? ; } 1 + sum } Variant ( fs ) => { let mut max = 0 ; for Field { ty , .. } in fs . iter ( ) { let s = self . size_helper ( seen , ty ) ? ; if s > max { max = s ; } ; } 1 + max } _ => 1 , } ) }
Approxiamte upper bound for IDLValue size of type t. Returns None if infinite.
Approxiamte upper bound for IDLValue size of type t . Returns None if infinite .
&self
seen
&mut HashSet<String>
t
&Type