From 084e40bf9eb1ecaaf7a4d11a42a186691e708b4e Mon Sep 17 00:00:00 2001 From: Malladi Pradyumna Date: Wed, 3 Jan 2024 01:09:38 +0530 Subject: [PATCH] Formatting --- vidyut-chandas/src/vrtta.rs | 33 +++++++++++++++++---------------- 1 file changed, 17 insertions(+), 16 deletions(-) diff --git a/vidyut-chandas/src/vrtta.rs b/vidyut-chandas/src/vrtta.rs index c475e0e..90301a2 100644 --- a/vidyut-chandas/src/vrtta.rs +++ b/vidyut-chandas/src/vrtta.rs @@ -80,21 +80,18 @@ fn to_counts(text: &str) -> Vec { .collect() } -/// Models a *pāda*, which is one of the four "feet" or "legs" of a verse. -/// A *pāda* defines a specific pattern of light and heavy syllables and +/// Models a *pāda*, which is one of the four "feet" or "legs" of a verse. +/// A *pāda* defines a specific pattern of light and heavy syllables and /// might also define one or more *yati*s (caesuras). #[derive(Clone, Debug, Eq, Hash, PartialEq)] pub struct Pada { weights: Vec, - yati: Vec + yati: Vec, } impl Pada { fn new(weights: Vec, yati: Vec) -> Self { - Pada { - weights, - yati - } + Pada { weights, yati } } } @@ -106,7 +103,6 @@ pub struct Vrtta { } impl Vrtta { - /// Creates a new `Vrtta` with the given name and weight pattern. pub fn new(name: impl AsRef, padas: Vec) -> Self { Self { @@ -115,7 +111,6 @@ impl Vrtta { } } - /// The name of this vrtta. /// /// A vrtta might be known by many other names. This method returns just one of these names. @@ -142,10 +137,10 @@ impl Vrtta { eprintln!(); let mut full = Vec::new(); - + while full.len() < 4 { for p in &self.padas { - full.push(p.weights.clone()); + full.push(p.weights.clone()); } } @@ -201,7 +196,6 @@ impl Vrtta { let mut result = Vec::new(); - for pada in &self.padas { let mut ganas = Vec::new(); @@ -236,14 +230,20 @@ impl TryFrom<&str> for Pada { type Error = Box; fn try_from(text: &str) -> Result { - let weights: Vec = text.chars().filter_map(|c| match c { + let weights: Vec = text + .chars() + .filter_map(|c| match c { '.' => Some(PatternWeight::Any), 'L' => Some(PatternWeight::L), 'G' => Some(PatternWeight::G), _ => None, }) - .collect(); - let yati: Vec = text.match_indices('|').enumerate().map(|(i, (offset, _))| offset - i).collect(); + .collect(); + let yati: Vec = text + .match_indices('|') + .enumerate() + .map(|(i, (offset, _))| offset - i) + .collect(); Ok(Pada::new(weights, yati)) } } @@ -258,7 +258,8 @@ impl TryFrom<&str> for Vrtta { let name = fields[0]; let _ = fields[1]; let pattern_str = fields[2]; - let padas: Result, Box> = pattern_str.split("/").map(|x| x.try_into()).collect(); + let padas: Result, Box> = + pattern_str.split("/").map(|x| x.try_into()).collect(); let padas = padas?; Ok(Vrtta::new(name, padas)) }