Skip to main content

serialize_paths_from_funcs

Function serialize_paths_from_funcs 

Source
pub fn serialize_paths_from_funcs<PathSrc, AdvanceF, PathF, W>(
    target: &mut W,
    src: &mut PathSrc,
    advance_f: AdvanceF,
    path_f: PathF,
) -> Result<SerializationStats>
where AdvanceF: FnMut(&mut PathSrc) -> Result<bool>, PathF: FnMut(&PathSrc) -> Option<&[u8]>, W: Write,
Expand description

Generates .paths data by invoking arbitrary closures

Warning: the size of the individual path serialization can be double exponential in the size of the PathMap

NOTE: This function takes two closures because of a limitation in the borrow checker. borrowck isn’t smart enough to allow one closure to take a mutable borrow of the PathSrc object, and return a const reborrow, and then allow the original mutable reference to be used again after the reborrow was dropped. Doing the reborrow in the loop works around this limitation.

When the borrow checker becomes more capable, we can try to collapse this function to take one closure instead of two.