Mercurial > public > mercurial-scm > hg
annotate rust/hg-pyo3/src/lib.rs @ 52409:a642c0a3860f
rust-pyo3: conversion helpers for Revision objects
Although the PyO3 API is indeed nicer and has derive macros, we still need
the collection helpers. The `Result` issue is not very relevant any more,
however the checking of incoming revisions for Python definitely is.
author | Georges Racinet <georges.racinet@cloudcrane.io> |
---|---|
date | Sat, 30 Nov 2024 20:30:18 +0100 |
parents | 20c0472b2ab7 |
children | c2480ac4c5e2 |
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; |
52409
a642c0a3860f
rust-pyo3: conversion helpers for Revision objects
Georges Racinet <georges.racinet@cloudcrane.io>
parents:
52408
diff
changeset
|
5 mod revision; |
52407
c5128c541021
rust-pyo3: facility for submodule registration, using it for dagop
Georges Racinet <georges.racinet@cloudcrane.io>
parents:
52403
diff
changeset
|
6 mod util; |
c5128c541021
rust-pyo3: facility for submodule registration, using it for dagop
Georges Racinet <georges.racinet@cloudcrane.io>
parents:
52403
diff
changeset
|
7 |
52402
6673cec8605c
rust: add PyO3 based Rust extension module
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
8 #[pymodule] |
52407
c5128c541021
rust-pyo3: facility for submodule registration, using it for dagop
Georges Racinet <georges.racinet@cloudcrane.io>
parents:
52403
diff
changeset
|
9 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
|
10 m.add( |
c5128c541021
rust-pyo3: facility for submodule registration, using it for dagop
Georges Racinet <georges.racinet@cloudcrane.io>
parents:
52403
diff
changeset
|
11 "__doc__", |
c5128c541021
rust-pyo3: facility for submodule registration, using it for dagop
Georges Racinet <georges.racinet@cloudcrane.io>
parents:
52403
diff
changeset
|
12 "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
|
13 )?; |
c5128c541021
rust-pyo3: facility for submodule registration, using it for dagop
Georges Racinet <georges.racinet@cloudcrane.io>
parents:
52403
diff
changeset
|
14 // 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
|
15 // (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
|
16 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
|
17 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
|
18 |
c5128c541021
rust-pyo3: facility for submodule registration, using it for dagop
Georges Racinet <georges.racinet@cloudcrane.io>
parents:
52403
diff
changeset
|
19 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
|
20 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
|
21 Ok(()) |
6673cec8605c
rust: add PyO3 based Rust extension module
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
22 } |