Add comments to code in docs
This commit is contained in:
parent
88559d5493
commit
3670bcaf63
@ -219,12 +219,16 @@ Here is a simple example to show the difference between preserving context betwe
|
|||||||
use evalexpr::*;
|
use evalexpr::*;
|
||||||
|
|
||||||
assert_eq!(eval("a = 5;"), Ok(Value::from(())));
|
assert_eq!(eval("a = 5;"), Ok(Value::from(())));
|
||||||
|
// The context is not preserved between eval calls
|
||||||
assert_eq!(eval("a"), Err(EvalexprError::VariableIdentifierNotFound("a".to_string())));
|
assert_eq!(eval("a"), Err(EvalexprError::VariableIdentifierNotFound("a".to_string())));
|
||||||
|
|
||||||
let mut context = HashMapContext::new();
|
let mut context = HashMapContext::new();
|
||||||
assert_eq!(eval_with_context_mut("a = 5;", &mut context), Ok(Value::from(())));
|
assert_eq!(eval_with_context_mut("a = 5;", &mut context), Ok(Value::from(())));
|
||||||
|
// Assignments require mutable contexts
|
||||||
assert_eq!(eval_with_context("a = 6", &context), Err(EvalexprError::ContextNotManipulable));
|
assert_eq!(eval_with_context("a = 6", &context), Err(EvalexprError::ContextNotManipulable));
|
||||||
|
// The HashMapContext is type safe
|
||||||
assert_eq!(eval_with_context_mut("a = 5.5", &mut context), Err(EvalexprError::ExpectedInt { actual: Value::from(5.5) }));
|
assert_eq!(eval_with_context_mut("a = 5.5", &mut context), Err(EvalexprError::ExpectedInt { actual: Value::from(5.5) }));
|
||||||
|
// Reading a variable does not require a mutable context
|
||||||
assert_eq!(eval_with_context("a", &context), Ok(Value::from(5)));
|
assert_eq!(eval_with_context("a", &context), Ok(Value::from(5)));
|
||||||
|
|
||||||
```
|
```
|
||||||
|
@ -206,12 +206,16 @@
|
|||||||
//! use evalexpr::*;
|
//! use evalexpr::*;
|
||||||
//!
|
//!
|
||||||
//! assert_eq!(eval("a = 5;"), Ok(Value::from(())));
|
//! assert_eq!(eval("a = 5;"), Ok(Value::from(())));
|
||||||
|
//! // The context is not preserved between eval calls
|
||||||
//! assert_eq!(eval("a"), Err(EvalexprError::VariableIdentifierNotFound("a".to_string())));
|
//! assert_eq!(eval("a"), Err(EvalexprError::VariableIdentifierNotFound("a".to_string())));
|
||||||
//!
|
//!
|
||||||
//! let mut context = HashMapContext::new();
|
//! let mut context = HashMapContext::new();
|
||||||
//! assert_eq!(eval_with_context_mut("a = 5;", &mut context), Ok(Value::from(())));
|
//! assert_eq!(eval_with_context_mut("a = 5;", &mut context), Ok(Value::from(())));
|
||||||
|
//! // Assignments require mutable contexts
|
||||||
//! assert_eq!(eval_with_context("a = 6", &context), Err(EvalexprError::ContextNotManipulable));
|
//! assert_eq!(eval_with_context("a = 6", &context), Err(EvalexprError::ContextNotManipulable));
|
||||||
|
//! // The HashMapContext is type safe
|
||||||
//! assert_eq!(eval_with_context_mut("a = 5.5", &mut context), Err(EvalexprError::ExpectedInt { actual: Value::from(5.5) }));
|
//! assert_eq!(eval_with_context_mut("a = 5.5", &mut context), Err(EvalexprError::ExpectedInt { actual: Value::from(5.5) }));
|
||||||
|
//! // Reading a variable does not require a mutable context
|
||||||
//! assert_eq!(eval_with_context("a", &context), Ok(Value::from(5)));
|
//! assert_eq!(eval_with_context("a", &context), Ok(Value::from(5)));
|
||||||
//!
|
//!
|
||||||
//! ```
|
//! ```
|
||||||
|
Loading…
Reference in New Issue
Block a user