Skip to content

Commit 8343c84

Browse files
committed
cleanups
1 parent b7992dc commit 8343c84

File tree

2 files changed

+7
-51
lines changed

2 files changed

+7
-51
lines changed

src/generate/peripheral.rs

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1114,7 +1114,7 @@ fn name_to_ty_str<'a, 'b>(name: &'a str, ns: Option<&'b str>) -> Cow<'a, str> {
11141114

11151115
fn name_to_ty(name: &str, ns: Option<&str>) -> Result<syn::Type, syn::Error> {
11161116
let ident = name_to_ty_str(name, ns);
1117-
Ok(syn::Type::Path(parse_str::<syn::TypePath>(&ident)?))
1117+
parse_str::<syn::TypePath>(&ident).map(syn::Type::Path)
11181118
}
11191119

11201120
fn name_to_wrapped_ty_str(name: &str, ns: Option<&str>) -> String {
@@ -1136,14 +1136,8 @@ fn name_to_wrapped_ty_str(name: &str, ns: Option<&str>) -> String {
11361136

11371137
fn name_to_wrapped_ty(name: &str, ns: Option<&str>) -> Result<syn::Type> {
11381138
let ident = name_to_wrapped_ty_str(name, ns);
1139-
match parse_str::<syn::TypePath>(&ident) {
1140-
Ok(path) => Ok(syn::Type::Path(path)),
1141-
Err(e) => {
1142-
let mut res = Err(e.into());
1143-
res = res.with_context(|| {
1144-
format!("Determining syn::TypePath from ident \"{}\" failed", ident)
1145-
});
1146-
res
1147-
}
1148-
}
1139+
parse_str::<syn::TypePath>(&ident)
1140+
.map(syn::Type::Path)
1141+
.map_err(anyhow::Error::from)
1142+
.with_context(|| format!("Determining syn::TypePath from ident \"{}\" failed", ident))
11491143
}

src/util.rs

Lines changed: 2 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
use std::borrow::Cow;
22

3-
use crate::svd::{
4-
Access, Cluster, Device, Field, Register, RegisterCluster, RegisterInfo, RegisterProperties,
5-
};
3+
use crate::svd::{Access, Cluster, Device, Field, Register, RegisterInfo, RegisterProperties};
64
use inflections::Inflect;
75
use proc_macro2::{Ident, Literal, Span, TokenStream};
86
use quote::{quote, ToTokens};
@@ -333,7 +331,7 @@ pub fn register_path_to_ty(
333331
}
334332
ident.push_str("::");
335333
ident.push_str(&rpath.name.to_sanitized_snake_case());
336-
Ok(syn::Type::Path(parse_str::<syn::TypePath>(&ident)?))
334+
parse_str::<syn::TypePath>(&ident).map(syn::Type::Path)
337335
}
338336

339337
pub trait U32Ext {
@@ -393,42 +391,6 @@ impl U32Ext for u32 {
393391
}
394392
}
395393

396-
/// Return the name of either register or cluster.
397-
pub fn erc_name(erc: &RegisterCluster) -> &String {
398-
match erc {
399-
RegisterCluster::Register(r) => &r.name,
400-
RegisterCluster::Cluster(c) => &c.name,
401-
}
402-
}
403-
404-
/// Return the name of either register or cluster from which this register or cluster is derived.
405-
pub fn erc_derived_from(erc: &RegisterCluster) -> &Option<String> {
406-
match erc {
407-
RegisterCluster::Register(r) => &r.derived_from,
408-
RegisterCluster::Cluster(c) => &c.derived_from,
409-
}
410-
}
411-
412-
/// Return only the clusters from the slice of either register or clusters.
413-
pub fn only_clusters(ercs: &[RegisterCluster]) -> Vec<&Cluster> {
414-
ercs.iter()
415-
.filter_map(|x| match x {
416-
RegisterCluster::Cluster(x) => Some(x),
417-
_ => None,
418-
})
419-
.collect()
420-
}
421-
422-
/// Return only the registers the given slice of either register or clusters.
423-
pub fn only_registers(ercs: &[RegisterCluster]) -> Vec<&Register> {
424-
ercs.iter()
425-
.filter_map(|x| match x {
426-
RegisterCluster::Register(x) => Some(x),
427-
_ => None,
428-
})
429-
.collect()
430-
}
431-
432394
pub fn build_rs() -> TokenStream {
433395
quote! {
434396
use std::env;

0 commit comments

Comments
 (0)