4
4
//! [qualified names]: https://www.w3.org/TR/xml-names11/#dt-qualname
5
5
//! [expanded names]: https://www.w3.org/TR/xml-names11/#dt-expname
6
6
7
- use std:: io:: BufRead ;
7
+ use std:: fs:: File ;
8
+ use std:: io:: { BufRead , BufReader } ;
8
9
use std:: ops:: { Deref , DerefMut } ;
10
+ use std:: path:: Path ;
9
11
10
12
use crate :: errors:: Result ;
11
13
use crate :: events:: Event ;
@@ -29,6 +31,15 @@ pub struct NsReader<R> {
29
31
pending_pop : bool ,
30
32
}
31
33
34
+ /// Builder methods
35
+ impl < R > NsReader < R > {
36
+ /// Creates a `NsReader` that reads from a reader.
37
+ #[ inline]
38
+ pub fn from_reader ( reader : R ) -> Self {
39
+ Self :: new ( Reader :: from_reader ( reader) )
40
+ }
41
+ }
42
+
32
43
/// Private methods
33
44
impl < R > NsReader < R > {
34
45
#[ inline]
@@ -96,6 +107,14 @@ impl<R> NsReader<R> {
96
107
97
108
/// Getters
98
109
impl < R > NsReader < R > {
110
+ /// Consumes `NsReader` returning the underlying reader
111
+ ///
112
+ /// See the [`Reader::into_inner`] for examples
113
+ #[ inline]
114
+ pub fn into_inner ( self ) -> R {
115
+ self . reader . into_inner ( )
116
+ }
117
+
99
118
/// Resolves a potentially qualified **element name** or **attribute name**
100
119
/// into (namespace name, local name).
101
120
///
@@ -386,6 +405,15 @@ impl<R: BufRead> NsReader<R> {
386
405
}
387
406
}
388
407
408
+ impl NsReader < BufReader < File > > {
409
+ /// Creates an XML reader from a file path.
410
+ pub fn from_file < P : AsRef < Path > > ( path : P ) -> Result < Self > {
411
+ let file = File :: open ( path) ?;
412
+ let reader = BufReader :: new ( file) ;
413
+ Ok ( Self :: from_reader ( reader) )
414
+ }
415
+ }
416
+
389
417
impl < ' i > NsReader < & ' i [ u8 ] > {
390
418
/// Creates an XML reader from a string slice.
391
419
#[ inline]
0 commit comments