Skip to content

Commit 3c005d7

Browse files
author
Your Name
committed
rename set_yield_args to yield_with
1 parent 3a079fe commit 3c005d7

File tree

3 files changed

+24
-3
lines changed

3 files changed

+24
-3
lines changed

src/error.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ pub enum Error {
206206
/// Underlying error.
207207
cause: Arc<Error>,
208208
},
209-
/// A special error variant that tells Rust to yield to Lua with the specified args
209+
/// A special error variant that tells Rust to yield to Lua with the specified arguments
210210
Yield(MultiValue),
211211
}
212212

src/state.rs

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2146,10 +2146,29 @@ impl Lua {
21462146
&*self.raw.data_ptr()
21472147
}
21482148

2149-
/// Helper method to set the yield arguments, returning a Error::Yield.
2149+
/// Helper method to set the yield arguments, returning a ``Error::Yield``.
2150+
///
2151+
/// Internally, this method is equivalent to ``Err(Error::Yield(args.into_lua_multi(self)?))``
21502152
///
21512153
/// This method is mostly useful with continuations and Rust-Rust yields
21522154
/// due to the Rust/Lua boundary
2155+
///
2156+
/// Example:
2157+
///
2158+
/// ```rust
2159+
/// fn test() -> mlua::Result<()> {
2160+
/// let lua = mlua::Lua::new();
2161+
/// let always_yield = lua.create_function(|lua, ()| lua.yield_with((42, "69420".to_string(), 45.6)))?;
2162+
///
2163+
/// let thread = lua.create_thread(always_yield)?;
2164+
/// assert_eq!(
2165+
/// thread.resume::<(i32, String, f32)>(())?,
2166+
/// (42, String::from("69420"), 45.6)
2167+
/// );
2168+
///
2169+
/// Ok(())
2170+
/// }
2171+
/// ```
21532172
pub fn yield_with(&self, args: impl IntoLuaMulti) -> Result<()> {
21542173
Err(Error::Yield(args.into_lua_multi(self)?))
21552174
}

src/state/raw.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,9 @@ use crate::chunk::ChunkMode;
1212
use crate::error::{Error, Result};
1313
use crate::function::Function;
1414
use crate::memory::{MemoryState, ALLOCATOR};
15-
use crate::state::util::{callback_error_ext, callback_error_ext_yieldable, ref_stack_pop};
15+
#[allow(unused_imports)]
16+
use crate::state::util::callback_error_ext;
17+
use crate::state::util::{callback_error_ext_yieldable, ref_stack_pop};
1618
use crate::stdlib::StdLib;
1719
use crate::string::String;
1820
use crate::table::Table;

0 commit comments

Comments
 (0)