Lines
61.76 %
Functions
11.97 %
Branches
10.99 %
use core::fmt;
use std::borrow::Cow;
use std::path::PathBuf;
use crate::domain::commands::arguments::Argument;
use color_eyre::{eyre::Context, Result};
use serde::{Deserialize, Serialize};
use transient::Transient;
use crate::domain::translation_unit::TranslationUnit;
use crate::impl_translation_unit_for;
#[derive(Debug, PartialEq, Eq, Clone, Default, Serialize, Deserialize, Transient)]
pub struct SourceFile<'a> {
pub path: PathBuf,
pub file_stem: Cow<'a, str>,
pub extension: Cow<'a, str>,
}
impl_translation_unit_for!(SourceFile<'a>);
impl<'a> fmt::Display for SourceFile<'a> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(
f,
"({:?}/{:?}.{:?})",
self.path, self.file_stem, self.extension
)
#[derive(Debug, PartialEq, Eq)]
pub enum Source {
File(PathBuf),
Glob(GlobPattern),
impl Source {
#[inline(always)]
pub fn paths(&self) -> Result<Vec<PathBuf>> {
match self {
Source::File(file) => Ok(vec![file.to_path_buf()]),
Source::Glob(pattern) => pattern.resolve(),
pub struct GlobPattern(pub PathBuf);
impl GlobPattern {
fn resolve(&self) -> Result<Vec<PathBuf>> {
glob::glob(self.0.to_str().unwrap_or_default())?
.map(|path| path.with_context(|| ""))
.collect()
#[derive(Debug, PartialEq, Eq, Serialize, Deserialize, Default, Clone)]
pub struct SourceSet<'a>(Vec<SourceFile<'a>>);
impl<'a> SourceSet<'a> {
pub fn new(sources: Vec<SourceFile<'a>>) -> Self {
Self(sources)
pub fn as_slice(&self) -> &[SourceFile<'a>] {
self.0.as_slice()
pub fn as_args_to(&self, dst: &mut Vec<Argument>) -> Result<()> {
let args = self.0.iter().map(|sf| sf.path()).map(Argument::from);
dst.extend(args);
Ok(())