diff --git a/crates/djls-template-ast/src/ast.rs b/crates/djls-template-ast/src/ast.rs index bbb6cbc..95a51fb 100644 --- a/crates/djls-template-ast/src/ast.rs +++ b/crates/djls-template-ast/src/ast.rs @@ -109,11 +109,12 @@ impl From for Span { #[derive(Clone, Debug, Serialize)] pub enum Node { - Text { + Block(Block), + Comment { content: String, span: Span, }, - Comment { + Text { content: String, span: Span, }, @@ -122,16 +123,15 @@ pub enum Node { filters: Vec, span: Span, }, - Block(Block), } impl Node { pub fn span(&self) -> Option<&Span> { match self { - Node::Text { span, .. } => Some(span), - Node::Comment { span, .. } => Some(span), - Node::Variable { span, .. } => Some(span), Node::Block(block) => Some(&block.tag().span), + Node::Comment { span, .. } => Some(span), + Node::Text { span, .. } => Some(span), + Node::Variable { span, .. } => Some(span), } } @@ -169,18 +169,18 @@ pub enum Block { impl Block { pub fn tag(&self) -> &Tag { match self { - Self::Container { tag, .. } - | Self::Branch { tag, .. } - | Self::Single { tag } + Self::Branch { tag, .. } + | Self::Container { tag, .. } + | Self::Closing { tag } | Self::Inclusion { tag, .. } - | Self::Closing { tag } => tag, + | Self::Single { tag } => tag, } } pub fn nodes(&self) -> Option<&Vec> { match self { - Block::Container { nodes, .. } => Some(nodes), Block::Branch { nodes, .. } => Some(nodes), + Block::Container { nodes, .. } => Some(nodes), _ => None, } } diff --git a/crates/djls-worker/src/lib.rs b/crates/djls-worker/src/lib.rs index 7fca536..f4d10d3 100644 --- a/crates/djls-worker/src/lib.rs +++ b/crates/djls-worker/src/lib.rs @@ -68,6 +68,10 @@ impl Worker { } } + /// Attempts to execute a task immediately without waiting. + /// Returns an error if the worker's channel is full. + /// + /// Best for non-critical tasks where backpressure is desired. pub fn execute(&self, task: T) -> Result<()> where T: Task + 'static, @@ -78,6 +82,10 @@ impl Worker { .map_err(|e| anyhow::anyhow!("Failed to execute task: {}", e)) } + /// Submits a task asynchronously, waiting if the channel is full. + /// + /// Good for tasks that must be processed but where you don't need + /// the result immediately. pub async fn submit(&self, task: T) -> Result<()> where T: Task + 'static, @@ -89,6 +97,10 @@ impl Worker { .map_err(|e| anyhow::anyhow!("Failed to submit task: {}", e)) } + /// Submits a task and waits for its result. + /// + /// Best when you need the output of the task. This method will + /// wait both for space to submit the task and for its completion. pub async fn wait_for(&self, task: T) -> Result where T: Task + 'static,