plykit/model/mod.rs
1/// Implements the standardized payload format for
2/// ply nodes.
3#[derive(Serialize, Deserialize, Clone, Debug, Default)]
4pub struct Node {
5 /// Globally unique ID of this element
6 pub id: String,
7 /// Display name
8 pub name: String,
9 /// Longer description of the meaning and significance
10 /// of this element.
11 #[serde(default)]
12 pub description: String,
13}
14
15
16/// A string that is a valid solution ID.
17#[derive(Debug, Clone)]
18pub struct SolutionId(pub String);
19
20/// Generic error for turning strings into more constrained string types.
21#[derive(Clone, Debug)]
22pub struct StringError { cause:String }
23
24// TODO Implement real validity check and develop consistent error strategy for these things.
25impl std::str::FromStr for SolutionId {
26 type Err = StringError;
27
28 fn from_str(s: &str) -> Result<Self, Self::Err> {
29 //println!("parse Solution ID {}",s);
30 // TODO This is just dummy code to illustrate the validity check
31 if s.len() > 10 {
32 return Err(StringError{cause:"String to long".into()})
33 }
34 Ok(SolutionId(s.into()))
35 }
36}