Skip to content

Commit d3cf7de

Browse files
committed
Just show 'PythonBlock' in doc for Context::run.
1 parent c41784c commit d3cf7de

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

src/context.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,10 +142,15 @@ impl Context {
142142
/// ```
143143
///
144144
/// 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+
) {
146150
Python::with_gil(|py| self.run_with_gil(py, code));
147151
}
148152

153+
#[cfg(not(doc))]
149154
pub(crate) fn run_with_gil<F: FnOnce(&Bound<PyDict>)>(&self, py: Python<'_>, block: PythonBlock<F>) {
150155
(block.set_variables)(self.globals().bind(py));
151156
if let Err(err) = run_python_code(py, self, block.bytecode) {

src/lib.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,7 @@ impl<F: FnOnce(&Bound<PyDict>)> FromInlinePython<F> for Context {
172172
}
173173

174174
/// Using a `python!{}` block as a `PythonBlock` object will not do anything yet.
175+
#[cfg(not(doc))]
175176
impl<F: FnOnce(&Bound<PyDict>)> FromInlinePython<F> for PythonBlock<F> {
176177
fn from_python_macro(bytecode: &'static [u8], set_variables: F, panic: fn(String) -> !) -> Self {
177178
Self {
@@ -183,9 +184,15 @@ impl<F: FnOnce(&Bound<PyDict>)> FromInlinePython<F> for PythonBlock<F> {
183184
}
184185

185186
/// Represents a `python!{}` block.
186-
#[doc(hidden)]
187+
#[cfg(not(doc))]
187188
pub struct PythonBlock<F> {
188189
bytecode: &'static [u8],
189190
set_variables: F,
190191
panic: fn(String) -> !,
191192
}
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;

0 commit comments

Comments
 (0)