You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

47 lines
1.2 KiB

  1. use lazy_static::lazy_static;
  2. use pyo3::prelude::*;
  3. use pyo3_log::ResetHandle;
  4. pub mod acl;
  5. pub mod push;
  6. lazy_static! {
  7. static ref LOGGING_HANDLE: ResetHandle = pyo3_log::init();
  8. }
  9. /// Returns the hash of all the rust source files at the time it was compiled.
  10. ///
  11. /// Used by python to detect if the rust library is outdated.
  12. #[pyfunction]
  13. fn get_rust_file_digest() -> &'static str {
  14. env!("SYNAPSE_RUST_DIGEST")
  15. }
  16. /// Formats the sum of two numbers as string.
  17. #[pyfunction]
  18. #[pyo3(text_signature = "(a, b, /)")]
  19. fn sum_as_string(a: usize, b: usize) -> PyResult<String> {
  20. Ok((a + b).to_string())
  21. }
  22. /// Reset the cached logging configuration of pyo3-log to pick up any changes
  23. /// in the Python logging configuration.
  24. ///
  25. #[pyfunction]
  26. fn reset_logging_config() {
  27. LOGGING_HANDLE.reset();
  28. }
  29. /// The entry point for defining the Python module.
  30. #[pymodule]
  31. fn synapse_rust(py: Python<'_>, m: &PyModule) -> PyResult<()> {
  32. m.add_function(wrap_pyfunction!(sum_as_string, m)?)?;
  33. m.add_function(wrap_pyfunction!(get_rust_file_digest, m)?)?;
  34. m.add_function(wrap_pyfunction!(reset_logging_config, m)?)?;
  35. acl::register_module(py, m)?;
  36. push::register_module(py, m)?;
  37. Ok(())
  38. }