pub fn to_expression(&self) -> Result<String, PacketError> {
        match &self.kind {
            PacketKind::Literal(value) => Ok(value.to_string()),
            PacketKind::Operator {
                operation, packets, ..
            } => {
                let mut packet_expressions = packets
                    .iter()
                    .map(Self::to_expression)
                    .collect::<Result<Vec<_>, _>>()?
                    .into_iter()
                    .zip(packets.iter())
                    .map(|(expr, packet)| match packet.kind {
                        PacketKind::Operator { operation, .. } if !operation.is_function() => {
                            format!("({})", expr)
                        }
                        _ => expr,
                    });
                if operation.is_function() {
                    Ok(format!(
                        "{func}({args})",
                        func = operation.to_string(),
                        args = packet_expressions.join(", ")
                    ))
                } else {
                    let args = packet_expressions.collect_vec();
                    Ok(match args.len() {
                        1 => {
                            format!(
                                "{func}({args})",
                                func = operation.as_func_str(),
                                args = args.join(", ")
                            )
                        }
                        _ => args.join(&format!(" {} ", operation.to_string())),
                    })
                }
            }
        }
    }
/// Renders to mathematical expression representation.
///
/// # Errors
///
/// Will return `Err` if packet does not evaluate properly.
Renders to mathematical expression representation.
Renders to mathematical expression representation .
pub fn to_expression(&self) -> Result<String, PacketError> {
        match &self.kind {
            PacketKind::Literal(value) => Ok(value.to_string()),
            PacketKind::Operator {
                operation, packets, ..
            } => {
                let mut packet_expressions = packets
                    .iter()
                    .map(Self::to_expression)
                    .collect::<Result<Vec<_>, _>>()?
                    .into_iter()
                    .zip(packets.iter())
                    .map(|(expr, packet)| match packet.kind {
                        PacketKind::Operator { operation, .. } if !operation.is_function() => {
                            format!("({})", expr)
                        }
                        _ => expr,
                    });
                if operation.is_function() {
                    Ok(format!(
                        "{func}({args})",
                        func = operation.to_string(),
                        args = packet_expressions.join(", ")
                    ))
                } else {
                    let args = packet_expressions.collect_vec();
                    Ok(match args.len() {
                        1 => {
                            format!(
                                "{func}({args})",
                                func = operation.as_func_str(),
                                args = args.join(", ")
                            )
                        }
                        _ => args.join(&format!(" {} ", operation.to_string())),
                    })
                }
            }
        }
    }
pub fn to_expression ( & self ) -> Result < String , PacketError > { match & self . kind { PacketKind :: Literal ( value ) => Ok ( value . to_string ( ) ) , PacketKind :: Operator { operation , packets , .. } => { let mut packet_expressions = packets . iter ( ) . map ( Self :: to_expression ) . collect :: < Result < Vec < _ > , _ > > ( ) ? . into_iter ( ) . zip ( packets . iter ( ) ) . map ( | ( expr , packet ) | match packet . kind { PacketKind :: Operator { operation , .. } if ! operation . is_function ( ) => { format ! ( " " expr ) } _ => expr , } ) ; if operation . is_function ( ) { Ok ( format ! ( " " func operation to_string ( ) args packet_expressions join ( " " ) ) ) } else { let args = packet_expressions . collect_vec ( ) ; Ok ( match args . len ( ) { 1 => { format ! ( " " func operation as_func_str ( ) args args join ( " " ) ) } _ => args . join ( & format ! ( " " operation to_string ( ) ) ) , } ) } } } }
Renders to mathematical expression representation.
Renders to mathematical expression representation .
&self
&self
errors
Will return `Err` if packet does not evaluate properly.
Will return ` Err ` if packet does not evaluate properly .