1use std::{fmt, io, result};
16
17use create::Create;
18use delete::Delete;
19use std::{marker::PhantomData, sync::Arc};
20use tansu_sans_io::ErrorCode;
21use url::Url;
22
23mod create;
24mod delete;
25
26pub type Result<T, E = Error> = result::Result<T, E>;
27
28#[derive(thiserror::Error, Debug)]
29pub enum Error {
30 Api(ErrorCode),
31 Io(Arc<io::Error>),
32 Protocol(#[from] tansu_sans_io::Error),
33}
34
35impl From<io::Error> for Error {
36 fn from(value: io::Error) -> Self {
37 Self::Io(Arc::new(value))
38 }
39}
40
41impl fmt::Display for Error {
42 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
43 write!(f, "{self:?}")
44 }
45}
46
47#[derive(Clone, Debug, Eq, PartialEq)]
48pub enum Topic {
49 Create(create::Configuration),
50 Delete(delete::Configuration),
51}
52
53impl Topic {
54 pub fn create() -> create::Builder<PhantomData<Url>, PhantomData<String>, PhantomData<i32>> {
55 create::Builder::default()
56 }
57
58 pub fn delete() -> delete::Builder<PhantomData<Url>, PhantomData<String>> {
59 delete::Builder::default()
60 }
61
62 pub async fn main(self) -> Result<ErrorCode> {
63 match self {
64 Self::Create(configuration) => Create::try_from(configuration)?.main().await,
65 Self::Delete(configuration) => Delete::try_from(configuration)?.main().await,
66 }
67 }
68}