Skip to content

Commit ae8003e

Browse files
committed
Adds a try_clone method for kube_client::client::Body when it's Kind::Once.
Signed-off-by: meowjesty <[email protected]>
1 parent f84d8c0 commit ae8003e

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

kube-client/src/client/body.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,18 @@ impl Body {
5353
pub async fn collect_bytes(self) -> Result<Bytes, crate::Error> {
5454
Ok(self.collect().await?.to_bytes())
5555
}
56+
57+
/// Tries to clone a [`Body`].
58+
///
59+
/// Returns the cloned `Body` when it's [`Kind::Once`].
60+
pub fn try_clone(&self) -> Option<Self> {
61+
match &self.kind {
62+
Kind::Once(bytes) => Some(Self {
63+
kind: Kind::Once(bytes.clone()),
64+
}),
65+
Kind::Wrap(..) => None,
66+
}
67+
}
5668
}
5769

5870
impl From<Bytes> for Body {

0 commit comments

Comments
 (0)