use super::BinObject;
use crate::Bin;
#[derive(Debug, Default, Clone)]
pub struct Builder {
objects: Vec<BinObject>,
dependencies: Vec<String>,
}
impl Builder {
pub fn new() -> Self {
Self::default()
}
pub fn dependency(mut self, dep: impl Into<String>) -> Self {
self.dependencies.push(dep.into());
self
}
pub fn dependencies(mut self, deps: impl IntoIterator<Item = impl Into<String>>) -> Self {
self.dependencies.extend(deps.into_iter().map(Into::into));
self
}
pub fn object(mut self, obj: BinObject) -> Self {
self.objects.push(obj);
self
}
pub fn objects(mut self, objs: impl IntoIterator<Item = BinObject>) -> Self {
self.objects.extend(objs);
self
}
pub fn build(self) -> Bin {
Bin {
version: 3,
objects: self.objects.into_iter().map(|o| (o.path_hash, o)).collect(),
dependencies: self.dependencies,
}
}
}