#[derive(Debug, Clone, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct RawRdNode {
tag: Option<String>,
option: Option<Vec<crate::RdNode>>,
children: Vec<crate::RdNode>,
payload: Option<Box<RawRdValue>>,
attributes: Vec<RdAttribute>,
}
impl RawRdNode {
pub fn tag(&self) -> Option<&str> {
self.tag.as_deref()
}
pub fn option(&self) -> Option<&[crate::RdNode]> {
self.option.as_deref()
}
pub fn children(&self) -> &[crate::RdNode] {
&self.children
}
pub fn payload(&self) -> Option<&RawRdValue> {
self.payload.as_deref()
}
pub fn attributes(&self) -> &[RdAttribute] {
&self.attributes
}
#[allow(clippy::type_complexity)]
pub fn into_parts(
self,
) -> (
Option<String>,
Option<Vec<crate::RdNode>>,
Vec<crate::RdNode>,
Option<RawRdValue>,
Vec<RdAttribute>,
) {
(
self.tag,
self.option,
self.children,
self.payload.map(|payload| *payload),
self.attributes,
)
}
}
#[derive(Debug, Clone, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct RdAttribute {
name: String,
value: RawRdObject,
}
impl RdAttribute {
pub fn name(&self) -> &str {
&self.name
}
pub fn value(&self) -> &RawRdObject {
&self.value
}
pub fn into_parts(self) -> (String, RawRdObject) {
(self.name, self.value)
}
}
#[derive(Debug, Clone, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct RawRdObject {
value: RawRdValue,
attributes: Vec<RdAttribute>,
}
impl RawRdObject {
pub fn value(&self) -> &RawRdValue {
&self.value
}
pub fn attributes(&self) -> &[RdAttribute] {
&self.attributes
}
pub fn into_parts(self) -> (RawRdValue, Vec<RdAttribute>) {
(self.value, self.attributes)
}
}
pub mod producer {
use super::{RawRdNode, RawRdObject, RawRdValue, RdAttribute};
use crate::RdNode;
pub fn raw_node(
tag: Option<String>,
option: Option<Vec<RdNode>>,
children: Vec<RdNode>,
payload: Option<RawRdValue>,
attributes: Vec<RdAttribute>,
) -> RawRdNode {
RawRdNode {
tag,
option,
children,
payload: payload.map(Box::new),
attributes,
}
}
pub fn raw_attribute(name: String, value: RawRdObject) -> RdAttribute {
RdAttribute { name, value }
}
pub fn raw_object(value: RawRdValue, attributes: Vec<RdAttribute>) -> RawRdObject {
RawRdObject { value, attributes }
}
}
#[derive(Debug, Clone, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[non_exhaustive]
pub enum RawRdValue {
Null,
Integer(Vec<Option<i32>>),
Logical(Vec<Option<bool>>),
Real(Vec<RawRdReal>),
Character(Vec<Option<String>>),
List(Vec<RawRdObject>),
Symbol(String),
Persisted(Vec<Option<String>>),
Environment(RawRdEnvironment),
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[non_exhaustive]
pub enum RawRdEnvironment {
Global,
Base,
Empty,
Other,
}
#[derive(Debug, Clone, Copy, PartialEq)]
#[cfg_attr(
feature = "serde",
derive(serde::Serialize, serde::Deserialize),
serde(tag = "kind", content = "value", rename_all = "snake_case")
)]
pub enum RawRdReal {
Na,
Finite(f64),
Nan,
PositiveInfinity,
NegativeInfinity,
}