chore(home-assistant): streamline ObjectId's Python definitions
This commit is contained in:
@@ -1,21 +1,11 @@
|
|||||||
use std::convert::Infallible;
|
use std::convert::Infallible;
|
||||||
|
|
||||||
use pyo3::{prelude::*, types::PyString};
|
use pyo3::{prelude::*, types::PyString};
|
||||||
|
use python_utils::{FromPyFromStr, ToStrToPy};
|
||||||
|
|
||||||
use super::slug::Slug;
|
use super::slug::Slug;
|
||||||
|
|
||||||
pub use super::slug::SlugParsingError as ObjectIdParsingError;
|
pub use super::slug::SlugParsingError as ObjectIdParsingError;
|
||||||
|
|
||||||
#[derive(Debug, Clone, derive_more::Display, derive_more::FromStr)]
|
#[derive(Debug, Clone, derive_more::FromStr, derive_more::Display, FromPyFromStr, ToStrToPy)]
|
||||||
pub struct ObjectId(pub Slug);
|
pub struct ObjectId(pub Slug);
|
||||||
|
|
||||||
impl<'py> IntoPyObject<'py> for ObjectId {
|
|
||||||
type Target = PyString;
|
|
||||||
type Output = Bound<'py, Self::Target>;
|
|
||||||
type Error = Infallible;
|
|
||||||
|
|
||||||
fn into_pyobject(self, py: Python<'py>) -> Result<Self::Output, Self::Error> {
|
|
||||||
let s = self.to_string();
|
|
||||||
s.into_pyobject(py)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|||||||
Reference in New Issue
Block a user