couchbase_core/results/
query.rs

1/*
2 *
3 *  * Copyright (c) 2025 Couchbase, Inc.
4 *  *
5 *  * Licensed under the Apache License, Version 2.0 (the "License");
6 *  * you may not use this file except in compliance with the License.
7 *  * You may obtain a copy of the License at
8 *  *
9 *  *    http://www.apache.org/licenses/LICENSE-2.0
10 *  *
11 *  * Unless required by applicable law or agreed to in writing, software
12 *  * distributed under the License is distributed on an "AS IS" BASIS,
13 *  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 *  * See the License for the specific language governing permissions and
15 *  * limitations under the License.
16 *
17 */
18
19use crate::error;
20use crate::queryx::query_respreader::QueryRespReader;
21use crate::queryx::query_result::{EarlyMetaData, MetaData};
22use bytes::Bytes;
23use futures::StreamExt;
24use futures_core::Stream;
25
26pub struct QueryResultStream {
27    pub(crate) inner: QueryRespReader,
28    pub(crate) endpoint: String,
29}
30
31impl QueryResultStream {
32    pub fn endpoint(&self) -> &str {
33        &self.endpoint
34    }
35
36    pub fn early_metadata(&self) -> &EarlyMetaData {
37        self.inner.early_metadata()
38    }
39
40    pub fn metadata(&self) -> error::Result<&MetaData> {
41        self.inner.metadata().map_err(|e| e.into())
42    }
43}
44
45impl Stream for QueryResultStream {
46    type Item = error::Result<Bytes>;
47
48    fn poll_next(
49        mut self: std::pin::Pin<&mut Self>,
50        cx: &mut std::task::Context<'_>,
51    ) -> std::task::Poll<Option<Self::Item>> {
52        self.inner.poll_next_unpin(cx).map_err(|e| e.into())
53    }
54}