use crate::{
Ctx,
ast::{
CodeFormatter, ComplexAttri, ComplexParseError, GroupComments, GroupFn, GroupSet,
Indentation, NamedGroup, ParseScope, SimpleAttri, SimpleParseRes, join_fmt,
},
common::items::{NameList, WordSet},
expression::{LogicBooleanExpression, PowerGroundBooleanExpression, logic},
pin::Direction,
table::CompactCcsPower,
};
use core::{
fmt::{self, Write},
hash::Hash,
str::FromStr,
};
#[derive(Debug, Clone)]
#[derive(liberty_macros::Group)]
#[mut_set::derive::item]
#[derive(serde::Serialize, serde::Deserialize)]
#[serde(bound = "C::Other: serde::Serialize + serde::de::DeserializeOwned")]
pub struct LeakagePower<C: Ctx> {
#[id]
#[liberty(name)]
pub name: Vec<String>,
#[liberty(comments)]
comments: GroupComments,
#[liberty(extra_ctx)]
pub extra_ctx: C::Other,
#[liberty(attributes)]
pub attributes: crate::ast::Attributes,
#[id]
#[liberty(simple(type = Option))]
pub power_level: Option<String>,
#[id]
#[liberty(simple)]
pub related_pg_pin: NameList,
#[id]
#[liberty(simple(type = Option))]
pub when: Option<LogicBooleanExpression>,
#[liberty(simple)]
pub value: f64,
#[liberty(complex(type = Option))]
pub mode: Option<[String; 2]>,
}
impl<C: Ctx> GroupFn<C> for LeakagePower<C> {}
#[cfg(test)]
mod test_sort {
use super::*;
use crate::DefaultCtx;
#[test]
fn test_leakage_sort() {
let cell = crate::ast::test_parse::<crate::Cell<DefaultCtx>>(
r#"(CELL) {
pin(A){}
pin(B){}
pin(Y){}
leakage_power () {
related_pg_pin : VDD;
value : 1;
}
leakage_power () {
related_pg_pin : VDD;
when : "A*B*Y";
value : 2;
}
leakage_power () {
related_pg_pin : VDD;
when : "!A*B*!Y";
value : 3;
}
leakage_power () {
related_pg_pin : VDD;
when : "A*!B*!Y";
value : 4;
}
leakage_power () {
related_pg_pin : VDD;
when : "!A*!B*!Y";
value : 5;
}
leakage_power () {
related_pg_pin : VSS;
value : 6;
}
leakage_power () {
related_pg_pin : VSS;
when : "A*B*Y";
value : 7;
}
leakage_power () {
related_pg_pin : VSS;
when : "!A*B*!Y";
value : 8;
}
leakage_power () {
related_pg_pin : VSS;
when : "A*!B*!Y";
value : 9;
}
leakage_power () {
related_pg_pin : VSS;
when : "!A*!B*!Y";
value : 10;
}
}
"#,
);
assert_eq!(
vec![1, 2, 3, 4, 5, 6, 7, 8, 9, 10],
cell
.leakage_power
.iter()
.map(|leakage| leakage.value as i8)
.collect::<Vec<_>>()
);
}
}
#[derive(Debug, Clone)]
#[derive(liberty_macros::Group)]
#[mut_set::derive::item]
#[derive(serde::Serialize, serde::Deserialize)]
#[serde(bound = "C::Other: serde::Serialize + serde::de::DeserializeOwned")]
pub struct Statetable<C: Ctx> {
#[id]
#[liberty(name)]
pub input_nodes: Vec<String>,
#[id]
#[liberty(name)]
pub internal_nodes: Vec<String>,
#[liberty(comments)]
comments: GroupComments,
#[liberty(extra_ctx)]
pub extra_ctx: C::Other,
#[liberty(attributes)]
pub attributes: crate::ast::Attributes,
#[liberty(simple)]
pub table: Table,
}
impl<C: Ctx> GroupFn<C> for Statetable<C> {}
impl<C: Ctx> NamedGroup<C> for Statetable<C> {
#[inline]
fn parse_set_name(
builder: &mut Self::Builder,
mut v: Vec<&str>,
) -> Result<(), crate::ast::IdError> {
let l = v.len();
if l == 2 {
v.pop()
.map_or(Err(crate::ast::IdError::Other("Unkown pop error".into())), |var2| {
v.pop().map_or(
Err(crate::ast::IdError::Other("Unkown pop error".into())),
|var1| {
builder.input_nodes =
var1.split_ascii_whitespace().map(String::from).collect();
builder.internal_nodes =
var2.split_ascii_whitespace().map(String::from).collect();
Ok(())
},
)
})
} else {
Err(crate::ast::IdError::length_dismatch(2, l, v))
}
}
#[inline]
#[expect(clippy::indexing_slicing)]
fn fmt_name<T: Write, I: Indentation>(
&self,
f: &mut CodeFormatter<'_, T, I>,
) -> fmt::Result {
if self.input_nodes.len() == 1 {
write!(f, "{}", self.input_nodes[0])?;
} else {
join_fmt(self.input_nodes.iter(), f, |s, ff| write!(ff, "{s}"), " ")?;
}
write!(f, ", ")?;
if self.internal_nodes.len() == 1 {
write!(f, "{}", self.internal_nodes[0])
} else {
join_fmt(self.internal_nodes.iter(), f, |s, ff| write!(ff, "{s}"), " ")
}
}
}
#[derive(Default, Debug, Clone)]
#[derive(serde::Serialize, serde::Deserialize)]
pub struct Table {
pub v: Vec<String>,
}
impl fmt::Display for Table {
#[inline]
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
fmt::Debug::fmt(&self.v, f)
}
}
impl FromStr for Table {
type Err = fmt::Error;
#[inline]
fn from_str(s: &str) -> Result<Self, Self::Err> {
Ok(Self {
v: s
.split("\\\n")
.filter_map(|line| {
let _l = line
.trim_start()
.trim_end_matches(|c: char| c == ',' || c.is_ascii_whitespace());
if _l.is_empty() { None } else { Some(String::from(_l)) }
})
.collect(),
})
}
}
crate::ast::impl_self_builder!(Table);
impl<C: Ctx> SimpleAttri<C> for Table {
#[inline]
fn is_set(&self) -> bool {
!self.v.is_empty()
}
#[inline]
fn nom_parse<'a>(i: &'a str, scope: &mut ParseScope) -> SimpleParseRes<'a, Self> {
let (input, simple_multi) =
crate::ast::parser::simple_multi(i, &mut scope.loc.line_num)?;
simple_multi
.parse()
.map_or(Ok((input, Err(String::from(simple_multi)))), |s| Ok((input, Ok(s))))
}
#[inline]
fn fmt_self<T: Write, I: Indentation>(
&self,
f: &mut CodeFormatter<'_, T, I>,
) -> fmt::Result {
let indent = f.indentation();
join_fmt(
self.v.iter(),
f,
|i, ff| write!(ff, "{i}"),
format!(" ,\\\n{indent} ").as_str(),
)
}
}
#[cfg(test)]
mod test_statetable {
use super::*;
use crate::DefaultCtx;
#[test]
fn statetable_test() {
_ = crate::ast::test_parse_fmt::<Statetable<DefaultCtx>>(
r#"(" CLK EN SE",ENL) {
table : " H L L : - : L ,\
H L H : - : H ,\
H H L : - : H ,\
H H H : - : H ,\
L - - : - : N ";
}
"#,
r#"
liberty_db::cell::items::Statetable ("CLK EN SE", ENL) {
| table : "H L L : - : L ,\
| H L H : - : H ,\
| H H L : - : H ,\
| H H H : - : H ,\
| L - - : - : N";
}"#,
);
}
}
#[derive(Debug, Clone)]
#[derive(liberty_macros::Group)]
#[mut_set::derive::item]
#[derive(serde::Serialize, serde::Deserialize)]
#[serde(bound = "C::Other: serde::Serialize + serde::de::DeserializeOwned")]
pub struct PgPin<C: Ctx> {
#[liberty(name)]
#[id(borrow = str)]
pub name: String,
#[liberty(comments)]
comments: GroupComments,
#[liberty(extra_ctx)]
pub extra_ctx: C::Other,
#[liberty(attributes)]
pub attributes: crate::ast::Attributes,
#[liberty(simple(type = Option))]
pub direction: Option<Direction>,
#[liberty(simple)]
pub voltage_name: String,
#[liberty(simple)]
pub pg_type: PgType,
#[liberty(simple)]
pub user_pg_type: String,
#[liberty(simple)]
pub physical_connection: String,
#[liberty(simple)]
pub related_bias_pin: String,
#[liberty(simple(type = Option))]
pub std_cell_main_rail: Option<bool>,
#[liberty(simple(type = Option))]
pub pg_function: Option<PowerGroundBooleanExpression>,
#[liberty(simple(type = Option))]
pub switch_function: Option<LogicBooleanExpression>,
}
impl<C: Ctx> GroupFn<C> for PgPin<C> {}
#[derive(Debug, Clone)]
#[derive(liberty_macros::Group)]
#[mut_set::derive::item]
#[derive(serde::Serialize, serde::Deserialize)]
#[serde(bound = "C::Other: serde::Serialize + serde::de::DeserializeOwned")]
pub struct DynamicCurrent<C: Ctx> {
#[liberty(name)]
#[id]
pub name: Option<String>,
#[liberty(comments)]
comments: GroupComments,
#[liberty(extra_ctx)]
pub extra_ctx: C::Other,
#[liberty(attributes)]
pub attributes: crate::ast::Attributes,
#[id]
#[liberty(simple(type = Option))]
pub when: Option<LogicBooleanExpression>,
#[id]
#[liberty(simple)]
pub related_inputs: NameList,
#[id]
#[liberty(simple)]
pub related_outputs: NameList,
#[liberty(complex(type = Option))]
pub typical_capacitances: Option<Vec<f64>>,
#[liberty(group(type = Set))]
pub switching_group: GroupSet<SwitchingGroup<C>>,
}
impl<C: Ctx> GroupFn<C> for DynamicCurrent<C> {}
#[derive(Debug, Clone)]
#[derive(liberty_macros::Group)]
#[mut_set::derive::item]
#[derive(serde::Serialize, serde::Deserialize)]
#[serde(bound = "C::Other: serde::Serialize + serde::de::DeserializeOwned")]
pub struct SwitchingGroup<C: Ctx> {
#[liberty(name)]
#[id]
pub name: Option<String>,
#[liberty(comments)]
comments: GroupComments,
#[liberty(extra_ctx)]
pub extra_ctx: C::Other,
#[liberty(attributes)]
pub attributes: crate::ast::Attributes,
#[id]
#[liberty(complex(type = Option))]
pub input_switching_condition: Option<logic::Edge>,
#[id]
#[liberty(complex(type = Option))]
pub output_switching_condition: Option<logic::Edge>,
#[liberty(simple(type = Option))]
pub min_input_switching_count: Option<usize>,
#[liberty(simple(type = Option))]
pub max_input_switching_count: Option<usize>,
#[liberty(group(type = Set))]
pub pg_current: GroupSet<PgCurrent<C>>,
}
impl<C: Ctx> GroupFn<C> for SwitchingGroup<C> {}
#[derive(Debug, Clone)]
#[derive(liberty_macros::Group)]
#[mut_set::derive::item]
#[derive(serde::Serialize, serde::Deserialize)]
#[serde(bound = "C::Other: serde::Serialize + serde::de::DeserializeOwned")]
pub struct PgCurrent<C: Ctx> {
#[liberty(name)]
#[id]
pub name: Option<String>,
#[liberty(comments)]
comments: GroupComments,
#[liberty(extra_ctx)]
pub extra_ctx: C::Other,
#[liberty(attributes)]
pub attributes: crate::ast::Attributes,
#[liberty(group(type = Set))]
#[liberty(after_build = crate::table::use_compact_template!)]
pub compact_ccs_power: GroupSet<CompactCcsPower<C>>,
}
impl<C: Ctx> GroupFn<C> for PgCurrent<C> {}
#[derive(Debug, Clone)]
#[derive(liberty_macros::Group)]
#[mut_set::derive::item]
#[derive(serde::Serialize, serde::Deserialize)]
#[serde(bound = "C::Other: serde::Serialize + serde::de::DeserializeOwned")]
pub struct IntrinsicParasitic<C: Ctx> {
#[liberty(name)]
pub name: Option<String>,
#[liberty(comments)]
comments: GroupComments,
#[liberty(extra_ctx)]
pub extra_ctx: C::Other,
#[liberty(attributes)]
pub attributes: crate::ast::Attributes,
#[id]
#[liberty(simple(type = Option))]
pub when: Option<LogicBooleanExpression>,
#[id]
#[liberty(simple(type = Option))]
pub reference_pg_pin: Option<String>,
#[liberty(complex(type = Option))]
pub mode: Option<[String; 2]>,
#[liberty(group(type = Set))]
pub intrinsic_capacitance: GroupSet<IntrinsicCapacitance<C>>,
#[liberty(group(type = Set))]
pub intrinsic_resistance: GroupSet<IntrinsicResistance<C>>,
#[liberty(group(type = Set))]
pub total_capacitance: GroupSet<PgPinWithValue<C>>,
}
impl<C: Ctx> GroupFn<C> for IntrinsicParasitic<C> {}
#[derive(Debug, Clone)]
#[derive(liberty_macros::Group)]
#[mut_set::derive::item]
#[derive(serde::Serialize, serde::Deserialize)]
#[serde(bound = "C::Other: serde::Serialize + serde::de::DeserializeOwned")]
pub struct IntrinsicCapacitance<C: Ctx> {
#[liberty(name)]
pub name: Option<String>,
#[liberty(comments)]
comments: GroupComments,
#[liberty(extra_ctx)]
pub extra_ctx: C::Other,
#[liberty(attributes)]
pub attributes: crate::ast::Attributes,
#[id(into_hash_ord_fn = crate::common::f64_into_hash_ord_fn)]
#[liberty(simple)]
pub value: f64,
#[id]
#[liberty(simple(type = Option))]
pub reference_pg_pin: Option<String>,
#[liberty(group(type = Option))]
pub lut_values: Option<LutValues<C>>,
}
impl<C: Ctx> GroupFn<C> for IntrinsicCapacitance<C> {}
#[derive(Debug, Clone)]
#[derive(liberty_macros::Group)]
#[mut_set::derive::item]
#[derive(serde::Serialize, serde::Deserialize)]
#[serde(bound = "C::Other: serde::Serialize + serde::de::DeserializeOwned")]
pub struct IntrinsicResistance<C: Ctx> {
#[liberty(name)]
pub name: Option<String>,
#[liberty(comments)]
comments: GroupComments,
#[liberty(extra_ctx)]
pub extra_ctx: C::Other,
#[liberty(attributes)]
pub attributes: crate::ast::Attributes,
#[liberty(simple)]
#[liberty(default = f64::INFINITY)]
pub value: f64,
#[id]
#[liberty(simple(type = Option))]
pub related_output: Option<String>,
#[id]
#[liberty(simple(type = Option))]
pub reference_pg_pin: Option<String>,
#[liberty(group(type = Option))]
pub lut_values: Option<LutValues<C>>,
}
impl<C: Ctx> GroupFn<C> for IntrinsicResistance<C> {}
#[derive(Debug, Clone)]
#[derive(liberty_macros::Group)]
#[mut_set::derive::item]
#[derive(serde::Serialize, serde::Deserialize)]
#[serde(bound = "C::Other: serde::Serialize + serde::de::DeserializeOwned")]
pub struct PgPinWithValue<C: Ctx> {
#[id]
#[liberty(name)]
pg_pin_name: Option<String>,
#[liberty(comments)]
comments: GroupComments,
#[liberty(extra_ctx)]
pub extra_ctx: C::Other,
#[liberty(attributes)]
pub attributes: crate::ast::Attributes,
#[liberty(simple)]
pub value: f64,
}
impl<C: Ctx> GroupFn<C> for PgPinWithValue<C> {}
#[derive(Debug, Clone)]
#[derive(liberty_macros::Group)]
#[mut_set::derive::item]
#[derive(serde::Serialize, serde::Deserialize)]
#[serde(bound = "C::Other: serde::Serialize + serde::de::DeserializeOwned")]
pub struct GateLeakage<C: Ctx> {
#[id]
#[liberty(name)]
input_pin_name: Option<String>,
#[liberty(comments)]
comments: GroupComments,
#[liberty(extra_ctx)]
pub extra_ctx: C::Other,
#[liberty(attributes)]
pub attributes: crate::ast::Attributes,
#[liberty(simple(type = Option))]
pub input_low_value: Option<f64>,
#[liberty(simple(type = Option))]
pub input_high_value: Option<f64>,
}
impl<C: Ctx> GroupFn<C> for GateLeakage<C> {}
#[derive(Debug, Clone)]
#[derive(liberty_macros::Group)]
#[mut_set::derive::item]
#[derive(serde::Serialize, serde::Deserialize)]
#[serde(bound = "C::Other: serde::Serialize + serde::de::DeserializeOwned")]
pub struct LeakageCurrent<C: Ctx> {
#[liberty(name)]
pub name: Option<String>,
#[liberty(comments)]
comments: GroupComments,
#[liberty(extra_ctx)]
pub extra_ctx: C::Other,
#[liberty(attributes)]
pub attributes: crate::ast::Attributes,
#[id]
#[liberty(simple(type = Option))]
pub when: Option<LogicBooleanExpression>,
#[liberty(simple(type = Option))]
pub value: Option<f64>,
#[liberty(complex(type = Option))]
pub mode: Option<[String; 2]>,
#[liberty(group(type = Set))]
pub pg_current: GroupSet<PgPinWithValue<C>>,
#[liberty(group(type = Set))]
pub gate_leakage: GroupSet<GateLeakage<C>>,
}
impl<C: Ctx> GroupFn<C> for LeakageCurrent<C> {}
#[derive(Debug, Clone)]
#[derive(liberty_macros::Group)]
#[derive(serde::Serialize, serde::Deserialize)]
#[serde(bound = "C::Other: serde::Serialize + serde::de::DeserializeOwned")]
pub struct LutValues<C: Ctx> {
#[liberty(name)]
pub name: Option<String>,
#[liberty(comments)]
comments: GroupComments,
#[liberty(extra_ctx)]
pub extra_ctx: C::Other,
#[liberty(attributes)]
pub attributes: crate::ast::Attributes,
#[liberty(complex)]
pub index_1: Vec<f64>,
#[liberty(complex)]
pub values: Vec<f64>,
}
impl<C: Ctx> GroupFn<C> for LutValues<C> {}
#[derive(Debug, Clone, Copy)]
#[derive(Hash, PartialEq, Eq)]
#[derive(Ord, PartialOrd, Default)]
#[derive(strum::EnumString, strum::EnumIter, strum::Display, strum::AsRefStr)]
#[derive(serde::Serialize, serde::Deserialize)]
pub enum PgType {
#[strum(serialize = "primary_power")]
PrimaryPower,
#[strum(serialize = "primary_ground")]
PrimaryGround,
#[strum(serialize = "backup_power")]
BackupPower,
#[strum(serialize = "backup_ground")]
#[default]
BackupGround,
#[strum(serialize = "internal_power")]
InternalPower,
#[strum(serialize = "internal_ground")]
InternalGround,
#[strum(serialize = "pwell")]
Pwell,
#[strum(serialize = "nwell")]
Nwell,
#[strum(serialize = "deepnwell")]
DeepNwell,
#[strum(serialize = "deeppwell")]
DeepPwell,
}
crate::ast::impl_self_builder!(PgType);
impl<C: Ctx> SimpleAttri<C> for PgType {
#[inline]
fn nom_parse<'a>(i: &'a str, scope: &mut ParseScope) -> SimpleParseRes<'a, Self> {
crate::ast::nom_parse_from_str::<C, _>(i, scope)
}
}
#[derive(Debug, Clone, Copy)]
#[derive(Hash, PartialEq, Eq)]
#[derive(Ord, PartialOrd)]
#[derive(strum::EnumString, strum::EnumIter, strum::Display)]
#[derive(serde::Serialize, serde::Deserialize)]
pub enum SwitchCellType {
#[strum(serialize = "coarse_grain")]
CoarseGrain,
#[strum(serialize = "fine_grain")]
FineGrain,
}
crate::ast::impl_self_builder!(SwitchCellType);
impl<C: Ctx> SimpleAttri<C> for SwitchCellType {
#[inline]
fn nom_parse<'a>(i: &'a str, scope: &mut ParseScope) -> SimpleParseRes<'a, Self> {
crate::ast::nom_parse_from_str::<C, _>(i, scope)
}
}
#[derive(Debug, Clone, Copy)]
#[derive(Hash, PartialEq, Eq)]
#[derive(Ord, PartialOrd)]
#[derive(strum::EnumString, strum::EnumIter, strum::Display)]
#[derive(serde::Serialize, serde::Deserialize)]
pub enum FpgaCellType {
#[strum(serialize = "rising_edge_clock_cell")]
RisingEdgeClockCell,
#[strum(serialize = "falling_edge_clock_cell")]
FallingEdgeClockCell,
}
crate::ast::impl_self_builder!(FpgaCellType);
impl<C: Ctx> SimpleAttri<C> for FpgaCellType {
#[inline]
fn nom_parse<'a>(i: &'a str, scope: &mut ParseScope) -> SimpleParseRes<'a, Self> {
crate::ast::nom_parse_from_str::<C, _>(i, scope)
}
}
#[expect(non_camel_case_types)]
#[derive(Debug, Clone, Copy)]
#[derive(Hash, PartialEq, Eq)]
#[derive(Ord, PartialOrd)]
#[derive(strum::EnumString, strum::EnumIter, strum::Display)]
#[derive(serde::Serialize, serde::Deserialize)]
pub enum LevelShifterType {
#[strum(serialize = "LH")]
LH,
#[strum(serialize = "HL")]
HL,
#[strum(serialize = "HL_LH")]
HL_LH,
}
crate::ast::impl_self_builder!(LevelShifterType);
impl<C: Ctx> SimpleAttri<C> for LevelShifterType {
#[inline]
fn nom_parse<'a>(i: &'a str, scope: &mut ParseScope) -> SimpleParseRes<'a, Self> {
crate::ast::nom_parse_from_str::<C, _>(i, scope)
}
}
#[derive(Debug, Clone)]
#[derive(Hash, PartialEq, Eq)]
#[derive(Ord, PartialOrd)]
#[derive(serde::Serialize, serde::Deserialize)]
pub enum ClockGatingIntegratedCell {
ContainlatchNegedge,
RegisterslatchPosedgePostcontrol,
LatchlatchNegedgePrecontrol,
LatchnonePosedgeControlObs,
Generic(String),
}
impl FromStr for ClockGatingIntegratedCell {
type Err = ();
#[inline]
fn from_str(s: &str) -> Result<Self, Self::Err> {
match s {
"containlatch_negedge" => Ok(Self::ContainlatchNegedge),
"registerslatch_posedge_postcontrol" => Ok(Self::RegisterslatchPosedgePostcontrol),
"latchlatch_negedge_precontrol" => Ok(Self::LatchlatchNegedgePrecontrol),
"latchnone_posedge_control_obs" => Ok(Self::LatchnonePosedgeControlObs),
_ => Ok(Self::Generic(s.into())),
}
}
}
impl fmt::Display for ClockGatingIntegratedCell {
#[inline]
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Self::ContainlatchNegedge => write!(f, "containlatch_negedge"),
Self::RegisterslatchPosedgePostcontrol => {
write!(f, "registerslatch_posedge_postcontrol")
}
Self::LatchlatchNegedgePrecontrol => write!(f, "latchlatch_negedge_precontrol"),
Self::LatchnonePosedgeControlObs => write!(f, "latchnone_posedge_control_obs"),
Self::Generic(s) => write!(f, "{s}"),
}
}
}
crate::ast::impl_self_builder!(ClockGatingIntegratedCell);
impl<C: Ctx> SimpleAttri<C> for ClockGatingIntegratedCell {
#[inline]
fn nom_parse<'a>(i: &'a str, scope: &mut ParseScope) -> SimpleParseRes<'a, Self> {
crate::ast::nom_parse_from_str::<C, _>(i, scope)
}
}
#[derive(Debug, Clone)]
#[derive(Hash, PartialEq, Eq)]
#[derive(Ord, PartialOrd)]
#[derive(serde::Serialize, serde::Deserialize)]
pub struct PinOpposite {
pub name_list1: WordSet,
pub name_list2: WordSet,
}
crate::ast::impl_self_builder!(PinOpposite);
impl<C: Ctx> ComplexAttri<C> for PinOpposite {
#[inline]
fn parse<'a, I: Iterator<Item = &'a &'a str>>(
mut iter: I,
_scope: &mut ParseScope,
) -> Result<Self, ComplexParseError> {
let name_list1: WordSet = match iter.next() {
Some(&s) => match s.parse() {
Ok(f) => f,
Err(_) => return Err(ComplexParseError::Other),
},
None => return Err(ComplexParseError::LengthDismatch),
};
let name_list2: WordSet = match iter.next() {
Some(&s) => match s.parse() {
Ok(f) => f,
Err(_) => return Err(ComplexParseError::Other),
},
None => return Err(ComplexParseError::LengthDismatch),
};
if iter.next().is_some() {
Err(ComplexParseError::LengthDismatch)
} else {
Ok(Self { name_list1, name_list2 })
}
}
#[inline]
fn fmt_self<T: Write, I: Indentation>(
&self,
f: &mut CodeFormatter<'_, T, I>,
) -> fmt::Result {
write!(f, "{}, {}", self.name_list1, self.name_list2)
}
}