1
+ use crate :: error:: Result ;
2
+ use crate :: macros:: err;
1
3
use crate :: mp4:: AtomIdent ;
2
4
use crate :: picture:: Picture ;
3
5
@@ -29,6 +31,18 @@ impl Debug for AtomDataStorage {
29
31
}
30
32
}
31
33
34
+ impl IntoIterator for AtomDataStorage {
35
+ type Item = AtomData ;
36
+ type IntoIter = std:: vec:: IntoIter < Self :: Item > ;
37
+
38
+ fn into_iter ( self ) -> Self :: IntoIter {
39
+ match self {
40
+ AtomDataStorage :: Single ( s) => vec ! [ s] . into_iter ( ) ,
41
+ AtomDataStorage :: Multiple ( v) => v. into_iter ( ) ,
42
+ }
43
+ }
44
+ }
45
+
32
46
impl < ' a > IntoIterator for & ' a AtomDataStorage {
33
47
type Item = & ' a AtomData ;
34
48
type IntoIter = AtomDataStorageIter < ' a > ;
@@ -118,6 +132,16 @@ impl<'a> Atom<'a> {
118
132
( & self . data ) . into_iter ( )
119
133
}
120
134
135
+ /// Consumes the atom, returning its [`AtomData`]
136
+ ///
137
+ /// # Examples
138
+ ///
139
+ /// ```rust
140
+ /// ```
141
+ pub fn into_data ( self ) -> impl Iterator < Item = AtomData > {
142
+ self . data . into_iter ( )
143
+ }
144
+
121
145
/// Append a value to the atom
122
146
pub fn push_data ( & mut self , data : AtomData ) {
123
147
match self . data {
@@ -128,6 +152,49 @@ impl<'a> Atom<'a> {
128
152
}
129
153
}
130
154
155
+ /// Merge the data of another atom into this one
156
+ ///
157
+ /// NOTE: Both atoms must have the same identifier
158
+ ///
159
+ /// # Errors
160
+ ///
161
+ /// * `self.ident()` != `other.ident()`
162
+ ///
163
+ /// # Examples
164
+ ///
165
+ /// ```rust
166
+ /// use lofty::mp4::{Atom, AtomData, AtomIdent};
167
+ ///
168
+ /// # fn main() -> lofty::Result<()> {
169
+ /// // Create an artist atom
170
+ /// let mut atom = Atom::new(
171
+ /// AtomIdent::Fourcc(*b"\x49ART"),
172
+ /// AtomData::UTF8(String::from("foo")),
173
+ /// );
174
+ ///
175
+ /// // Create a second and merge it into the first
176
+ /// let atom2 = Atom::new(
177
+ /// AtomIdent::Fourcc(*b"\x49ART"),
178
+ /// AtomData::UTF8(String::from("bar")),
179
+ /// );
180
+ /// atom.merge(atom2)?;
181
+ ///
182
+ /// // Our first atom now contains the second atom's content
183
+ /// assert_eq!(atom.data().count(), 2);
184
+ /// # Ok(()) }
185
+ /// ```
186
+ pub fn merge ( & mut self , other : Atom < ' _ > ) -> Result < ( ) > {
187
+ if self . ident != other. ident {
188
+ err ! ( AtomMismatch ) ;
189
+ }
190
+
191
+ for data in other. data {
192
+ self . push_data ( data)
193
+ }
194
+
195
+ Ok ( ( ) )
196
+ }
197
+
131
198
// Used internally, has no correctness checks
132
199
pub ( crate ) fn unknown_implicit ( ident : AtomIdent < ' _ > , data : Vec < u8 > ) -> Self {
133
200
Self {
@@ -248,7 +315,7 @@ impl AdvisoryRating {
248
315
impl TryFrom < u8 > for AdvisoryRating {
249
316
type Error = u8 ;
250
317
251
- fn try_from ( input : u8 ) -> Result < Self , Self :: Error > {
318
+ fn try_from ( input : u8 ) -> std :: result :: Result < Self , Self :: Error > {
252
319
match input {
253
320
0 => Ok ( Self :: Inoffensive ) ,
254
321
1 | 4 => Ok ( Self :: Explicit ) ,
0 commit comments