alef 0.110.4

Opinionated polyglot binding generator for Rust libraries
Documentation
#[allow(clippy::should_implement_trait)]
impl {{ handle_name }} {
    /// Advance the stream and return the next chunk JSON, or `""` on clean
    /// end-of-stream. Returns `Err(message)` on a stream-level error.
    ///
    /// Declared `async fn` in the bridge module: the Swift caller suspends until a chunk
    /// arrives instead of parking a thread per open stream. The lock is an async mutex
    /// because the guard is held across the `.await`.
    pub async fn next(&self) -> Result<String, String> {
        let mut guard = self.stream.lock().await;
        let stream = match guard.as_mut() {
            Some(s) => s,
            None => return Ok(String::new()),
        };
        use ::futures_util::StreamExt;
        match stream.next().await {
            Some(Ok(item)) => ::serde_json::to_string(&item).map_err(|e| e.to_string()),
            Some(Err(e)) => {
                *guard = None;
                Err(e.to_string())
            }
            None => {
                *guard = None;
                Ok(String::new())
            }
        }
    }
}