office_convert_client/
lib.rs

1pub mod client;
2pub mod load;
3
4use std::sync::Arc;
5
6use bytes::Bytes;
7pub use client::{ClientOptions, CreateError, OfficeConvertClient, RequestError};
8pub use load::{LoadBalanceError, OfficeConvertLoadBalancer};
9
10/// Office converter
11#[derive(Clone)]
12pub enum OfficeConverter {
13    /// Recommended: Load balanced client that can handle blocking of the server
14    LoadBalanced(Arc<OfficeConvertLoadBalancer>),
15    /// Office client without any additional logic for handling a server
16    /// being unavailable.
17    Client(OfficeConvertClient),
18}
19
20impl OfficeConverter {
21    /// Create a new converter from a client
22    pub fn from_client(client: OfficeConvertClient) -> Self {
23        Self::Client(client)
24    }
25
26    /// Create a new converter from a load balancer
27    pub fn from_load_balancer(client: OfficeConvertLoadBalancer) -> Self {
28        Self::LoadBalanced(Arc::new(client))
29    }
30
31    /// Converts the provided office file format bytes into a
32    /// PDF returning the PDF file bytes
33    ///
34    /// ## Arguments
35    /// * `file` - The file bytes to convert
36    pub async fn convert(&self, file: Bytes) -> Result<Bytes, RequestError> {
37        match self {
38            OfficeConverter::LoadBalanced(inner) => inner.convert(file).await,
39            OfficeConverter::Client(inner) => inner.convert(file).await,
40        }
41    }
42}