/// Follow is a trait that allows us to access FlatBuffers in a declarative, /// type safe, and fast way. They compile down to almost no code (after /// optimizations). Conceptually, Follow lifts the offset-based access /// patterns of FlatBuffers data into the type system. This trait is used /// pervasively at read time, to access tables, vtables, vectors, strings, and /// all other data. At this time, Follow is not utilized much on the write /// path. /// /// Writing a new Follow implementation primarily involves deciding whether /// you want to return data (of the type Self::Inner) or do you want to /// continue traversing the FlatBuffer. pubtrait Follow<'buf> { type Inner; /// # Safety /// /// `buf[loc..]` must contain a valid value of `Self` and anything it /// transitively refers to by offset must also be valid unsafefn follow(buf: &'buf [u8], loc: usize) -> Self::Inner;
}
/// FollowStart wraps a Follow impl in a struct type. This can make certain /// programming patterns more ergonomic. #[derive(Debug, Default)] pubstruct FollowStart<T>(PhantomData<T>); impl<'a, T: Follow<'a> + 'a> FollowStart<T> { #[inline] pubfn new() -> Self { Self(PhantomData)
}
/// # Safety /// /// `buf[loc..]` must contain a valid value of `T` #[inline] pubunsafefn self_follow(&'a self, buf: &'a [u8], loc: usize) -> T::Inner {
T::follow(buf, loc)
}
} impl<'a, T: Follow<'a>> Follow<'a> for FollowStart<T> { type Inner = T::Inner; #[inline] unsafefn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
T::follow(buf, loc)
}
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.