#![doc = include_str!("../README.md")]
#![deny(missing_docs)]
#![deny(clippy::missing_docs_in_private_items)]
use std::collections::{HashMap, HashSet};
pub use cargo_metadata::CargoOpt;
use ego_tree::NodeId;
use syn::Item;
mod module;
pub mod parse;
pub mod platforms;
pub use module::Module;
mod module_information;
pub use module_information::ModuleInformation;
mod syn_helpers;
pub type Items = Vec<Item>;
type Features = HashMap<String, HashSet<String>>;
#[derive(Debug)]
struct Import {
pub item: syn::Path,
pub strength: ImportStrength,
pub az: Option<syn::Ident>,
}
impl Import {
pub fn ident(&self) -> &syn::Ident {
match &self.az {
Some(az) => az,
None => &self.item.segments.last().unwrap().ident,
}
}
}
impl Import {
pub fn new(item: syn::Path, strength: ImportStrength, az: Option<syn::Ident>) -> Self {
Self { item, strength, az }
}
}
#[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Clone, Copy)]
enum ImportStrength {
Strong,
Weak,
}
#[derive(Debug, PartialEq, Eq, Clone, Copy)]
pub struct ItemId {
node: NodeId,
item_id: usize,
}
impl ItemId {
pub fn module_id(&self) -> NodeId {
self.node
}
}
#[derive(Debug, PartialEq, Eq, Clone, Copy)]
pub enum ModuleOrItem {
Module(NodeId),
Item(ItemId),
}
impl ModuleOrItem {
pub fn unwrap_module(self) -> NodeId {
match self {
ModuleOrItem::Module(x) => x,
ModuleOrItem::Item(_) => panic!(
"Tried to unwrap a Module from a ModuleOrItem::Item: {:?}",
self
),
}
}
pub fn unwrap_item(self) -> ItemId {
match self {
ModuleOrItem::Item(x) => x,
ModuleOrItem::Module(_) => panic!(
"Tried to unwrap an Item from a ModuleOrItem::Module: {:?}",
self
),
}
}
}
impl From<ItemId> for ModuleOrItem {
fn from(them: ItemId) -> Self {
Self::Item(them)
}
}
impl From<NodeId> for ModuleOrItem {
fn from(them: NodeId) -> Self {
Self::Module(them)
}
}
#[derive(thiserror::Error, Debug)]
pub enum ResolveError {
#[error("path not found")]
NotFound,
#[error("premature non module item")]
PrematureItem,
#[error("items should not exist from the root in rust.")]
RootItem,
#[error("conflicting imports")]
Conflicting,
#[error("too many supers!")]
TooManySupers,
}