pub struct FileDestination { /* private fields */ }Expand description
Destination implementation for writing JSON data to a file File output destination writing to a buffered file on disk (32KB write buffer).
Implementations§
Source§impl FileDestination
impl FileDestination
Sourcepub fn new(path: impl AsRef<Path>) -> Result<FileDestination, Error>
pub fn new(path: impl AsRef<Path>) -> Result<FileDestination, Error>
Creates or opens a file for writing with 32KB buffer.
Examples found in repository?
More examples
examples/json_strip_whitespace.rs (lines 11-16)
9fn process_json_file(file_path: &str) -> Result<(), String> {
10 let mut source = FileSource::new(file_path).map_err(|e| e.to_string())?;
11 let mut destination = FileDestination::new(
12 Path::new(file_path)
13 .with_extension("json_stripped")
14 .to_string_lossy()
15 .as_ref(),
16 )
17 .map_err(|e| e.to_string())?;
18
19 strip_whitespace(&mut source, &mut destination);
20 Ok(())
21}examples/json_to_toml.rs (lines 13-18)
10fn process_json_file(file_path: &str) -> Result<(), String> {
11 let mut source = FileSource::new(file_path).map_err(|e| e.to_string())?;
12 let node = parse(&mut source).map_err(|e| e.to_string())?;
13 let mut destination = FileDestination::new(
14 Path::new(file_path)
15 .with_extension("toml")
16 .to_string_lossy()
17 .as_ref(),
18 )
19 .map_err(|e| e.to_string())?;
20
21 to_toml(&node, &mut destination)?;
22 Ok(())
23}examples/json_pretty_print.rs (lines 13-18)
10fn process_json_file(file_path: &str) -> Result<(), String> {
11 let mut source = FileSource::new(file_path).map_err(|e| e.to_string())?;
12 let node = parse(&mut source).map_err(|e| e.to_string())?;
13 let mut destination = FileDestination::new(
14 Path::new(file_path)
15 .with_extension("json_pp")
16 .to_string_lossy()
17 .as_ref(),
18 )
19 .map_err(|e| e.to_string())?;
20
21 print(&node, &mut destination, 4);
22 Ok(())
23}examples/json_to_bencode.rs (lines 12-17)
9fn process_json_file(file_path: &str) -> Result<(), String> {
10 let mut source = FileSource::new(file_path).map_err(|e| e.to_string())?;
11 let node = parse(&mut source).map_err(|e| e.to_string())?;
12 let mut destination = FileDestination::new(
13 Path::new(file_path)
14 .with_extension("bencode")
15 .to_string_lossy()
16 .as_ref(),
17 )
18 .map_err(|e| e.to_string())?;
19
20 to_bencode(&node, &mut destination)?;
21 Ok(())
22}examples/json_to_xml.rs (lines 12-17)
9fn process_json_file(file_path: &str) -> Result<(), String> {
10 let mut source = FileSource::new(file_path).map_err(|e| e.to_string())?;
11 let node = parse(&mut source).map_err(|e| e.to_string())?;
12 let mut destination = FileDestination::new(
13 Path::new(file_path)
14 .with_extension("xml")
15 .to_string_lossy()
16 .as_ref(),
17 )
18 .map_err(|e| e.to_string())?;
19
20 to_xml(&node, &mut destination).map_err(|e| e.to_string())?;
21 Ok(())
22}Additional examples can be found in:
Sourcepub fn create(path: impl AsRef<Path>) -> Result<FileDestination, Error>
pub fn create(path: impl AsRef<Path>) -> Result<FileDestination, Error>
Creates or opens a file for writing with 32KB buffer.
Sourcepub fn add_bytes(&mut self, bytes: &str)
pub fn add_bytes(&mut self, bytes: &str)
Writes multiple bytes from a string slice to the buffered destination.
Sourcepub fn file_length(&self) -> usize
pub fn file_length(&self) -> usize
Returns the number of bytes written.
Sourcepub fn flush(&mut self) -> Result<(), Error>
pub fn flush(&mut self) -> Result<(), Error>
Flushes the underlying buffered writer and syncs file data.
Trait Implementations§
Source§impl Drop for FileDestination
Available on crate feature file-io only.
impl Drop for FileDestination
Available on crate feature
file-io only.Source§impl IByteWriter for FileDestination
Available on crate feature file-io only.
impl IByteWriter for FileDestination
Available on crate feature
file-io only.Source§impl IClearable for FileDestination
Available on crate feature file-io only.
impl IClearable for FileDestination
Available on crate feature
file-io only.Source§impl IDestination for FileDestination
Available on crate feature file-io only.
impl IDestination for FileDestination
Available on crate feature
file-io only.Source§impl IFlushable for FileDestination
Available on crate feature file-io only.
impl IFlushable for FileDestination
Available on crate feature
file-io only.Source§impl ITailInspectable for FileDestination
Available on crate feature file-io only.
impl ITailInspectable for FileDestination
Available on crate feature
file-io only.Auto Trait Implementations§
impl Freeze for FileDestination
impl RefUnwindSafe for FileDestination
impl Send for FileDestination
impl Sync for FileDestination
impl Unpin for FileDestination
impl UnsafeUnpin for FileDestination
impl UnwindSafe for FileDestination
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more