From 5559860699301fe9ea1d535d547134985a89f3e9 Mon Sep 17 00:00:00 2001 From: Jeff Date: Sun, 18 Feb 2024 07:14:32 -0500 Subject: [PATCH] Fix doc tests --- src/context/mod.rs | 31 ++++++++++++------------------- src/interpret.rs | 4 ++-- 2 files changed, 14 insertions(+), 21 deletions(-) diff --git a/src/context/mod.rs b/src/context/mod.rs index cd184a0..eb7d29f 100644 --- a/src/context/mod.rs +++ b/src/context/mod.rs @@ -10,7 +10,7 @@ //! //! ``` //! # use dust_lang::*; -//! let context = Context::new(); +//! let context = Context::default(); //! //! context.set_value( //! "foobar".into(), @@ -31,6 +31,14 @@ //! //! ## 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 //! [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 @@ -108,21 +116,6 @@ impl Context { /// /// In the case of the conflict, the inherited value will override the previous /// 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> { let mut self_variables = self.inner.write()?; @@ -153,15 +146,15 @@ impl Context { /// /// ``` /// # use dust_lang::*; - /// let first_context = Context::new(); - /// let second_context = Context::new(); + /// let first_context = Context::default(); + /// let second_context = Context::default(); /// /// second_context.set_value( /// "Foo".into(), /// 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); /// ``` diff --git a/src/interpret.rs b/src/interpret.rs index 0829c61..4ccb338 100644 --- a/src/interpret.rs +++ b/src/interpret.rs @@ -22,7 +22,7 @@ //! //! ```rust //! # use dust_lang::*; -//! let context = Context::new(); +//! let context = Context::default(); //! //! context.set_value("one".into(), 1.into()).unwrap(); //! context.set_value("two".into(), 2.into()).unwrap(); @@ -67,7 +67,7 @@ pub fn interpret_with_context(source: &str, context: Context) -> Result