mod compute;
mod format;
pub use compute::*;
pub use format::*;
use serde::{Deserialize, Serialize};
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
pub enum ChangeKind {
Added,
Removed,
SignatureChanged,
BodyChanged,
Moved { from_file: String },
Renamed { old_name: String },
}
impl std::fmt::Display for ChangeKind {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
ChangeKind::Added => write!(f, "ADDED"),
ChangeKind::Removed => write!(f, "REMOVED"),
ChangeKind::SignatureChanged => write!(f, "SIGNATURE_CHANGED"),
ChangeKind::BodyChanged => write!(f, "BODY_CHANGED"),
ChangeKind::Moved { from_file } => write!(f, "MOVED(from:{})", from_file),
ChangeKind::Renamed { old_name } => write!(f, "RENAMED(from:{})", old_name),
}
}
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct SymbolChange {
pub name: String,
pub kind: String,
pub file: String,
pub change: ChangeKind,
pub caller_count: usize,
}
#[derive(Debug, Default)]
pub struct SymbolDiff {
pub old_ref: String,
pub new_ref: String,
pub changes: Vec<SymbolChange>,
}
impl SymbolDiff {
pub fn added(&self) -> impl Iterator<Item = &SymbolChange> {
self.changes
.iter()
.filter(|c| c.change == ChangeKind::Added)
}
pub fn removed(&self) -> impl Iterator<Item = &SymbolChange> {
self.changes
.iter()
.filter(|c| c.change == ChangeKind::Removed)
}
pub fn modified(&self) -> impl Iterator<Item = &SymbolChange> {
self.changes.iter().filter(|c| {
matches!(
c.change,
ChangeKind::BodyChanged
| ChangeKind::SignatureChanged
| ChangeKind::Moved { .. }
| ChangeKind::Renamed { .. }
)
})
}
}
#[derive(Clone)]
pub(crate) struct FlatSym {
pub(crate) file: String,
pub(crate) name: String,
pub(crate) kind: String,
pub(crate) sig_hash: String,
pub(crate) params: String,
pub(crate) return_type: String,
}