Skip to content
This repository was archived by the owner on May 7, 2024. It is now read-only.

Commit c98fee2

Browse files
refactor: apply rustfmt rules
1 parent 93f2bc0 commit c98fee2

File tree

9 files changed

+54
-44
lines changed

9 files changed

+54
-44
lines changed

src/core/export.rs

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,25 @@
1-
use std::any::Any;
2-
use std::collections::HashMap;
31
use crate::core::export::export::Export;
42
use crate::core::path::path::path::Path;
3+
use std::any::Any;
4+
use std::collections::HashMap;
55

66
pub mod export {
7+
use crate::core::path::path::path::Path;
78
use std::any::Any;
89
use std::collections::HashMap;
9-
use crate::core::path::path::path::Path;
1010

1111
/// Abstraction for the result of local computation.
1212
/// It is an AST decorated with the computation value.
1313
#[derive(Debug)]
14-
pub struct Export{
14+
pub struct Export {
1515
pub(crate) map: HashMap<Path, Box<dyn Any>>,
1616
}
1717
}
1818

1919
impl Export {
20-
2120
/// Creates an Export with the passed HashMap.
2221
pub fn new(map: HashMap<Path, Box<dyn Any>>) -> Self {
23-
Export{ map }
22+
Export { map }
2423
}
2524

2625
/// Inserts a value in the Export at the given Path.
@@ -30,7 +29,9 @@ impl Export {
3029

3130
/// Returns the value at the given Path.
3231
pub fn get<A: 'static>(&self, path: &Path) -> Option<&A> {
33-
self.map.get(path).and_then(|value| value.downcast_ref::<A>())
32+
self.map
33+
.get(path)
34+
.and_then(|value| value.downcast_ref::<A>())
3435
}
3536

3637
/// Returns the root value.
@@ -46,8 +47,8 @@ impl Export {
4647

4748
#[cfg(test)]
4849
mod tests {
49-
use crate::core::path::slot::slot::Slot::{Nbr, Rep};
5050
use super::*;
51+
use crate::core::path::slot::slot::Slot::{Nbr, Rep};
5152

5253
#[test]
5354
fn test_new_empty() {
@@ -78,7 +79,10 @@ mod tests {
7879
let mut map: HashMap<Path, Box<dyn Any>> = HashMap::new();
7980
map.insert(Path::new(vec![Rep(0), Nbr(0)]), Box::new(10));
8081
let export = Export::new(map);
81-
assert_eq!(export.get::<i32>(&Path::new(vec![Rep(0), Nbr(0)])).unwrap(), &10);
82+
assert_eq!(
83+
export.get::<i32>(&Path::new(vec![Rep(0), Nbr(0)])).unwrap(),
84+
&10
85+
);
8286
}
8387

8488
#[test]
@@ -107,7 +111,7 @@ mod tests {
107111
}
108112

109113
#[test]
110-
fn test_paths(){
114+
fn test_paths() {
111115
let mut map: HashMap<Path, Box<dyn Any>> = HashMap::new();
112116
let mut map2: HashMap<Path, Box<dyn Any>> = HashMap::new();
113117
map.insert(Path::new(vec![]), Box::new(10));

src/core/export_factory.rs

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
pub mod export_factory {
2-
use std::any::Any;
3-
use std::collections::HashMap;
42
use crate::core::export::export::Export;
53
use crate::core::path::path::path::Path;
64
use crate::core::path::slot::slot::Slot;
5+
use std::any::Any;
6+
use std::collections::HashMap;
77

88
/// Returns an empty Path.
99
pub fn empty_path() -> Path {
@@ -22,8 +22,8 @@ pub mod export_factory {
2222

2323
/// Returns an Export with the given HashMap.
2424
pub fn export_from(exps: Vec<(Path, Box<dyn Any>)>) -> Export {
25-
Export{
26-
map: HashMap::from_iter(exps.into_iter())
25+
Export {
26+
map: HashMap::from_iter(exps.into_iter()),
2727
}
2828
}
2929
}
@@ -46,8 +46,14 @@ mod tests {
4646
fn test_root_path() {
4747
let mut export: Export = empty_export();
4848
export.put(empty_path(), String::from("foo"));
49-
assert_eq!(export.get::<String>(&empty_path()).unwrap(), export.root::<String>());
50-
assert_eq!(export.get::<String>(&empty_path()), Some(&String::from("foo")));
49+
assert_eq!(
50+
export.get::<String>(&empty_path()).unwrap(),
51+
export.root::<String>()
52+
);
53+
assert_eq!(
54+
export.get::<String>(&empty_path()),
55+
Some(&String::from("foo"))
56+
);
5157
}
5258

5359
#[test]
@@ -62,7 +68,10 @@ mod tests {
6268
fn test_overwriting_with_different_type() {
6369
let mut export: Export = empty_export();
6470
export.put(empty_path(), String::from("foo"));
65-
assert_eq!(export.get::<String>(&empty_path()), Some(&String::from("foo")));
71+
assert_eq!(
72+
export.get::<String>(&empty_path()),
73+
Some(&String::from("foo"))
74+
);
6675
export.put(empty_path(), 77);
6776
assert_eq!(export.get::<i32>(&empty_path()).unwrap(), &77);
6877
}

src/core/mod.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
pub mod vm;
2-
pub mod path;
31
pub mod export;
4-
pub mod export_factory;
2+
pub mod export_factory;
3+
pub mod path;
4+
pub mod vm;

src/core/path/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
pub mod path;
2-
pub mod slot;
2+
pub mod slot;

src/core/path/path.rs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ use crate::core::path::path::path::Path;
1212
use crate::core::path::slot::slot::Slot;
1313

1414
impl Path {
15-
1615
/// Factory method to create a new Path
1716
pub fn new(slots: Vec<Slot>) -> Self {
1817
Path { slots }
@@ -41,8 +40,11 @@ impl Path {
4140
pub fn to_str(&self) -> String {
4241
let slots = &self.slots;
4342
let path = String::from("P://");
44-
path +
45-
&slots.into_iter().map(|slot| slot.to_str()).collect::<Vec<String>>().join("/")
43+
path + &slots
44+
.into_iter()
45+
.map(|slot| slot.to_str())
46+
.collect::<Vec<String>>()
47+
.join("/")
4648
}
4749

4850
/// Check if the Path matches another Path
@@ -59,7 +61,7 @@ impl Path {
5961
#[cfg(test)]
6062
mod tests {
6163
use crate::core::path::path::path::Path;
62-
use crate::core::path::slot::slot::Slot::{Nbr, Rep, Branch};
64+
use crate::core::path::slot::slot::Slot::{Branch, Nbr, Rep};
6365

6466
#[test]
6567
fn test_is_root() {
@@ -113,4 +115,4 @@ mod tests {
113115
assert!(path.matches(&Path::new(vec![Rep(0), Nbr(0), Nbr(1), Branch(0)])));
114116
assert!(!path.matches(&Path::new(vec![Nbr(0), Nbr(1), Branch(0)])))
115117
}
116-
}
118+
}

src/core/path/slot.rs

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,37 +2,36 @@ use crate::core::path::slot::slot::Slot;
22

33
/// A slot is a representation for a construct of the language that forms an execution path.
44
pub mod slot {
5-
5+
66
/// Slot is an enum that represents the different constructs of the language.
77
/// Can be Nbr(index), Rep(index), Branch(index) or Exchange(index).
88
#[derive(PartialEq, Debug, Clone, Eq, Hash)]
9-
pub enum Slot{
9+
pub enum Slot {
1010
Nbr(i32),
1111
Rep(i32),
1212
Branch(i32),
1313
Exchange(i32),
1414
}
1515
}
1616

17-
impl Slot{
18-
17+
impl Slot {
1918
/// Return a String representation of the Slot.
2019
pub fn to_str(&self) -> String {
2120
match self {
22-
Slot::Nbr(index) => "Nbr(".to_owned()+&index.to_string()+")",
23-
Slot::Rep(index) => "Rep(".to_owned()+&index.to_string()+")",
24-
Slot::Branch(index) => "Branch(".to_owned()+&index.to_string()+")",
25-
Slot::Exchange(index) => "Exchange(".to_owned()+&index.to_string()+")",
21+
Slot::Nbr(index) => "Nbr(".to_owned() + &index.to_string() + ")",
22+
Slot::Rep(index) => "Rep(".to_owned() + &index.to_string() + ")",
23+
Slot::Branch(index) => "Branch(".to_owned() + &index.to_string() + ")",
24+
Slot::Exchange(index) => "Exchange(".to_owned() + &index.to_string() + ")",
2625
}
2726
}
2827
}
2928

3029
#[cfg(test)]
31-
mod test{
30+
mod test {
3231
use super::*;
3332

3433
#[test]
35-
fn test_slot_creation(){
34+
fn test_slot_creation() {
3635
let nbr = Slot::Nbr(0);
3736
let rep = Slot::Rep(0);
3837
let branch = Slot::Branch(0);
@@ -54,4 +53,4 @@ mod test{
5453
assert_eq!(branch.to_str(), "Branch(0)");
5554
assert_eq!(exchange.to_str(), "Exchange(0)");
5655
}
57-
}
56+
}

src/core/vm/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1+
pub mod round_vm;
12
pub mod vm_status;
2-
pub mod round_vm;

src/core/vm/round_vm.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1 @@
1-
pub mod round_vm {
2-
3-
}
1+
pub mod round_vm {}

src/core/vm/vm_status.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1 @@
1-
pub mod vm_status {
2-
3-
}
1+
pub mod vm_status {}

0 commit comments

Comments
 (0)