Skip to main content

google_cloud_bigquery/write/arrow/
writer.rs

1// Copyright 2026 Google LLC
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7//     https://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15use super::{BufferedWriter, CommittedWriter, PendingWriter};
16use crate::model::ArrowSchema;
17use crate::model::write_stream::Type;
18use crate::write::transport::Transport;
19use std::sync::Arc;
20
21pub(crate) mod sealed {
22    use super::*;
23
24    pub trait Writer {
25        const STREAM_TYPE: Type;
26        fn build(inner: Arc<Transport>, write_stream: String, schema: ArrowSchema) -> Self;
27    }
28
29    impl Writer for PendingWriter {
30        const STREAM_TYPE: Type = Type::Pending;
31
32        fn build(inner: Arc<Transport>, write_stream: String, schema: ArrowSchema) -> Self {
33            Self::new(inner, write_stream, schema)
34        }
35    }
36
37    impl Writer for CommittedWriter {
38        const STREAM_TYPE: Type = Type::Committed;
39
40        fn build(inner: Arc<Transport>, write_stream: String, schema: ArrowSchema) -> Self {
41            Self::new(inner, write_stream, schema)
42        }
43    }
44
45    impl Writer for BufferedWriter {
46        const STREAM_TYPE: Type = Type::Buffered;
47
48        fn build(inner: Arc<Transport>, write_stream: String, schema: ArrowSchema) -> Self {
49            Self::new(inner, write_stream, schema)
50        }
51    }
52}
53
54/// A trait for strongly-typed stream writers that can be attached to an existing stream.
55///
56/// This trait is sealed and cannot be implemented for types outside of this crate.
57pub trait Writer: sealed::Writer + Sized {}
58
59impl<T: sealed::Writer + Sized> Writer for T {}