Skip to content

Commit 3a7b28c

Browse files
authored
Merge pull request #60 from jinlow/issue-#59
Added declarative init example
2 parents 99ee890 + ced5863 commit 3a7b28c

1 file changed

Lines changed: 26 additions & 0 deletions

File tree

src/lib.rs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,32 @@
4646
//! }
4747
//! ```
4848
//!
49+
//! The following example is how this would be performed with the new declarative inline module syntax
50+
//! introduced in PyO3 0.23 and above.
51+
//!
52+
//! ```rust
53+
//! # mod test_declarative_example {
54+
//! use pyo3::prelude::*;
55+
//! use log::info;
56+
//!
57+
//! #[pymodule]
58+
//! mod my_module{
59+
//! use super::*;
60+
//!
61+
//! #[pymodule_init]
62+
//! fn init(_m: &Bound<'_, PyModule>) -> PyResult<()> {
63+
//! pyo3_log::init();
64+
//! Ok(())
65+
//! }
66+
//!
67+
//! #[pyfunction]
68+
//! fn log_something() {
69+
//! info!("Something!");
70+
//! }
71+
//! }
72+
//! # }
73+
//! ```
74+
//!
4975
//! # Performance, Filtering and Caching
5076
//!
5177
//! Ideally, the logging system would always consult the Python loggers to know which messages

0 commit comments

Comments
 (0)