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