Skip to content

Commit

Permalink
impl IntoNode for Var
Browse files Browse the repository at this point in the history
  • Loading branch information
mkeeter committed Jun 4, 2024
1 parent fda0744 commit 7e64217
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
# 0.3.2 (unreleased)
- Added `impl IntoNode for Var`, to make handling `Var` values in a context
easier.

# 0.3.1
The highlight of this release is the `fidget::solver` module, which implements
Expand Down
7 changes: 7 additions & 0 deletions fidget/src/core/var/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
//! it is wrapped in a [`Op::Input`](crate::context::Op::Input)) to evaluation
//! (where [`Tape::vars`](crate::eval::Tape::vars) maps from `Var` to index in
//! the argument list).
use crate::context::{Context, IntoNode, Node};
use crate::Error;
use serde::{Deserialize, Serialize};
use std::collections::HashMap;
Expand Down Expand Up @@ -90,6 +91,12 @@ impl std::fmt::Display for Var {
}
}

impl IntoNode for Var {
fn into_node(self, ctx: &mut Context) -> Result<Node, Error> {
Ok(ctx.var(self))
}
}

/// Map from [`Var`] to a particular index
///
/// Variable indexes are automatically assigned the first time
Expand Down

0 comments on commit 7e64217

Please sign in to comment.