1use anyhow::{Ok, anyhow};
2use std::str::FromStr;
3
4#[derive(Debug)]
5pub struct Dlist {
6 pub node: usize,
7 pub label: String,
8 pub real: f32,
9 pub imag: f32,
10}
11
12impl FromStr for Dlist {
13 type Err = anyhow::Error;
14
15 fn from_str(s: &str) -> Result<Self, Self::Err> {
16 let mut parts = s.split_whitespace();
17
18 let node = parts.next().ok_or(anyhow!("not enought data at `{s}`"))?;
19 let label = parts.next().ok_or(anyhow!("not enought data at `{s}`"))?;
20 let real = parts.next().ok_or(anyhow!("not enought data at `{s}`"))?;
21 let imag = parts.next().ok_or(anyhow!("not enought data at `{s}`"))?;
22
23 Ok(Self {
24 node: node.parse()?,
25 label: label.parse()?,
26 real: real.parse()?,
27 imag: imag.parse()?,
28 })
29 }
30}