Skip to main content

Shape

Trait Shape 

Source
pub trait Shape {
    // Required methods
    fn id(&self) -> ShapeId;
    fn key(&self, name: &str) -> Option<Key>;
}
Expand description

The names a view answers.

use web_net::{Key, Shape, ShapeId};

struct PostShape;
impl Shape for PostShape {
    fn id(&self) -> ShapeId { ShapeId(1) }
    fn key(&self, name: &str) -> Option<Key> {
        match name { "title" => Some(Key(0)), "body" => Some(Key(1)), _ => None }
    }
}
assert_eq!(PostShape.key("body"), Some(Key(1)));
assert_eq!(PostShape.key("author"), None);

Required Methods§

Source

fn id(&self) -> ShapeId

The shape’s identity. Two views with the same id resolve every name to the same key.

Source

fn key(&self, name: &str) -> Option<Key>

The key for a field or method name.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§

Source§

impl Shape for Fields<'_>