mirror of
https://github.com/mbilker/kbinxml-rs.git
synced 2026-09-07 10:05:13 -05:00
options: add builder option
This commit is contained in:
@@ -33,7 +33,7 @@ pub use crate::reader::Reader;
|
||||
pub use crate::error::{KbinError, KbinErrorKind, Result};
|
||||
pub use crate::node::{Node, NodeCollection};
|
||||
pub use crate::node_types::StandardType;
|
||||
pub use crate::options::Options;
|
||||
pub use crate::options::{Options, OptionsBuilder};
|
||||
pub use crate::to_text_xml::ToTextXml;
|
||||
pub use crate::value::{Value, ValueArray};
|
||||
pub use crate::writer::{Writer, Writeable};
|
||||
|
||||
@@ -7,6 +7,12 @@ pub struct Options {
|
||||
pub(crate) encoding: EncodingType,
|
||||
}
|
||||
|
||||
#[derive(Default)]
|
||||
pub struct OptionsBuilder {
|
||||
compression: Compression,
|
||||
encoding: EncodingType,
|
||||
}
|
||||
|
||||
impl Options {
|
||||
pub fn new(
|
||||
compression: Compression,
|
||||
@@ -18,6 +24,10 @@ impl Options {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn builder() -> OptionsBuilder {
|
||||
OptionsBuilder::default()
|
||||
}
|
||||
|
||||
pub fn with_encoding(encoding: EncodingType) -> Self {
|
||||
Self {
|
||||
encoding,
|
||||
@@ -25,3 +35,22 @@ impl Options {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl OptionsBuilder {
|
||||
pub fn compression(&mut self, compression: Compression) -> &mut Self {
|
||||
self.compression = compression;
|
||||
self
|
||||
}
|
||||
|
||||
pub fn encoding(&mut self, encoding: EncodingType) -> &mut Self {
|
||||
self.encoding = encoding;
|
||||
self
|
||||
}
|
||||
|
||||
pub fn build(self) -> Options {
|
||||
Options {
|
||||
compression: self.compression,
|
||||
encoding: self.encoding,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user