pub struct DeserializeShapeGraph { /* private fields */ }Expand description
A complete deserialization shape graph rooted at one type.
Implementations§
Source§impl DeserializeShapeGraph
impl DeserializeShapeGraph
Sourcepub fn from_fn<F>(build_root: F) -> Self
pub fn from_fn<F>(build_root: F) -> Self
Builds a deserialization graph from a function that returns its root shape.
This lets a custom shape function describe a foreign root without introducing a wrapper
type solely to implement DeserializeShape.
use serde_shape::DeserializeShapeContext;
use serde_shape::DeserializeShapeGraph;
use serde_shape::ShapeRef;
fn duration_input(_context: &mut DeserializeShapeContext) -> ShapeRef {
ShapeRef::union([ShapeRef::String, ShapeRef::U64])
}
let graph = DeserializeShapeGraph::from_fn(duration_input);
assert_eq!(
graph.root(),
&ShapeRef::union([ShapeRef::String, ShapeRef::U64]),
);Sourcepub fn for_type<T>() -> Selfwhere
T: DeserializeShape + ?Sized,
pub fn for_type<T>() -> Selfwhere
T: DeserializeShape + ?Sized,
Builds a complete deserialization shape graph rooted at T.
Sourcepub fn root_definition(&self) -> Option<&DeserializeDefinitionShape>
pub fn root_definition(&self) -> Option<&DeserializeDefinitionShape>
Returns the root definition when the graph root is a named type.
Sourcepub fn definitions(&self) -> &[DeserializeDefinitionShape]
pub fn definitions(&self) -> &[DeserializeDefinitionShape]
Returns the named definitions reachable from the root.
Sourcepub fn definition(&self, id: ShapeId) -> Option<&DeserializeDefinitionShape>
pub fn definition(&self, id: ShapeId) -> Option<&DeserializeDefinitionShape>
Returns the definition at this id’s graph-local index.
A ShapeId does not encode graph ownership. The caller must pass an id produced by this
graph; an id from another graph with an in-bounds index cannot be distinguished here.
Sourcepub fn definition_for(
&self,
shape: &ShapeRef,
) -> Option<&DeserializeDefinitionShape>
pub fn definition_for( &self, shape: &ShapeRef, ) -> Option<&DeserializeDefinitionShape>
Returns the definition directly referenced by shape.
Returns None for non-definition shapes and out-of-bounds definition indexes.
Trait Implementations§
Source§impl Clone for DeserializeShapeGraph
impl Clone for DeserializeShapeGraph
Source§fn clone(&self) -> DeserializeShapeGraph
fn clone(&self) -> DeserializeShapeGraph
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more