feat(tvix/composition): allow creating a blank CompositionContext
this is useful when oneshot-instantiating a store from a single config Change-Id: I08538fdee1d0bb26b3ae2da7d3b2339b2e93bc0a Reviewed-on: https://cl.tvl.fyi/c/depot/+/11975 Reviewed-by: flokli <flokli@flokli.de> Autosubmit: yuka <yuka@yuka.dev> Tested-by: BuildkiteCI
This commit is contained in:
parent
1a6b6e3ef3
commit
b8415a94d9
1 changed files with 13 additions and 6 deletions
|
@ -218,10 +218,17 @@ pub fn add_default_services(reg: &mut Registry) {
|
||||||
|
|
||||||
pub struct CompositionContext<'a, T: ?Sized> {
|
pub struct CompositionContext<'a, T: ?Sized> {
|
||||||
stack: Vec<String>,
|
stack: Vec<String>,
|
||||||
composition: &'a Composition<T>,
|
composition: Option<&'a Composition<T>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a, T: ?Sized + Send + Sync + 'static> CompositionContext<'a, T> {
|
impl<'a, T: ?Sized + Send + Sync + 'static> CompositionContext<'a, T> {
|
||||||
|
pub fn blank() -> Self {
|
||||||
|
Self {
|
||||||
|
stack: Default::default(),
|
||||||
|
composition: None,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub async fn resolve(
|
pub async fn resolve(
|
||||||
&self,
|
&self,
|
||||||
entrypoint: String,
|
entrypoint: String,
|
||||||
|
@ -230,10 +237,10 @@ impl<'a, T: ?Sized + Send + Sync + 'static> CompositionContext<'a, T> {
|
||||||
if self.stack.contains(&entrypoint) {
|
if self.stack.contains(&entrypoint) {
|
||||||
return Err(CompositionError::Recursion(self.stack.clone()).into());
|
return Err(CompositionError::Recursion(self.stack.clone()).into());
|
||||||
}
|
}
|
||||||
Ok(self
|
match self.composition {
|
||||||
.composition
|
Some(comp) => Ok(comp.build_internal(self.stack.clone(), entrypoint).await?),
|
||||||
.build_internal(self.stack.clone(), entrypoint)
|
None => Err(CompositionError::NotFound(entrypoint).into()),
|
||||||
.await?)
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -340,7 +347,7 @@ impl<T: ?Sized + Send + Sync + 'static> Composition<T> {
|
||||||
(async move {
|
(async move {
|
||||||
let mut new_context = CompositionContext {
|
let mut new_context = CompositionContext {
|
||||||
stack: stack.clone(),
|
stack: stack.clone(),
|
||||||
composition: self,
|
composition: Some(self),
|
||||||
};
|
};
|
||||||
new_context.stack.push(entrypoint.clone());
|
new_context.stack.push(entrypoint.clone());
|
||||||
let res = config
|
let res = config
|
||||||
|
|
Loading…
Reference in a new issue