Skip to content

Commit 589316a

Browse files
author
mlund
committed
Reduce indents w. let Some(..)
1 parent 2fe69d1 commit 589316a

File tree

2 files changed

+39
-39
lines changed

2 files changed

+39
-39
lines changed

src/icotable.rs

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -426,23 +426,24 @@ impl Table6D {
426426
writeln!(stream, "# r 𝜔 𝜃1 𝜑1 𝜃2 𝜑2 data")?;
427427
for (omega, angles) in self.get(r)?.iter() {
428428
for (vertex1, vertex2, data) in angles.flat_iter() {
429-
if let Some(data) = data.get() {
430-
let (s1, s2) = (
431-
SphericalCoord::from_cartesian(vertex1.normalize()),
432-
SphericalCoord::from_cartesian(vertex2.normalize()),
433-
);
434-
writeln!(
435-
stream,
436-
"{:.2} {:.3} {:.3} {:.3} {:.3} {:.3} {:.4e}",
437-
r,
438-
omega,
439-
s1.theta(),
440-
s1.phi(),
441-
s2.theta(),
442-
s2.phi(),
443-
data
444-
)?;
445-
}
429+
let Some(data) = data.get() else {
430+
continue; // skip uninitialized data
431+
};
432+
let (s1, s2) = (
433+
SphericalCoord::from_cartesian(vertex1.normalize()),
434+
SphericalCoord::from_cartesian(vertex2.normalize()),
435+
);
436+
writeln!(
437+
stream,
438+
"{:.2} {:.3} {:.3} {:.3} {:.3} {:.3} {:.4e}",
439+
r,
440+
omega,
441+
s1.theta(),
442+
s1.phi(),
443+
s2.theta(),
444+
s2.phi(),
445+
data
446+
)?;
446447
}
447448
}
448449
Ok(())

src/structure.rs

Lines changed: 21 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
// limitations under the license.
1414

1515
use crate::Vector3;
16-
use anyhow::{bail, Context, Result};
16+
use anyhow::{anyhow, Context, Result};
1717
use faunus::topology::{AtomKind, FindByName};
1818
use itertools::Itertools;
1919
use nalgebra::Matrix3;
@@ -319,14 +319,14 @@ impl Display for Structure {
319319

320320
/// Parse a single line from an XYZ file
321321
fn from_xyz_line(line: &str) -> Result<(String, Vector3)> {
322-
if let Some([name, x, y, z]) = line.split_whitespace().collect_array() {
323-
Ok((
324-
name.to_string(),
325-
Vector3::new(x.parse()?, y.parse()?, z.parse()?),
326-
))
327-
} else {
328-
bail!("'name x y z' expected in XYZ record: {}", line);
329-
}
322+
let [name, x, y, z] = line
323+
.split_whitespace()
324+
.collect_array()
325+
.ok_or_else(|| anyhow!("Invalid XYZ record: {}", line))?;
326+
Ok((
327+
name.to_string(),
328+
Vector3::new(x.parse()?, y.parse()?, z.parse()?),
329+
))
330330
}
331331

332332
/// Write single ATOM record in PQR file stream
@@ -357,18 +357,17 @@ pub struct AminoAcidModelRecord {
357357

358358
impl AminoAcidModelRecord {
359359
pub fn from_line(line: &str) -> Result<Self> {
360-
if let Some([name, _, x, y, z, charge, mass, radius]) =
361-
line.split_whitespace().collect_array()
362-
{
363-
Ok(Self {
364-
name: name.to_string(),
365-
pos: Vector3::new(x.parse()?, y.parse()?, z.parse()?),
366-
charge: charge.parse()?,
367-
mass: mass.parse()?,
368-
radius: radius.parse()?,
369-
})
370-
} else {
371-
bail!("Invalid AAM record: {}", line);
372-
}
360+
let [name, _, x, y, z, charge, mass, radius] = line
361+
.split_whitespace()
362+
.collect_array()
363+
.ok_or_else(|| anyhow!("Invalid AAM record: {}", line))?;
364+
365+
Ok(Self {
366+
name: name.to_string(),
367+
pos: Vector3::new(x.parse()?, y.parse()?, z.parse()?),
368+
charge: charge.parse()?,
369+
mass: mass.parse()?,
370+
radius: radius.parse()?,
371+
})
373372
}
374373
}

0 commit comments

Comments
 (0)