46 lines
931 B
Rust
46 lines
931 B
Rust
use pile_config::Label;
|
|
use smartstring::{LazyCompact, SmartString};
|
|
use std::{collections::HashMap, sync::Arc};
|
|
|
|
use crate::{source::DirDataSource, value::PileValue};
|
|
|
|
//
|
|
// MARK: item
|
|
//
|
|
|
|
/// A cheaply-cloneable pointer to an item in a dataset
|
|
#[derive(Clone)]
|
|
pub enum Item {
|
|
File {
|
|
key: SmartString<LazyCompact>,
|
|
source: Arc<DirDataSource>,
|
|
files: HashMap<Label, PileValue>,
|
|
},
|
|
}
|
|
|
|
impl std::fmt::Debug for Item {
|
|
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
|
match self {
|
|
Self::File { key, files, .. } => f
|
|
.debug_struct("Item::File")
|
|
.field("key", key)
|
|
.field("files", &files.keys().collect::<Vec<_>>())
|
|
.finish(),
|
|
}
|
|
}
|
|
}
|
|
|
|
impl Item {
|
|
pub fn source_name(&self) -> &pile_config::Label {
|
|
match self {
|
|
Self::File { source, .. } => &source.name,
|
|
}
|
|
}
|
|
|
|
pub fn key(&self) -> SmartString<LazyCompact> {
|
|
match self {
|
|
Self::File { key, .. } => key.clone(),
|
|
}
|
|
}
|
|
}
|