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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
//! This module/file's name is a hack to get the `impl Ruby` defined here to
//! show first in docs. This module shouldn't be exposed publicly.
use ;
use ruby_native_thread_p;
// Ruby does not expose this publicly, but it is used in the fiddle gem via
// this kind of hack, and although the function is marked experimental in
// Ruby's source, that comment and the code have been unchanged singe 1.9.2,
// 14 years ago as of writing.
extern "C"
use crate::;
thread_local!
/// A handle to access Ruby's API.
///
/// Using Ruby's API requires the Ruby VM to be initialised and all access to be
/// from a Ruby-created thread.
///
/// This structure allows safe access to Ruby's API as it should only be
/// possible to acquire an instance in situations where Ruby's API is known to
/// be available.
///
/// Many functions that take Ruby values as arguments are available directly
/// without having to use a `Ruby` handle, as being able to provide a Ruby
/// value is 'proof' the function is being called from a Ruby thread. Because
/// of this most methods defined on `Ruby` deal with creating Ruby objects
/// from Rust data.
///
/// ---
///
/// The methods available on `Ruby` are broken up into sections for easier
/// navigation.
///
/// * [Accessing `Ruby`](#accessing-ruby) - how to get a `Ruby` handle
/// * [Argument Parsing](#argument-parsing) - helpers for argument handling
/// * [Blocks](#blocks) - working with Ruby blocks
/// * [Conversion to `Value`](#conversion-to-value)
/// * [Core Classes](#core-classes) - access built-in classes
/// * [Core Exceptions](#core-exceptions) - access built-in exceptions
/// * [Core Modules](#core-modules) - access built-in modules
/// * [Embedding](#embedding) - functions relevant when embedding Ruby in Rust
/// * [`Encoding`](#encoding) - string encoding
/// * [Encoding Index](#encoding-index) - string encoding
/// * [Errors](#errors)
/// * [Extracting values from `Opaque`/`Lazy`](#extracting-values-from-opaquelazy)
/// * [`false`](#false)
/// * [`Fiber`](#fiber)
/// * [`Fixnum`](#fixnum) - small/fast integers
/// * [`Float`](#float)
/// * [`Flonum`](#flonum) - lower precision/fast floats
/// * [`GC`](#gc) - Garbage Collection
/// * [Globals](#globals) - global variables, etc, plus current VM state such
/// as calling the current `super` method.
/// * [`Id`](#id) - low-level Symbol representation
/// * [`Io`](#io-helper-functions) - IO helper functions
/// * [`Integer`](#integer)
/// * [`Mutex`](#mutex)
/// * [`nil`](#nil)
/// * [`Proc`](#proc) - Ruby's blocks as objects
/// * [`Process`](#process) - external processes
/// * [`Range`](#range)
/// * [`RArray`](#rarray)
/// * [`RbEncoding`](#rbencoding) - string encoding
/// * [`RBignum`](#rbignum) - big integers
/// * [`RFloat`](#rfloat)
/// * [`RHash`](#rhash)
/// * [`RModule`](#rmodule)
/// * [`RRational`](#rrational)
/// * [`RRegexp`](#rregexp)
/// * [`RString`](#rstring)
/// * [`RTypedData`](#rtypeddata) - wrapping Rust data in a Ruby object
/// * [`StaticSymbol`](#staticsymbol) - non GC'd symbols
/// * [`Struct`](#struct)
/// * [`Symbol`](#symbol)
/// * [`Thread`](#thread)
/// * [`Time`](#time)
/// * [`true`](#true)
/// * [`typed_data::Obj`](#typed_dataobj) - wrapping Rust data in a Ruby object
>);
/// # Accessing `Ruby`
///
/// These functions allow you to obtain a `Ruby` handle only when the current
/// thread is a Ruby thread.
///
/// Methods exposed to Ruby via the [`method`](macro@crate::method),
/// [`function`](macro@crate::function) or [`init`](macro@crate::init) macros
/// can also take an optional first argument of `&Ruby` to obtain a `Ruby`
/// handle.