async_zip/file/
builder.rs

1// Copyright (c) 2022 Harry [Majored] [hello@majored.pw]
2// MIT License (https://github.com/Majored/rs-async-zip/blob/main/LICENSE)
3
4use crate::{file::ZipFile, string::ZipString};
5
6/// A builder for [`ZipFile`].
7pub struct ZipFileBuilder(pub(crate) ZipFile);
8
9impl From<ZipFile> for ZipFileBuilder {
10    fn from(file: ZipFile) -> Self {
11        Self(file)
12    }
13}
14
15impl Default for ZipFileBuilder {
16    fn default() -> Self {
17        ZipFileBuilder(ZipFile { entries: Vec::new(), zip64: false, comment: String::new().into() })
18    }
19}
20
21impl ZipFileBuilder {
22    pub fn new() -> Self {
23        Self::default()
24    }
25
26    /// Sets the file's comment.
27    pub fn comment(mut self, comment: ZipString) -> Self {
28        self.0.comment = comment;
29        self
30    }
31
32    /// Consumes this builder and returns a final [`ZipFile`].
33    ///
34    /// This is equivalent to:
35    /// ```
36    /// # use async_zip::{ZipFile, ZipFileBuilder};
37    /// #
38    /// # let builder = ZipFileBuilder::new();
39    /// let file: ZipFile = builder.into();
40    /// ```
41    pub fn build(self) -> ZipFile {
42        self.into()
43    }
44}