diff --git a/svd-parser/src/expand.rs b/svd-parser/src/expand.rs index ca6423c..2e1abd7 100644 --- a/svd-parser/src/expand.rs +++ b/svd-parser/src/expand.rs @@ -1,7 +1,7 @@ //! Provides [expand] method to convert arrays, clusters and derived items in regular instances use anyhow::{anyhow, Result}; -use std::{collections::HashMap, fmt, mem::take, ops::Deref}; +use std::{collections::HashMap, fmt, mem::take, ops::Deref, rc::Rc}; use svd_rs::{ array::names, cluster, field, peripheral, register, Cluster, ClusterInfo, DeriveFrom, Device, EnumeratedValues, Field, Peripheral, Register, RegisterCluster, RegisterProperties, @@ -10,23 +10,23 @@ use svd_rs::{ /// Path to `peripheral` or `cluster` element #[derive(Clone, Debug, PartialEq, Hash, Eq)] pub struct BlockPath { - pub peripheral: String, - pub path: Vec, + pub peripheral: Rc, + pub path: Vec>, } impl BlockPath { - pub fn new(p: impl Into) -> Self { + pub fn new(p: impl Into>) -> Self { Self { peripheral: p.into(), path: Vec::new(), } } - pub fn new_cluster(&self, name: impl Into) -> Self { + pub fn new_cluster(&self, name: impl Into>) -> Self { let mut child = self.clone(); child.path.push(name.into()); child } - pub fn new_register(&self, name: impl Into) -> RegisterPath { + pub fn new_register(&self, name: impl Into>) -> RegisterPath { RegisterPath::new(self.clone(), name) } pub fn parse_str(s: &str) -> (Option, &str) { @@ -44,7 +44,7 @@ impl BlockPath { }; (block, name) } - pub fn name(&self) -> &String { + pub fn name(&self) -> &str { self.path.last().unwrap() } pub fn parent(&self) -> Option { @@ -91,17 +91,17 @@ impl fmt::Display for BlockPath { #[derive(Clone, Debug, PartialEq, Hash, Eq)] pub struct RegisterPath { pub block: BlockPath, - pub name: String, + pub name: Rc, } impl RegisterPath { - pub fn new(block: BlockPath, name: impl Into) -> Self { + pub fn new(block: BlockPath, name: impl Into>) -> Self { Self { block, name: name.into(), } } - pub fn new_field(&self, name: impl Into) -> FieldPath { + pub fn new_field(&self, name: impl Into>) -> FieldPath { FieldPath::new(self.clone(), name) } pub fn parse_str(s: &str) -> (Option, &str) { @@ -110,7 +110,7 @@ impl RegisterPath { pub fn parse_vec(v: Vec<&str>) -> (Option, &str) { BlockPath::parse_vec(v) } - pub fn peripheral(&self) -> &String { + pub fn peripheral(&self) -> &str { &self.block.peripheral } } @@ -138,17 +138,17 @@ impl fmt::Display for RegisterPath { #[derive(Clone, Debug, PartialEq, Hash, Eq)] pub struct FieldPath { pub register: RegisterPath, - pub name: String, + pub name: Rc, } impl FieldPath { - pub fn new(register: RegisterPath, name: impl Into) -> Self { + pub fn new(register: RegisterPath, name: impl Into>) -> Self { Self { register, name: name.into(), } } - pub fn new_enum(&self, name: impl Into) -> EnumPath { + pub fn new_enum(&self, name: impl Into>) -> EnumPath { EnumPath::new(self.clone(), name) } pub fn parse_str(s: &str) -> (Option, &str) { @@ -170,7 +170,7 @@ impl FieldPath { pub fn register(&self) -> &RegisterPath { &self.register } - pub fn peripheral(&self) -> &String { + pub fn peripheral(&self) -> &str { self.register.peripheral() } } @@ -198,11 +198,11 @@ impl fmt::Display for FieldPath { #[derive(Clone, Debug, PartialEq, Hash, Eq)] pub struct EnumPath { pub field: FieldPath, - pub name: String, + pub name: Rc, } impl EnumPath { - pub fn new(field: FieldPath, name: impl Into) -> Self { + pub fn new(field: FieldPath, name: impl Into>) -> Self { Self { field, name: name.into(), @@ -214,7 +214,7 @@ impl EnumPath { pub fn register(&self) -> &RegisterPath { &self.field.register } - pub fn peripheral(&self) -> &String { + pub fn peripheral(&self) -> &str { self.field.peripheral() } }