1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
//! Serialization and encodings.
//!
//! This module provides encoding support enabled via Cargo features. Each
//! enabled encoding has a corresponding sub-module. For example, when
//! [PLY](https://en.wikipedia.org/wiki/ply_(file_format)) support is enabled,
//! the `ply` module is exposed. The following table summarizes the encodings
//! supported by Plexus:
//!
//! | Feature        | Default | Encoding | Read | Write |
//! |----------------|---------|----------|------|-------|
//! | `encoding-ply` | No      | PLY      | Yes  | No    |
//!
//! This module provides traits used by all encodings. These traits describe
//! the outputs and inputs of decoders and encoders, respectively. Generally,
//! these traits should **not** be used directly. Instead, prefer the
//! conversion traits exposed for specific encodings.

pub mod ply;

use std::fmt::Debug;

pub trait VertexDecoder {
    type Output: IntoIterator<Item = Self::Vertex>;
    type Vertex;
}

pub trait FaceDecoder {
    type Output: IntoIterator<Item = (Self::Index, Self::Face)>;
    type Index: IntoIterator<Item = usize>;
    type Face;
}

pub trait FromEncoding<E>: Sized
where
    E: FaceDecoder + VertexDecoder,
{
    type Error: Debug;

    fn from_encoding(
        vertices: <E as VertexDecoder>::Output,
        faces: <E as FaceDecoder>::Output,
    ) -> Result<Self, Self::Error>;
}