File tree Expand file tree Collapse file tree 2 files changed +14
-2
lines changed Expand file tree Collapse file tree 2 files changed +14
-2
lines changed Original file line number Diff line number Diff line change @@ -142,10 +142,15 @@ impl Context {
142
142
/// ```
143
143
///
144
144
/// This function panics if the Python code fails.
145
- pub fn run < F : FnOnce ( & Bound < PyDict > ) > ( & self , code : PythonBlock < F > ) {
145
+ pub fn run (
146
+ & self ,
147
+ #[ cfg( not( doc) ) ] code : PythonBlock < impl FnOnce ( & Bound < PyDict > ) > ,
148
+ #[ cfg( doc) ] code : PythonBlock , // Just show 'PythonBlock' in the docs.
149
+ ) {
146
150
Python :: with_gil ( |py| self . run_with_gil ( py, code) ) ;
147
151
}
148
152
153
+ #[ cfg( not( doc) ) ]
149
154
pub ( crate ) fn run_with_gil < F : FnOnce ( & Bound < PyDict > ) > ( & self , py : Python < ' _ > , block : PythonBlock < F > ) {
150
155
( block. set_variables ) ( self . globals ( ) . bind ( py) ) ;
151
156
if let Err ( err) = run_python_code ( py, self , block. bytecode ) {
Original file line number Diff line number Diff line change @@ -172,6 +172,7 @@ impl<F: FnOnce(&Bound<PyDict>)> FromInlinePython<F> for Context {
172
172
}
173
173
174
174
/// Using a `python!{}` block as a `PythonBlock` object will not do anything yet.
175
+ #[ cfg( not( doc) ) ]
175
176
impl < F : FnOnce ( & Bound < PyDict > ) > FromInlinePython < F > for PythonBlock < F > {
176
177
fn from_python_macro ( bytecode : & ' static [ u8 ] , set_variables : F , panic : fn ( String ) -> !) -> Self {
177
178
Self {
@@ -183,9 +184,15 @@ impl<F: FnOnce(&Bound<PyDict>)> FromInlinePython<F> for PythonBlock<F> {
183
184
}
184
185
185
186
/// Represents a `python!{}` block.
186
- #[ doc ( hidden ) ]
187
+ #[ cfg ( not ( doc ) ) ]
187
188
pub struct PythonBlock < F > {
188
189
bytecode : & ' static [ u8 ] ,
189
190
set_variables : F ,
190
191
panic : fn ( String ) -> !,
191
192
}
193
+
194
+ /// In the documentation, we just show `PythonBlock` in
195
+ /// `Context::run`'s signature, without any generic arguments.
196
+ #[ cfg( doc) ]
197
+ #[ doc( hidden) ]
198
+ pub struct PythonBlock ;
You can’t perform that action at this time.
0 commit comments