1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
|
//! Extra tests!
//!
//! ```compile_fail
//! use std::mem;
//! use hexchat_unsafe_plugin::PluginHandle;
//!
//! fn prepoop_your_pants_pluginhandle(ph: &mut PluginHandle<'_>) {
//! let temporary: String = "Hello, world!".to_string();
//! let hook = ph.hook_timer(0, |_| {
//! println!("{}", temporary);
//! true
//! });
//! }
//! ```
//!
//! ```compile_fail
//! use hexchat_unsafe_plugin::list::Contexts;
//! use hexchat_unsafe_plugin::PluginHandle;
//!
//! fn unsound(ph: &mut PluginHandle<'_>) {
//! ph.ensure_valid_context(|mut ph| {
//! let mut list = ph.list(&Contexts);
//! let context = list.next().unwrap();
//! write!(ph, "{}", context.name().unwrap());
//! std::mem::forget(list);
//! write!(ph, "{}", context.name().unwrap());
//! let ctx = context.context();
//! ph.set_context(&ctx);
//! write!(ph, "{}", context.name().unwrap());
//! })
//! }
//! ```
//!
//! ```compile_fail
//! use hexchat_unsafe_plugin::list::Contexts;
//! use hexchat_unsafe_plugin::PluginHandle;
//!
//! fn unsound(ph: &mut PluginHandle<'_>) {
//! ph.ensure_valid_context(|mut ph| {
//! let mut list = ph.list(&Contexts);
//! let context = list.next().unwrap();
//! std::mem::forget(list);
//! let ctx = context.context();
//! ph.set_context(&ctx);
//! })
//! }
//! ```
//!
//! ```no_run
//! use hexchat_unsafe_plugin::list::Contexts;
//! use hexchat_unsafe_plugin::PluginHandle;
//!
//! fn fine(ph: &mut PluginHandle<'_>) {
//! ph.ensure_valid_context(|mut ph| {
//! let mut list = ph.list(&Contexts);
//! let context = list.next().unwrap();
//! write!(ph, "{}", context.name().unwrap());
//! let ctx = context.context();
//! let name = context.name().unwrap();
//! drop(list);
//! ph.set_context(&ctx);
//! write!(ph, "{}", name);
//! })
//! }
//! ```
|