Skip to main content

apdl_parser/
elist.rs

1use anyhow::{Ok, anyhow};
2use std::str::FromStr;
3
4#[derive(Debug)]
5pub struct Elist {
6    pub elem: usize,
7    pub mat: usize,
8    pub typ: usize,
9    pub rel: usize,
10    pub esy: usize,
11    pub sec: usize,
12    pub node_i: usize,
13    pub node_j: usize,
14    pub node_k: usize,
15}
16
17impl FromStr for Elist {
18    type Err = anyhow::Error;
19
20    fn from_str(s: &str) -> Result<Self, Self::Err> {
21        let mut parts = s.split_whitespace();
22
23        let elem = parts.next().ok_or(anyhow!("not enought data at `{s}`"))?;
24        let mat = parts.next().ok_or(anyhow!("not enought data at `{s}`"))?;
25        let typ = parts.next().ok_or(anyhow!("not enought data at `{s}`"))?;
26        let rel = parts.next().ok_or(anyhow!("not enought data at `{s}`"))?;
27        let esy = parts.next().ok_or(anyhow!("not enought data at `{s}`"))?;
28        let sec = parts.next().ok_or(anyhow!("not enought data at `{s}`"))?;
29        let node_i = parts.next().ok_or(anyhow!("not enought data at `{s}`"))?;
30        let node_j = parts.next().ok_or(anyhow!("not enought data at `{s}`"))?;
31        let node_k = parts.next().ok_or(anyhow!("not enought data at `{s}`"))?;
32
33        Ok(Self {
34            elem: elem.parse()?,
35            mat: mat.parse()?,
36            typ: typ.parse()?,
37            rel: rel.parse()?,
38            esy: esy.parse()?,
39            sec: sec.parse()?,
40            node_i: node_i.parse()?,
41            node_j: node_j.parse()?,
42            node_k: node_k.parse()?,
43        })
44    }
45}