annotate rust/hg-pyo3/src/lib.rs @ 52408:20c0472b2ab7

rust-pyo3: defining GraphError This pretty much parallels the way in works with `cpython`. A warning, though: this new `pyo3_rustext.GraphError` is not the same as `rustext.GraphError`, yet both subclass `ValueError`.
author Georges Racinet <georges.racinet@cloudcrane.io>
date Sat, 30 Nov 2024 20:27:11 +0100
parents c5128c541021
children a642c0a3860f
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
52402
6673cec8605c rust: add PyO3 based Rust extension module
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff changeset
1 use pyo3::prelude::*;
6673cec8605c rust: add PyO3 based Rust extension module
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff changeset
2
52407
c5128c541021 rust-pyo3: facility for submodule registration, using it for dagop
Georges Racinet <georges.racinet@cloudcrane.io>
parents: 52403
diff changeset
3 mod dagops;
52408
20c0472b2ab7 rust-pyo3: defining GraphError
Georges Racinet <georges.racinet@cloudcrane.io>
parents: 52407
diff changeset
4 mod exceptions;
52407
c5128c541021 rust-pyo3: facility for submodule registration, using it for dagop
Georges Racinet <georges.racinet@cloudcrane.io>
parents: 52403
diff changeset
5 mod util;
c5128c541021 rust-pyo3: facility for submodule registration, using it for dagop
Georges Racinet <georges.racinet@cloudcrane.io>
parents: 52403
diff changeset
6
52402
6673cec8605c rust: add PyO3 based Rust extension module
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff changeset
7 #[pymodule]
52407
c5128c541021 rust-pyo3: facility for submodule registration, using it for dagop
Georges Racinet <georges.racinet@cloudcrane.io>
parents: 52403
diff changeset
8 fn pyo3_rustext(py: Python<'_>, m: &Bound<'_, PyModule>) -> PyResult<()> {
c5128c541021 rust-pyo3: facility for submodule registration, using it for dagop
Georges Racinet <georges.racinet@cloudcrane.io>
parents: 52403
diff changeset
9 m.add(
c5128c541021 rust-pyo3: facility for submodule registration, using it for dagop
Georges Racinet <georges.racinet@cloudcrane.io>
parents: 52403
diff changeset
10 "__doc__",
c5128c541021 rust-pyo3: facility for submodule registration, using it for dagop
Georges Racinet <georges.racinet@cloudcrane.io>
parents: 52403
diff changeset
11 "Mercurial core concepts - Rust implementation exposed via PyO3",
c5128c541021 rust-pyo3: facility for submodule registration, using it for dagop
Georges Racinet <georges.racinet@cloudcrane.io>
parents: 52403
diff changeset
12 )?;
c5128c541021 rust-pyo3: facility for submodule registration, using it for dagop
Georges Racinet <georges.racinet@cloudcrane.io>
parents: 52403
diff changeset
13 // the module's __name__ is pyo3_rustext, not mercurial.pyo3_rustext
c5128c541021 rust-pyo3: facility for submodule registration, using it for dagop
Georges Racinet <georges.racinet@cloudcrane.io>
parents: 52403
diff changeset
14 // (at least at this point).
c5128c541021 rust-pyo3: facility for submodule registration, using it for dagop
Georges Racinet <georges.racinet@cloudcrane.io>
parents: 52403
diff changeset
15 let name: String = m.getattr("__name__")?.extract()?;
c5128c541021 rust-pyo3: facility for submodule registration, using it for dagop
Georges Racinet <georges.racinet@cloudcrane.io>
parents: 52403
diff changeset
16 let dotted_name = format!("mercurial.{}", name);
c5128c541021 rust-pyo3: facility for submodule registration, using it for dagop
Georges Racinet <georges.racinet@cloudcrane.io>
parents: 52403
diff changeset
17
c5128c541021 rust-pyo3: facility for submodule registration, using it for dagop
Georges Racinet <georges.racinet@cloudcrane.io>
parents: 52403
diff changeset
18 m.add_submodule(&dagops::init_module(py, &dotted_name)?)?;
52408
20c0472b2ab7 rust-pyo3: defining GraphError
Georges Racinet <georges.racinet@cloudcrane.io>
parents: 52407
diff changeset
19 m.add("GraphError", py.get_type::<exceptions::GraphError>())?;
52402
6673cec8605c rust: add PyO3 based Rust extension module
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff changeset
20 Ok(())
6673cec8605c rust: add PyO3 based Rust extension module
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff changeset
21 }