Skip to content

Commit

Permalink
add maybe_array constructors
Browse files Browse the repository at this point in the history
  • Loading branch information
burrbull committed Feb 13, 2024
1 parent 366e2fd commit 7b9e9ad
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 0 deletions.
1 change: 1 addition & 0 deletions svd-rs/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).

## Unreleased

- add `maybe_array` constructors
- Bump MSRV to 1.65.0
- Bump `regex` to 1.10

Expand Down
8 changes: 8 additions & 0 deletions svd-rs/src/cluster.rs
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,14 @@ impl ClusterInfo {
pub const fn array(self, dim: DimElement) -> Cluster {
Cluster::Array(self, dim)
}
/// Construct single [`Cluster`] or array
pub fn maybe_array(self, dim: Option<DimElement>) -> Cluster {
if let Some(dim) = dim {
self.array(dim)
} else {
self.single()
}
}
/// Modify an existing [`ClusterInfo`] based on a [builder](ClusterInfoBuilder).
pub fn modify_from(
&mut self,
Expand Down
8 changes: 8 additions & 0 deletions svd-rs/src/field.rs
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,14 @@ impl FieldInfo {
pub const fn array(self, dim: DimElement) -> Field {
Field::Array(self, dim)
}
/// Construct single [`Field`] or array
pub fn maybe_array(self, dim: Option<DimElement>) -> Field {
if let Some(dim) = dim {
self.array(dim)
} else {
self.single()
}
}
/// Modify an existing [`FieldInfo`] based on a [builder](FieldInfoBuilder).
pub fn modify_from(
&mut self,
Expand Down
8 changes: 8 additions & 0 deletions svd-rs/src/peripheral.rs
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,14 @@ impl PeripheralInfo {
pub const fn array(self, dim: DimElement) -> Peripheral {
Peripheral::Array(self, dim)
}
/// Construct single [`Peripheral`] or array
pub fn maybe_array(self, dim: Option<DimElement>) -> Peripheral {
if let Some(dim) = dim {
self.array(dim)
} else {
self.single()
}
}
/// Modify an existing [`Peripheral`] based on a [builder](PeripheralInfoBuilder).
pub fn modify_from(
&mut self,
Expand Down
8 changes: 8 additions & 0 deletions svd-rs/src/register.rs
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,14 @@ impl RegisterInfo {
pub const fn array(self, dim: DimElement) -> Register {
Register::Array(self, dim)
}
/// Construct single [`Register`] or array
pub fn maybe_array(self, dim: Option<DimElement>) -> Register {
if let Some(dim) = dim {
self.array(dim)
} else {
self.single()
}
}
/// Modify an existing [`RegisterInfo`] based on a [builder](RegisterInfoBuilder).
pub fn modify_from(
&mut self,
Expand Down

0 comments on commit 7b9e9ad

Please sign in to comment.