Skip to content

Commit d5456cc

Browse files
Merge pull request #5 from JakeRoggenbuck/add-database-class
Add Database class in Rust
2 parents a396df3 + 51f6756 commit d5456cc

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

python/lstore/__init__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from typing import Final
2-
from .lstore import hello_from_rust
2+
from .lstore import hello_from_rust, Database
33

4+
print(Database.ping())
45

56
msg = hello_from_rust()
67
assert "Rust" in msg

src/lib.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,20 @@ pub fn get_physical_block_size(drive: &str) -> i16 {
5050
read_block_size(drive, "physical")
5151
}
5252

53+
#[pyclass]
54+
struct Database {
55+
#[pyo3(get, set)]
56+
page_size: usize,
57+
}
58+
59+
#[pymethods]
60+
impl Database {
61+
#[staticmethod]
62+
fn ping() -> String {
63+
return String::from("pong!");
64+
}
65+
}
66+
5367
/// Blazingly fast hello
5468
#[pyfunction]
5569
fn hello_from_rust() -> PyResult<String> {
@@ -59,6 +73,7 @@ fn hello_from_rust() -> PyResult<String> {
5973
/// A Python module implemented in Rust.
6074
#[pymodule]
6175
fn lstore(m: &Bound<'_, PyModule>) -> PyResult<()> {
76+
m.add_class::<Database>()?;
6277
m.add_function(wrap_pyfunction!(hello_from_rust, m)?)?;
6378
Ok(())
6479
}

0 commit comments

Comments
 (0)