Skip to content

Commit 993031f

Browse files
committed
intro: 02-modules
1 parent 156e461 commit 993031f

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

exercises/01_intro/02_modules/Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ version = "0.1.0"
44
edition = "2021"
55

66
[lib]
7+
# Setting "name" here is optional. If not set, by default the value in the [package] section is used.
8+
# name = "modules"
79
crate-type = ["cdylib"]
810

911
[dependencies]

exercises/01_intro/02_modules/src/lib.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,12 @@ fn it_works() -> bool {
66
true
77
}
88

9-
/// A Python module implemented in Rust.
9+
// A Python module implemented in Rust.
10+
// When Python imports a module names `modules`, it's looking for a function called
11+
// PyInit_modules. Rust code here was creating a function named `learn_modules`.
12+
// The module name in Rust code **must** match the library name.
1013
#[pymodule]
11-
fn learn_modules(m: &Bound<'_, PyModule>) -> PyResult<()> {
14+
fn modules(m: &Bound<'_, PyModule>) -> PyResult<()> {
1215
m.add_function(wrap_pyfunction!(it_works, m)?)?;
1316
Ok(())
1417
}

0 commit comments

Comments
 (0)