chore(home-assistant): streamline Python conversion for ServiceDomain and ServiceId
This commit is contained in:
@@ -1,21 +1,8 @@
|
||||
use std::convert::Infallible;
|
||||
|
||||
use pyo3::{prelude::*, types::PyString};
|
||||
use python_utils::{FromPyFromStr, ToStrToPy};
|
||||
|
||||
use super::super::slug::Slug;
|
||||
|
||||
pub use super::super::slug::SlugParsingError as ServiceDomainParsingError;
|
||||
|
||||
#[derive(Debug, Clone, derive_more::Display, derive_more::FromStr)]
|
||||
#[derive(Debug, Clone, derive_more::FromStr, derive_more::Display, FromPyFromStr, ToStrToPy)]
|
||||
pub struct ServiceDomain(pub Slug);
|
||||
|
||||
impl<'py> IntoPyObject<'py> for ServiceDomain {
|
||||
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)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,21 +1,8 @@
|
||||
use std::convert::Infallible;
|
||||
|
||||
use pyo3::{prelude::*, types::PyString};
|
||||
use python_utils::{FromPyFromStr, ToStrToPy};
|
||||
|
||||
use super::super::slug::Slug;
|
||||
|
||||
pub use super::super::slug::SlugParsingError as ServiceIdParsingError;
|
||||
|
||||
#[derive(Debug, Clone, derive_more::Display, derive_more::FromStr)]
|
||||
#[derive(Debug, Clone, derive_more::FromStr, derive_more::Display, FromPyFromStr, ToStrToPy)]
|
||||
pub struct ServiceId(pub Slug);
|
||||
|
||||
impl<'py> IntoPyObject<'py> for ServiceId {
|
||||
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