Skip to content

Commit 50b0e72

Browse files
Switch to rust 2024 edition (#26)
Also use better badges
2 parents ed78946 + e525ac0 commit 50b0e72

22 files changed

+135
-100
lines changed

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
name = "frequenz-microgrid-component-graph"
33
description = "A library for representing the components of a microgrid and the connections between them as a Directed Acyclic Graph (DAG)."
44
version = "0.2.0"
5-
edition = "2021"
5+
edition = "2024"
66
repository = "https://github.com/frequenz-floss/frequenz-microgrid-component-graph-rs"
77
license = "MIT"
88

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# Frequenz Microgrid Component Graph
22

3-
![Crates.io Version](https://img.shields.io/crates/v/frequenz-microgrid-component-graph) ![docs.rs](https://img.shields.io/docsrs/frequenz-microgrid-component-graph)
3+
[<img alt="docs.rs" src="https://img.shields.io/docsrs/frequenz-microgrid-component-graph">](https://docs.rs/frequenz-microgrid-component-graph)
4+
[<img alt="Crates.io" src="https://img.shields.io/crates/v/frequenz-microgrid-component-graph">](https://crates.io/crates/frequenz-microgrid-component-graph)
45

56
This is a library for representing the components of a microgrid and the
67
connections between them as a Directed Acyclic Graph (DAG).

RELEASE_NOTES.md

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,17 @@
11
# Frequenz Component Graph Release Notes
22

3+
## Summary
4+
5+
<!-- Here goes a general summary of what this release is about -->
6+
7+
## Upgrading
8+
9+
<!-- Here goes notes on how to upgrade from previous versions, including deprecations and what they should be replaced with -->
10+
311
## New Features
412

5-
- Grid formulas now use single successor meters as fallback components for meters attached to the grid.
13+
<!-- Here goes the main new features and examples or instructions on how to use them -->
14+
15+
## Bug Fixes
16+
17+
<!-- Here goes notable bug fixes that are worth a special mention or explanation -->

src/component_category.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
//! This module defines the `ComponentCategory` enum, which represents the
55
//! category of a component.
66
7-
use crate::graph_traits::Node;
87
use crate::ComponentGraphConfig;
8+
use crate::graph_traits::Node;
99
use std::fmt::Display;
1010

1111
/// Represents the type of an inverter.

src/graph/creation.rs

Lines changed: 27 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
77
use petgraph::graph::DiGraph;
88

9-
use crate::{component_category::CategoryPredicates, ComponentGraphConfig, Edge, Error, Node};
9+
use crate::{ComponentGraphConfig, Edge, Error, Node, component_category::CategoryPredicates};
1010

1111
use super::{ComponentGraph, EdgeMap, NodeIndexMap};
1212

@@ -120,9 +120,9 @@ where
120120
#[cfg(test)]
121121
mod tests {
122122
use super::*;
123-
use crate::graph::test_utils::{ComponentGraphBuilder, ComponentHandle};
124123
use crate::ComponentCategory;
125124
use crate::InverterType;
125+
use crate::graph::test_utils::{ComponentGraphBuilder, ComponentHandle};
126126

127127
fn nodes_and_edges() -> (ComponentGraphBuilder, ComponentHandle) {
128128
let mut builder = ComponentGraphBuilder::new();
@@ -141,26 +141,30 @@ mod tests {
141141
fn test_component_validation() {
142142
let (mut builder, grid_meter) = nodes_and_edges();
143143

144-
assert!(builder
145-
.build(None)
146-
.is_err_and(|e| e == Error::invalid_graph("No grid component found.")),);
144+
assert!(
145+
builder
146+
.build(None)
147+
.is_err_and(|e| e == Error::invalid_graph("No grid component found.")),
148+
);
147149

148150
let grid = builder.grid();
149151
builder.connect(grid, grid_meter);
150152

151153
assert!(builder.build(None).is_ok());
152154

153155
builder.add_component_with_id(2, ComponentCategory::Meter);
154-
assert!(builder
155-
.build(None)
156-
.is_err_and(|e| e == Error::invalid_graph("Duplicate component ID found: 2")));
156+
assert!(
157+
builder
158+
.build(None)
159+
.is_err_and(|e| e == Error::invalid_graph("Duplicate component ID found: 2"))
160+
);
157161

158162
builder.pop_component();
159163
builder.add_component(ComponentCategory::Unspecified);
160-
assert!(builder
161-
.build(None)
162-
.is_err_and(|e| e
163-
== Error::invalid_component("ComponentCategory not specified for component: 8")));
164+
assert!(
165+
builder.build(None).is_err_and(|e| e
166+
== Error::invalid_component("ComponentCategory not specified for component: 8"))
167+
);
164168

165169
builder.pop_component();
166170
let unspec_inv =
@@ -180,15 +184,19 @@ mod tests {
180184

181185
assert!(builder.build(Some(unspec_inv_config.clone())).is_ok());
182186

183-
assert!(builder
184-
.pop_component()
185-
.unwrap()
186-
.is_battery_inverter(&unspec_inv_config));
187+
assert!(
188+
builder
189+
.pop_component()
190+
.unwrap()
191+
.is_battery_inverter(&unspec_inv_config)
192+
);
187193
builder.pop_connection();
188194
builder.add_component(ComponentCategory::GridConnectionPoint);
189-
assert!(builder
190-
.build(None)
191-
.is_err_and(|e| e == Error::invalid_graph("Multiple grid components found.")));
195+
assert!(
196+
builder
197+
.build(None)
198+
.is_err_and(|e| e == Error::invalid_graph("Multiple grid components found."))
199+
);
192200

193201
builder.pop_component();
194202
assert!(builder.build(None).is_ok());

src/graph/formulas/fallback.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,8 +180,8 @@ mod tests {
180180
use std::collections::BTreeSet;
181181

182182
use crate::{
183-
graph::{formulas::fallback::FallbackExpr, test_utils::ComponentGraphBuilder},
184183
ComponentGraphConfig, Error,
184+
graph::{formulas::fallback::FallbackExpr, test_utils::ComponentGraphBuilder},
185185
};
186186

187187
#[test]

src/graph/formulas/generators/battery.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@
66
use std::collections::BTreeSet;
77

88
use crate::component_category::CategoryPredicates;
9+
use crate::graph::formulas::AggregationFormula;
910
use crate::graph::formulas::expr::Expr;
1011
use crate::graph::formulas::fallback::FallbackExpr;
11-
use crate::graph::formulas::AggregationFormula;
1212
use crate::{ComponentGraph, Edge, Error, Node};
1313

1414
pub(crate) struct BatteryFormulaBuilder<'a, N, E>
@@ -97,7 +97,7 @@ mod tests {
9797
use std::collections::BTreeSet;
9898

9999
use crate::{
100-
graph::test_utils::ComponentGraphBuilder, ComponentGraphConfig, Error, InverterType,
100+
ComponentGraphConfig, Error, InverterType, graph::test_utils::ComponentGraphBuilder,
101101
};
102102

103103
#[test]
@@ -208,10 +208,10 @@ mod tests {
208208

209209
assert_eq!(unspec_inverter.component_id(), 20);
210210

211-
assert!(builder
212-
.build(None)
213-
.is_err_and(|x| x.to_string()
214-
== "InvalidComponent: InverterType not specified for inverter: 20"));
211+
assert!(
212+
builder.build(None).is_err_and(|x| x.to_string()
213+
== "InvalidComponent: InverterType not specified for inverter: 20")
214+
);
215215

216216
let graph = builder.build(Some(ComponentGraphConfig {
217217
allow_unspecified_inverters: true,

src/graph/formulas/generators/battery_ac_coalesce.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ use crate::component_category::CategoryPredicates;
77
use std::collections::BTreeSet;
88

99
use crate::{
10-
graph::formulas::{expr::Expr, CoalesceFormula},
1110
ComponentGraph, Edge, Error, Node,
11+
graph::formulas::{CoalesceFormula, expr::Expr},
1212
};
1313

1414
use super::battery::BatteryFormulaBuilder;
@@ -83,7 +83,7 @@ mod tests {
8383
use std::collections::BTreeSet;
8484

8585
use crate::{
86-
graph::test_utils::ComponentGraphBuilder, ComponentGraphConfig, Error, InverterType,
86+
ComponentGraphConfig, Error, InverterType, graph::test_utils::ComponentGraphBuilder,
8787
};
8888

8989
#[test]
@@ -184,10 +184,10 @@ mod tests {
184184

185185
assert_eq!(unspec_inverter.component_id(), 20);
186186

187-
assert!(builder
188-
.build(None)
189-
.is_err_and(|x| x.to_string()
190-
== "InvalidComponent: InverterType not specified for inverter: 20"));
187+
assert!(
188+
builder.build(None).is_err_and(|x| x.to_string()
189+
== "InvalidComponent: InverterType not specified for inverter: 20")
190+
);
191191

192192
let graph = builder.build(Some(ComponentGraphConfig {
193193
allow_unspecified_inverters: true,

src/graph/formulas/generators/chp.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@
66
use std::collections::BTreeSet;
77

88
use crate::component_category::CategoryPredicates;
9+
use crate::graph::formulas::AggregationFormula;
910
use crate::graph::formulas::expr::Expr;
1011
use crate::graph::formulas::fallback::FallbackExpr;
11-
use crate::graph::formulas::AggregationFormula;
1212
use crate::{ComponentGraph, Edge, Error, Node};
1313

1414
pub(crate) struct CHPFormulaBuilder<'a, N, E>
@@ -72,7 +72,7 @@ where
7272
mod tests {
7373
use std::collections::BTreeSet;
7474

75-
use crate::{graph::test_utils::ComponentGraphBuilder, Error};
75+
use crate::{Error, graph::test_utils::ComponentGraphBuilder};
7676

7777
#[test]
7878
fn test_chp_formula() -> Result<(), Error> {

src/graph/formulas/generators/consumer.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@ use std::collections::{BTreeMap, BTreeSet};
77

88
use super::super::expr::Expr;
99
use crate::{
10-
component_category::CategoryPredicates,
11-
graph::formulas::{fallback::FallbackExpr, AggregationFormula},
1210
ComponentGraph, Edge, Error, Node,
11+
component_category::CategoryPredicates,
12+
graph::formulas::{AggregationFormula, fallback::FallbackExpr},
1313
};
1414

1515
pub(crate) struct ConsumerFormulaBuilder<'a, N, E>
@@ -126,7 +126,7 @@ where
126126
#[cfg(test)]
127127
mod tests {
128128
use super::*;
129-
use crate::{graph::test_utils::ComponentGraphBuilder, ComponentGraphConfig};
129+
use crate::{ComponentGraphConfig, graph::test_utils::ComponentGraphBuilder};
130130

131131
#[test]
132132
fn test_zero_consumers() -> Result<(), Error> {

0 commit comments

Comments
 (0)