File tree Expand file tree Collapse file tree 1 file changed +16
-2
lines changed Expand file tree Collapse file tree 1 file changed +16
-2
lines changed Original file line number Diff line number Diff line change @@ -246,11 +246,25 @@ impl Plot {
246
246
///
247
247
/// In contrast to `Plot::show()` this will save the resulting html in a user specified location
248
248
/// instead of the system temp directory.
249
+ ///
250
+ /// In contrast to `Plot::write_html`, this will save the resulting html to a file located at a
251
+ /// user specified location, instead of a writing it to anything that implements `std::io::Write`.
249
252
pub fn to_html < P : AsRef < Path > > ( & self , filename : P ) {
253
+ let mut file = File :: create ( filename. as_ref ( ) ) . unwrap ( ) ;
254
+
255
+ self . write_html ( & mut file) ;
256
+ }
257
+
258
+ /// Renders the contents of the `Plot` to HTML and outputs them to a writable buffer.
259
+ ///
260
+ /// In contrast to `Plot::to_html`, this will save the resulting html to a byte buffer using the
261
+ /// `std::io::Write` trait, instead of to a user specified file.
262
+ pub fn write_html < W : Write > ( & self , buffer : & mut W ) {
250
263
let rendered = self . render ( false , "" , 0 , 0 ) ;
251
264
let rendered = rendered. as_bytes ( ) ;
252
- let mut file = File :: create ( filename. as_ref ( ) ) . unwrap ( ) ;
253
- file. write_all ( rendered)
265
+
266
+ buffer
267
+ . write_all ( rendered)
254
268
. expect ( "failed to write html output" ) ;
255
269
}
256
270
You can’t perform that action at this time.
0 commit comments