From 91a868d6db246f1821aa532b699883c7a29c8ce7 Mon Sep 17 00:00:00 2001 From: Colin Finck Date: Sun, 17 Oct 2021 20:49:43 +0200 Subject: Implement `NtfsAttributes::attach` and its helper struct. --- src/attribute.rs | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) 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(&mut self, fs: &mut T) -> Option>> 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>; + + fn next(&mut self) -> Option { + 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>, -- cgit v1.2.3