From 1d831b4c4e730a7a7a4556e6c71aecc88d73d9ee Mon Sep 17 00:00:00 2001
From: cel 🌸 <cel@bunny.garden>
Date: Wed, 4 Dec 2024 02:36:05 +0000
Subject: add write function and remove todo Sink impl

---
 src/writer.rs | 38 +++++++-------------------------------
 1 file changed, 7 insertions(+), 31 deletions(-)

diff --git a/src/writer.rs b/src/writer.rs
index 25e19fb..5f9f3fd 100644
--- a/src/writer.rs
+++ b/src/writer.rs
@@ -1,4 +1,4 @@
-use std::{collections::HashSet, str::FromStr};
+use std::{collections::HashSet, pin::pin, str::FromStr};
 
 use async_recursion::async_recursion;
 use futures::Sink;
@@ -6,7 +6,7 @@ use tokio::io::{AsyncWrite, AsyncWriteExt};
 
 use crate::{
     declaration::{Declaration, VersionInfo},
-    element::{escape_str, Content, Element, IntoElement, Name, NamespaceDeclaration},
+    element::{escape_str, Content, Element, IntoContent, IntoElement, Name, NamespaceDeclaration},
     error::Error,
     xml::{self, composers::Composer, parsers_complete::Parser, ETag, XMLDecl},
     Result, XMLNS_NS, XML_NS,
@@ -79,6 +79,11 @@ impl<W: AsyncWrite + Unpin + Send> Writer<W> {
         Ok(())
     }
 
+    pub async fn write(&mut self, into_content: &impl IntoContent) -> Result<()> {
+        let content = into_content.into_content();
+        Ok(self.write_content(&content).await?)
+    }
+
     #[async_recursion]
     pub async fn write_element(&mut self, element: &Element) -> Result<()> {
         if element.content.is_empty() {
@@ -357,35 +362,6 @@ impl<W: AsyncWrite + Unpin + Send> Writer<W> {
     }
 }
 
-impl<W: AsyncWrite, E: Into<Element>> Sink<E> for Writer<W> {
-    type Error = Error;
-
-    fn poll_ready(
-        self: std::pin::Pin<&mut Self>,
-        cx: &mut std::task::Context<'_>,
-    ) -> std::task::Poll<Result<()>> {
-        todo!()
-    }
-
-    fn start_send(self: std::pin::Pin<&mut Self>, item: E) -> Result<()> {
-        todo!()
-    }
-
-    fn poll_flush(
-        self: std::pin::Pin<&mut Self>,
-        cx: &mut std::task::Context<'_>,
-    ) -> std::task::Poll<Result<()>> {
-        todo!()
-    }
-
-    fn poll_close(
-        self: std::pin::Pin<&mut Self>,
-        cx: &mut std::task::Context<'_>,
-    ) -> std::task::Poll<Result<()>> {
-        todo!()
-    }
-}
-
 #[cfg(test)]
 mod test {
     use crate::{
-- 
cgit