1
0

Fix doc tests

This commit is contained in:
Jeff 2024-02-18 07:14:32 -05:00
parent 3a63d4973d
commit 5559860699
2 changed files with 14 additions and 21 deletions

View File

@ -10,7 +10,7 @@
//! //!
//! ``` //! ```
//! # use dust_lang::*; //! # use dust_lang::*;
//! let context = Context::new(); //! let context = Context::default();
//! //!
//! context.set_value( //! context.set_value(
//! "foobar".into(), //! "foobar".into(),
@ -31,6 +31,14 @@
//! //!
//! ## Garbage Collection //! ## Garbage Collection
//! //!
//! To disable garbage collection, run a Context in AllowGarbage mode.
//!
//! ```
//! # use dust_lang::*;
//! let context = Context::new(ContextMode::AllowGarbage);
//! ```
//!
//!
//! Every item stored in a Context has a counter attached to it. You must use //! Every item stored in a Context has a counter attached to it. You must use
//! [Context::add_allowance][] to let the Context know not to drop the value. //! [Context::add_allowance][] to let the Context know not to drop the value.
//! Every time you use [Context::get_value][] it checks the number of times it //! Every time you use [Context::get_value][] it checks the number of times it
@ -108,21 +116,6 @@ impl Context {
/// ///
/// In the case of the conflict, the inherited value will override the previous /// In the case of the conflict, the inherited value will override the previous
/// value. /// value.
///
/// ```
/// # use dust_lang::*;
/// let first_context = Context::new();
/// let second_context = Context::new();
///
/// second_context.set_value(
/// "Foo".into(),
/// Value::String("Bar".to_string())
/// );
///
/// first_context.inherit_from(&second_context).unwrap();
///
/// assert_eq!(first_context, second_context);
/// ```
pub fn inherit_from(&self, other: &Context) -> Result<(), RwLockError> { pub fn inherit_from(&self, other: &Context) -> Result<(), RwLockError> {
let mut self_variables = self.inner.write()?; let mut self_variables = self.inner.write()?;
@ -153,15 +146,15 @@ impl Context {
/// ///
/// ``` /// ```
/// # use dust_lang::*; /// # use dust_lang::*;
/// let first_context = Context::new(); /// let first_context = Context::default();
/// let second_context = Context::new(); /// let second_context = Context::default();
/// ///
/// second_context.set_value( /// second_context.set_value(
/// "Foo".into(), /// "Foo".into(),
/// Value::String("Bar".to_string()) /// Value::String("Bar".to_string())
/// ); /// );
/// ///
/// first_context.inherit_from(&second_context).unwrap(); /// first_context.inherit_all_from(&second_context).unwrap();
/// ///
/// assert_eq!(first_context, second_context); /// assert_eq!(first_context, second_context);
/// ``` /// ```

View File

@ -22,7 +22,7 @@
//! //!
//! ```rust //! ```rust
//! # use dust_lang::*; //! # use dust_lang::*;
//! let context = Context::new(); //! let context = Context::default();
//! //!
//! context.set_value("one".into(), 1.into()).unwrap(); //! context.set_value("one".into(), 1.into()).unwrap();
//! context.set_value("two".into(), 2.into()).unwrap(); //! context.set_value("two".into(), 2.into()).unwrap();
@ -67,7 +67,7 @@ pub fn interpret_with_context(source: &str, context: Context) -> Result<Value, E
/// ///
/// ``` /// ```
/// # use dust_lang::*; /// # use dust_lang::*;
/// let context = Context::new(); /// let context = Context::default();
/// let mut interpreter = Interpreter::new(context); /// let mut interpreter = Interpreter::new(context);
/// let result = interpreter.run("2 + 2"); /// let result = interpreter.run("2 + 2");
/// ///