Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/windirstat/ntfs.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorColin Finck <colin@reactos.org>2021-10-17 21:49:43 +0300
committerColin Finck <colin@reactos.org>2021-10-17 21:49:43 +0300
commit91a868d6db246f1821aa532b699883c7a29c8ce7 (patch)
tree6e8bc4a8071bb7c4ce765c9366e568fa26c43c80
parentc4a7bb9c8b12b47138a4172d868b52b60ce2e4d8 (diff)
Implement `NtfsAttributes::attach` and its helper struct.
-rw-r--r--src/attribute.rs38
1 files changed, 38 insertions, 0 deletions
diff --git a/src/attribute.rs b/src/attribute.rs
index a4b6ae3..a5abf11 100644
--- a/src/attribute.rs
+++ b/src/attribute.rs
@@ -419,6 +419,13 @@ impl<'n, 'f> NtfsAttributes<'n, 'f> {
}
}
+ pub fn attach<'a, T>(self, fs: &'a mut T) -> NtfsAttributesAttached<'n, 'f, 'a, T>
+ where
+ T: Read + Seek,
+ {
+ NtfsAttributesAttached::new(fs, self)
+ }
+
pub fn next<T>(&mut self, fs: &mut T) -> Option<Result<NtfsAttributeItem<'n, 'f>>>
where
T: Read + Seek,
@@ -497,6 +504,37 @@ impl<'n, 'f> NtfsAttributes<'n, 'f> {
}
}
+pub struct NtfsAttributesAttached<'n, 'f, 'a, T: Read + Seek> {
+ fs: &'a mut T,
+ attributes: NtfsAttributes<'n, 'f>,
+}
+
+impl<'n, 'f, 'a, T> NtfsAttributesAttached<'n, 'f, 'a, T>
+where
+ T: Read + Seek,
+{
+ fn new(fs: &'a mut T, attributes: NtfsAttributes<'n, 'f>) -> Self {
+ Self { fs, attributes }
+ }
+
+ pub fn detach(self) -> NtfsAttributes<'n, 'f> {
+ self.attributes
+ }
+}
+
+impl<'n, 'f, 'a, T> Iterator for NtfsAttributesAttached<'n, 'f, 'a, T>
+where
+ T: Read + Seek,
+{
+ type Item = Result<NtfsAttributeItem<'n, 'f>>;
+
+ fn next(&mut self) -> Option<Self::Item> {
+ self.attributes.next(self.fs)
+ }
+}
+
+impl<'n, 'f, 'a, T> FusedIterator for NtfsAttributesAttached<'n, 'f, 'a, T> where T: Read + Seek {}
+
#[derive(Clone, Debug)]
pub struct NtfsAttributeItem<'n, 'f> {
attribute_file: &'f NtfsFile<'n>,