1

I'd like to add hidden methods to pyo3 class methods implementation which will be invisible for Python.

Example:

#[pyclass]
pub struct SomeItem;

#[pymethods]
impl SomeItem {
    #[new]
    pub fn new() -> Self {  // visible for python constructor
        SomeItem;
    }

    pub fn method(&self) -> u8 {  // visible for python method
        self.hidden_method()
    }

    #[pyo3(ignore)]  // just for example
    fn hidden_method(&self) -> u8 {  // invisible for python method (that must be able to return non-python type)
        0
    }
}

1 Answers1

1

What about using a separate impl block?

#[pymethods]
impl SomeItem {
    #[new]
    pub fn new() -> Self {  // visible for python constructor
        SomeItem;
    }

    pub fn method(&self) -> u8 {  // visible for python method
        self.hidden_method()
    }
}

impl SomeItem {
    fn hidden_method(&self) -> u8 {
        0
    }
}
Chayim Friedman
  • 47,971
  • 5
  • 48
  • 77