Skip to main content

bee/
dev.rs

1//! Bee dev-mode wrapper. The dev-mode endpoint surface is a strict
2//! subset of production Bee, so this is mostly a documentation /
3//! discovery signal: callers can `let bee = DevClient::new(url)?;`
4//! and use the same accessors they already know from [`Client`].
5//!
6//! Mirrors bee-js `BeeDev`. The endpoints currently exposed
7//! (`addresses`, `topology`) accept a slimmer payload in dev mode but
8//! the same accessors work; bee-rs avoids splitting the type system
9//! here and reuses the regular debug handles.
10
11use crate::Client;
12use crate::swarm::Error;
13
14/// Thin newtype around [`Client`] for use against Bee in dev mode.
15/// Cheap to clone.
16#[derive(Clone, Debug)]
17pub struct DevClient {
18    inner: Client,
19}
20
21impl DevClient {
22    /// Construct a dev-mode client from a base URL. Same shape as
23    /// [`Client::new`].
24    pub fn new(url: &str) -> Result<Self, Error> {
25        Ok(Self {
26            inner: Client::new(url)?,
27        })
28    }
29
30    /// Construct a dev-mode client with a caller-provided HTTP client.
31    pub fn with_http_client(url: &str, http: reqwest::Client) -> Result<Self, Error> {
32        Ok(Self {
33            inner: Client::with_http_client(url, http)?,
34        })
35    }
36
37    /// Borrow the wrapped [`Client`] for full API access.
38    pub fn client(&self) -> &Client {
39        &self.inner
40    }
41
42    /// Convert into the wrapped [`Client`].
43    pub fn into_client(self) -> Client {
44        self.inner
45    }
46}
47
48impl std::ops::Deref for DevClient {
49    type Target = Client;
50
51    fn deref(&self) -> &Self::Target {
52        &self.inner
53    }
54}