update manual

This commit is contained in:
Tianyi 2020-10-27 23:18:03 +00:00
parent 923d7b1ce8
commit e218f6c47d
7 changed files with 64 additions and 50 deletions

Binary file not shown.

Binary file not shown.

View file

@ -205,7 +205,8 @@ The following example shows how you can read the tag in an \texttt{mp3} file, co
\CommentTok{// we have an mp3 and an m4a file}
\KeywordTok{const}\NormalTok{ MP3\_FILE}\OperatorTok{:} \OperatorTok{\&}\OtherTok{\textquotesingle{}static} \DataTypeTok{str} \OperatorTok{=} \StringTok{"assets/a.mp3"}\OperatorTok{;}
\KeywordTok{const}\NormalTok{ M4A\_FILE}\OperatorTok{:} \OperatorTok{\&}\OtherTok{\textquotesingle{}static} \DataTypeTok{str} \OperatorTok{=} \StringTok{"assets/a.m4a"}\OperatorTok{;}
\CommentTok{// read tag from the mp3 file. Using \textasciigrave{}default()\textasciigrave{} so that the type of tag is guessed from the file extension}
\CommentTok{// read tag from the mp3 file. Using \textasciigrave{}default()\textasciigrave{} so that the}
\CommentTok{// type of tag is guessed from the file extension}
\KeywordTok{let} \KeywordTok{mut}\NormalTok{ mp3tag }\OperatorTok{=} \PreprocessorTok{Tag::}\KeywordTok{default}\NormalTok{()}\OperatorTok{.}\NormalTok{read\_from\_path(MP3\_FILE)}\OperatorTok{.}\NormalTok{unwrap()}\OperatorTok{;}
\CommentTok{// set the title}
\NormalTok{ mp3tag}\OperatorTok{.}\NormalTok{set\_title(}\StringTok{"title from mp3 file"}\NormalTok{)}\OperatorTok{;}
@ -213,11 +214,13 @@ The following example shows how you can read the tag in an \texttt{mp3} file, co
\KeywordTok{let} \KeywordTok{mut}\NormalTok{ mp4tag }\OperatorTok{=}\NormalTok{ mp3tag}\OperatorTok{.}\NormalTok{into\_tag(}\PreprocessorTok{TagType::}\NormalTok{Mp4)}\OperatorTok{;}
\NormalTok{ mp4tag}\OperatorTok{.}\NormalTok{write\_to\_path(M4A\_FILE)}\OperatorTok{.}\NormalTok{unwrap()}\OperatorTok{;}
\CommentTok{// reload the tag from the m4a file; this time specifying the tag type (you can also use \textasciigrave{}default()\textasciigrave{})}
\CommentTok{// reload the tag from the m4a file; this time specifying the}
\CommentTok{// tag type (you can also use \textasciigrave{}default()\textasciigrave{})}
\KeywordTok{let} \KeywordTok{mut}\NormalTok{ mp4tag }\OperatorTok{=} \PreprocessorTok{Tag::}\NormalTok{with\_tag\_type(}\PreprocessorTok{TagType::}\NormalTok{Mp4)}
\OperatorTok{.}\NormalTok{read\_from\_path(M4A\_FILE)}
\OperatorTok{.}\NormalTok{unwrap()}\OperatorTok{;}
\CommentTok{// the tag originated from an mp3 file is successfully written to an m4a file!}
\CommentTok{// the tag originated from an mp3 file is successfully written}
\CommentTok{// to an m4a file!}
\PreprocessorTok{assert\_eq!}\NormalTok{(mp4tag}\OperatorTok{.}\NormalTok{title()}\OperatorTok{,} \ConstantTok{Some}\NormalTok{(}\StringTok{"title from mp3 file"}\NormalTok{))}\OperatorTok{;}
\CommentTok{// multiple artists}
\NormalTok{ mp4tag}\OperatorTok{.}\NormalTok{add\_artist(}\StringTok{"artist1 of mp4"}\NormalTok{)}\OperatorTok{;}
@ -280,7 +283,9 @@ The following example shows how you can downcast a \texttt{Box\textless{}dyn\ Au
\OperatorTok{.}\NormalTok{expect(}\StringTok{"Fail to read!"}\NormalTok{)}\OperatorTok{;}
\PreprocessorTok{assert\_eq!}\NormalTok{(id3tag\_reload}\OperatorTok{.}\NormalTok{title()}\OperatorTok{,} \ConstantTok{Some}\NormalTok{(}\StringTok{"title from metaflac::Tag"}\NormalTok{))}\OperatorTok{;}
\KeywordTok{let} \KeywordTok{mut}\NormalTok{ id3tag\_inner}\OperatorTok{:} \PreprocessorTok{id3::}\NormalTok{Tag }\OperatorTok{=} \PreprocessorTok{downcast!}\NormalTok{(id3tag\_reload}\OperatorTok{,}\NormalTok{ Id3v2Tag)}\OperatorTok{;}
\KeywordTok{let} \KeywordTok{mut}\NormalTok{ id3tag\_inner}\OperatorTok{:} \PreprocessorTok{id3::}\NormalTok{Tag }\OperatorTok{=}\NormalTok{ id3tag\_reload}\OperatorTok{.}\NormalTok{try\_into()}\OperatorTok{.}\NormalTok{unwrap()}\OperatorTok{;}
\CommentTok{// this would fail if \textasciigrave{}id3tag\_reload\textasciigrave{} isn\textquotesingle{}t really a id3 tag.}
\KeywordTok{let}\NormalTok{ timestamp }\OperatorTok{=} \PreprocessorTok{id3::}\NormalTok{Timestamp }\OperatorTok{\{}
\NormalTok{ year}\OperatorTok{:} \DecValTok{2013}\OperatorTok{,}
\NormalTok{ month}\OperatorTok{:} \ConstantTok{Some}\NormalTok{(}\DecValTok{2u8}\NormalTok{)}\OperatorTok{,}
@ -294,7 +299,8 @@ The following example shows how you can downcast a \texttt{Box\textless{}dyn\ Au
\OperatorTok{.}\NormalTok{write\_to\_path(}\StringTok{"assets/a.mp3"}\OperatorTok{,} \PreprocessorTok{id3::Version::}\NormalTok{Id3v24)}
\OperatorTok{.}\NormalTok{expect(}\StringTok{"Fail to write!"}\NormalTok{)}\OperatorTok{;}
\KeywordTok{let}\NormalTok{ id3tag\_reload }\OperatorTok{=} \PreprocessorTok{id3::Tag::}\NormalTok{read\_from\_path(}\StringTok{"assets/a.mp3"}\NormalTok{)}\OperatorTok{.}\NormalTok{expect(}\StringTok{"Fail to read!"}\NormalTok{)}\OperatorTok{;}
\KeywordTok{let}\NormalTok{ id3tag\_reload }\OperatorTok{=} \PreprocessorTok{id3::Tag::}\NormalTok{read\_from\_path(}\StringTok{"assets/a.mp3"}\NormalTok{)}
\OperatorTok{.}\NormalTok{expect(}\StringTok{"Fail to read!"}\NormalTok{)}\OperatorTok{;}
\PreprocessorTok{assert\_eq!}\NormalTok{(id3tag\_reload}\OperatorTok{.}\NormalTok{date\_recorded()}\OperatorTok{,} \ConstantTok{Some}\NormalTok{(timestamp))}\OperatorTok{;}
\OperatorTok{\}}
\end{Highlighting}

View file

@ -171,33 +171,36 @@ code span.wa { color: #60a0b0; font-weight: bold; font-style: italic; } /* Warni
<span id="cb2-4"><a href="conversion.html#cb2-4" aria-hidden="true"></a> <span class="co">// we have an mp3 and an m4a file</span></span>
<span id="cb2-5"><a href="conversion.html#cb2-5" aria-hidden="true"></a> <span class="kw">const</span> MP3_FILE<span class="op">:</span> <span class="op">&amp;</span><span class="ot">&#39;static</span> <span class="dt">str</span> <span class="op">=</span> <span class="st">&quot;assets/a.mp3&quot;</span><span class="op">;</span></span>
<span id="cb2-6"><a href="conversion.html#cb2-6" aria-hidden="true"></a> <span class="kw">const</span> M4A_FILE<span class="op">:</span> <span class="op">&amp;</span><span class="ot">&#39;static</span> <span class="dt">str</span> <span class="op">=</span> <span class="st">&quot;assets/a.m4a&quot;</span><span class="op">;</span></span>
<span id="cb2-7"><a href="conversion.html#cb2-7" aria-hidden="true"></a> <span class="co">// read tag from the mp3 file. Using `default()` so that the type of tag is guessed from the file extension</span></span>
<span id="cb2-8"><a href="conversion.html#cb2-8" aria-hidden="true"></a> <span class="kw">let</span> <span class="kw">mut</span> mp3tag <span class="op">=</span> <span class="pp">Tag::</span><span class="kw">default</span>()<span class="op">.</span>read_from_path(MP3_FILE)<span class="op">.</span>unwrap()<span class="op">;</span></span>
<span id="cb2-9"><a href="conversion.html#cb2-9" aria-hidden="true"></a> <span class="co">// set the title</span></span>
<span id="cb2-10"><a href="conversion.html#cb2-10" aria-hidden="true"></a> mp3tag<span class="op">.</span>set_title(<span class="st">&quot;title from mp3 file&quot;</span>)<span class="op">;</span></span>
<span id="cb2-11"><a href="conversion.html#cb2-11" aria-hidden="true"></a> <span class="co">// we can convert it to an mp4 tag and save it to an m4a file.</span></span>
<span id="cb2-12"><a href="conversion.html#cb2-12" aria-hidden="true"></a> <span class="kw">let</span> <span class="kw">mut</span> mp4tag <span class="op">=</span> mp3tag<span class="op">.</span>into_tag(<span class="pp">TagType::</span>Mp4)<span class="op">;</span></span>
<span id="cb2-13"><a href="conversion.html#cb2-13" aria-hidden="true"></a> mp4tag<span class="op">.</span>write_to_path(M4A_FILE)<span class="op">.</span>unwrap()<span class="op">;</span></span>
<span id="cb2-14"><a href="conversion.html#cb2-14" aria-hidden="true"></a></span>
<span id="cb2-15"><a href="conversion.html#cb2-15" aria-hidden="true"></a> <span class="co">// reload the tag from the m4a file; this time specifying the tag type (you can also use `default()`)</span></span>
<span id="cb2-16"><a href="conversion.html#cb2-16" aria-hidden="true"></a> <span class="kw">let</span> <span class="kw">mut</span> mp4tag <span class="op">=</span> <span class="pp">Tag::</span>with_tag_type(<span class="pp">TagType::</span>Mp4)</span>
<span id="cb2-17"><a href="conversion.html#cb2-17" aria-hidden="true"></a> <span class="op">.</span>read_from_path(M4A_FILE)</span>
<span id="cb2-18"><a href="conversion.html#cb2-18" aria-hidden="true"></a> <span class="op">.</span>unwrap()<span class="op">;</span></span>
<span id="cb2-19"><a href="conversion.html#cb2-19" aria-hidden="true"></a> <span class="co">// the tag originated from an mp3 file is successfully written to an m4a file!</span></span>
<span id="cb2-20"><a href="conversion.html#cb2-20" aria-hidden="true"></a> <span class="pp">assert_eq!</span>(mp4tag<span class="op">.</span>title()<span class="op">,</span> <span class="cn">Some</span>(<span class="st">&quot;title from mp3 file&quot;</span>))<span class="op">;</span></span>
<span id="cb2-21"><a href="conversion.html#cb2-21" aria-hidden="true"></a> <span class="co">// multiple artists</span></span>
<span id="cb2-22"><a href="conversion.html#cb2-22" aria-hidden="true"></a> mp4tag<span class="op">.</span>add_artist(<span class="st">&quot;artist1 of mp4&quot;</span>)<span class="op">;</span></span>
<span id="cb2-23"><a href="conversion.html#cb2-23" aria-hidden="true"></a> mp4tag<span class="op">.</span>add_artist(<span class="st">&quot;artist2 of mp4&quot;</span>)<span class="op">;</span></span>
<span id="cb2-24"><a href="conversion.html#cb2-24" aria-hidden="true"></a> <span class="pp">assert_eq!</span>(</span>
<span id="cb2-25"><a href="conversion.html#cb2-25" aria-hidden="true"></a> mp4tag<span class="op">.</span>artists()<span class="op">,</span></span>
<span id="cb2-26"><a href="conversion.html#cb2-26" aria-hidden="true"></a> <span class="cn">Some</span>(<span class="pp">vec!</span>[<span class="st">&quot;artist1 of mp4&quot;</span><span class="op">,</span> <span class="st">&quot;artist2 of mp4&quot;</span>])</span>
<span id="cb2-27"><a href="conversion.html#cb2-27" aria-hidden="true"></a> )<span class="op">;</span></span>
<span id="cb2-28"><a href="conversion.html#cb2-28" aria-hidden="true"></a> <span class="co">// convert to id3 tag, which does not support multiple artists</span></span>
<span id="cb2-29"><a href="conversion.html#cb2-29" aria-hidden="true"></a> mp4tag<span class="op">.</span>set_config(<span class="pp">Config::</span><span class="kw">default</span>()<span class="op">.</span>sep_artist(<span class="st">&quot;/&quot;</span>))<span class="op">;</span></span>
<span id="cb2-30"><a href="conversion.html#cb2-30" aria-hidden="true"></a> <span class="co">// separator is by default `;` but we can customise it</span></span>
<span id="cb2-31"><a href="conversion.html#cb2-31" aria-hidden="true"></a> <span class="kw">let</span> mp3tag <span class="op">=</span> mp4tag<span class="op">.</span>into_tag(<span class="pp">TagType::</span>Id3v2)<span class="op">;</span></span>
<span id="cb2-32"><a href="conversion.html#cb2-32" aria-hidden="true"></a> <span class="pp">assert_eq!</span>(mp3tag<span class="op">.</span>artist()<span class="op">,</span> <span class="cn">Some</span>(<span class="st">&quot;artist1 of mp4/artist2 of mp4&quot;</span>))<span class="op">;</span></span>
<span id="cb2-33"><a href="conversion.html#cb2-33" aria-hidden="true"></a><span class="op">}</span></span></code></pre></div>
<span id="cb2-7"><a href="conversion.html#cb2-7" aria-hidden="true"></a> <span class="co">// read tag from the mp3 file. Using `default()` so that the</span></span>
<span id="cb2-8"><a href="conversion.html#cb2-8" aria-hidden="true"></a> <span class="co">// type of tag is guessed from the file extension</span></span>
<span id="cb2-9"><a href="conversion.html#cb2-9" aria-hidden="true"></a> <span class="kw">let</span> <span class="kw">mut</span> mp3tag <span class="op">=</span> <span class="pp">Tag::</span><span class="kw">default</span>()<span class="op">.</span>read_from_path(MP3_FILE)<span class="op">.</span>unwrap()<span class="op">;</span></span>
<span id="cb2-10"><a href="conversion.html#cb2-10" aria-hidden="true"></a> <span class="co">// set the title</span></span>
<span id="cb2-11"><a href="conversion.html#cb2-11" aria-hidden="true"></a> mp3tag<span class="op">.</span>set_title(<span class="st">&quot;title from mp3 file&quot;</span>)<span class="op">;</span></span>
<span id="cb2-12"><a href="conversion.html#cb2-12" aria-hidden="true"></a> <span class="co">// we can convert it to an mp4 tag and save it to an m4a file.</span></span>
<span id="cb2-13"><a href="conversion.html#cb2-13" aria-hidden="true"></a> <span class="kw">let</span> <span class="kw">mut</span> mp4tag <span class="op">=</span> mp3tag<span class="op">.</span>into_tag(<span class="pp">TagType::</span>Mp4)<span class="op">;</span></span>
<span id="cb2-14"><a href="conversion.html#cb2-14" aria-hidden="true"></a> mp4tag<span class="op">.</span>write_to_path(M4A_FILE)<span class="op">.</span>unwrap()<span class="op">;</span></span>
<span id="cb2-15"><a href="conversion.html#cb2-15" aria-hidden="true"></a></span>
<span id="cb2-16"><a href="conversion.html#cb2-16" aria-hidden="true"></a> <span class="co">// reload the tag from the m4a file; this time specifying the</span></span>
<span id="cb2-17"><a href="conversion.html#cb2-17" aria-hidden="true"></a> <span class="co">// tag type (you can also use `default()`)</span></span>
<span id="cb2-18"><a href="conversion.html#cb2-18" aria-hidden="true"></a> <span class="kw">let</span> <span class="kw">mut</span> mp4tag <span class="op">=</span> <span class="pp">Tag::</span>with_tag_type(<span class="pp">TagType::</span>Mp4)</span>
<span id="cb2-19"><a href="conversion.html#cb2-19" aria-hidden="true"></a> <span class="op">.</span>read_from_path(M4A_FILE)</span>
<span id="cb2-20"><a href="conversion.html#cb2-20" aria-hidden="true"></a> <span class="op">.</span>unwrap()<span class="op">;</span></span>
<span id="cb2-21"><a href="conversion.html#cb2-21" aria-hidden="true"></a> <span class="co">// the tag originated from an mp3 file is successfully written</span></span>
<span id="cb2-22"><a href="conversion.html#cb2-22" aria-hidden="true"></a> <span class="co">// to an m4a file!</span></span>
<span id="cb2-23"><a href="conversion.html#cb2-23" aria-hidden="true"></a> <span class="pp">assert_eq!</span>(mp4tag<span class="op">.</span>title()<span class="op">,</span> <span class="cn">Some</span>(<span class="st">&quot;title from mp3 file&quot;</span>))<span class="op">;</span></span>
<span id="cb2-24"><a href="conversion.html#cb2-24" aria-hidden="true"></a> <span class="co">// multiple artists</span></span>
<span id="cb2-25"><a href="conversion.html#cb2-25" aria-hidden="true"></a> mp4tag<span class="op">.</span>add_artist(<span class="st">&quot;artist1 of mp4&quot;</span>)<span class="op">;</span></span>
<span id="cb2-26"><a href="conversion.html#cb2-26" aria-hidden="true"></a> mp4tag<span class="op">.</span>add_artist(<span class="st">&quot;artist2 of mp4&quot;</span>)<span class="op">;</span></span>
<span id="cb2-27"><a href="conversion.html#cb2-27" aria-hidden="true"></a> <span class="pp">assert_eq!</span>(</span>
<span id="cb2-28"><a href="conversion.html#cb2-28" aria-hidden="true"></a> mp4tag<span class="op">.</span>artists()<span class="op">,</span></span>
<span id="cb2-29"><a href="conversion.html#cb2-29" aria-hidden="true"></a> <span class="cn">Some</span>(<span class="pp">vec!</span>[<span class="st">&quot;artist1 of mp4&quot;</span><span class="op">,</span> <span class="st">&quot;artist2 of mp4&quot;</span>])</span>
<span id="cb2-30"><a href="conversion.html#cb2-30" aria-hidden="true"></a> )<span class="op">;</span></span>
<span id="cb2-31"><a href="conversion.html#cb2-31" aria-hidden="true"></a> <span class="co">// convert to id3 tag, which does not support multiple artists</span></span>
<span id="cb2-32"><a href="conversion.html#cb2-32" aria-hidden="true"></a> mp4tag<span class="op">.</span>set_config(<span class="pp">Config::</span><span class="kw">default</span>()<span class="op">.</span>sep_artist(<span class="st">&quot;/&quot;</span>))<span class="op">;</span></span>
<span id="cb2-33"><a href="conversion.html#cb2-33" aria-hidden="true"></a> <span class="co">// separator is by default `;` but we can customise it</span></span>
<span id="cb2-34"><a href="conversion.html#cb2-34" aria-hidden="true"></a> <span class="kw">let</span> mp3tag <span class="op">=</span> mp4tag<span class="op">.</span>into_tag(<span class="pp">TagType::</span>Id3v2)<span class="op">;</span></span>
<span id="cb2-35"><a href="conversion.html#cb2-35" aria-hidden="true"></a> <span class="pp">assert_eq!</span>(mp3tag<span class="op">.</span>artist()<span class="op">,</span> <span class="cn">Some</span>(<span class="st">&quot;artist1 of mp4/artist2 of mp4&quot;</span>))<span class="op">;</span></span>
<span id="cb2-36"><a href="conversion.html#cb2-36" aria-hidden="true"></a><span class="op">}</span></span></code></pre></div>
</div>
</section>

View file

@ -183,23 +183,26 @@ code span.wa { color: #60a0b0; font-weight: bold; font-style: italic; } /* Warni
<span id="cb4-16"><a href="downcast.html#cb4-16" aria-hidden="true"></a> <span class="op">.</span>expect(<span class="st">&quot;Fail to read!&quot;</span>)<span class="op">;</span></span>
<span id="cb4-17"><a href="downcast.html#cb4-17" aria-hidden="true"></a> <span class="pp">assert_eq!</span>(id3tag_reload<span class="op">.</span>title()<span class="op">,</span> <span class="cn">Some</span>(<span class="st">&quot;title from metaflac::Tag&quot;</span>))<span class="op">;</span></span>
<span id="cb4-18"><a href="downcast.html#cb4-18" aria-hidden="true"></a></span>
<span id="cb4-19"><a href="downcast.html#cb4-19" aria-hidden="true"></a> <span class="kw">let</span> <span class="kw">mut</span> id3tag_inner<span class="op">:</span> <span class="pp">id3::</span>Tag <span class="op">=</span> <span class="pp">downcast!</span>(id3tag_reload<span class="op">,</span> Id3v2Tag)<span class="op">;</span></span>
<span id="cb4-20"><a href="downcast.html#cb4-20" aria-hidden="true"></a> <span class="kw">let</span> timestamp <span class="op">=</span> <span class="pp">id3::</span>Timestamp <span class="op">{</span></span>
<span id="cb4-21"><a href="downcast.html#cb4-21" aria-hidden="true"></a> year<span class="op">:</span> <span class="dv">2013</span><span class="op">,</span></span>
<span id="cb4-22"><a href="downcast.html#cb4-22" aria-hidden="true"></a> month<span class="op">:</span> <span class="cn">Some</span>(<span class="dv">2u8</span>)<span class="op">,</span></span>
<span id="cb4-23"><a href="downcast.html#cb4-23" aria-hidden="true"></a> day<span class="op">:</span> <span class="cn">Some</span>(<span class="dv">5u8</span>)<span class="op">,</span></span>
<span id="cb4-24"><a href="downcast.html#cb4-24" aria-hidden="true"></a> hour<span class="op">:</span> <span class="cn">Some</span>(<span class="dv">6u8</span>)<span class="op">,</span></span>
<span id="cb4-25"><a href="downcast.html#cb4-25" aria-hidden="true"></a> minute<span class="op">:</span> <span class="cn">None</span><span class="op">,</span></span>
<span id="cb4-26"><a href="downcast.html#cb4-26" aria-hidden="true"></a> second<span class="op">:</span> <span class="cn">None</span><span class="op">,</span></span>
<span id="cb4-27"><a href="downcast.html#cb4-27" aria-hidden="true"></a> <span class="op">};</span></span>
<span id="cb4-28"><a href="downcast.html#cb4-28" aria-hidden="true"></a> id3tag_inner<span class="op">.</span>set_date_recorded(timestamp<span class="op">.</span>clone())<span class="op">;</span></span>
<span id="cb4-29"><a href="downcast.html#cb4-29" aria-hidden="true"></a> id3tag_inner</span>
<span id="cb4-30"><a href="downcast.html#cb4-30" aria-hidden="true"></a> <span class="op">.</span>write_to_path(<span class="st">&quot;assets/a.mp3&quot;</span><span class="op">,</span> <span class="pp">id3::Version::</span>Id3v24)</span>
<span id="cb4-31"><a href="downcast.html#cb4-31" aria-hidden="true"></a> <span class="op">.</span>expect(<span class="st">&quot;Fail to write!&quot;</span>)<span class="op">;</span></span>
<span id="cb4-32"><a href="downcast.html#cb4-32" aria-hidden="true"></a></span>
<span id="cb4-33"><a href="downcast.html#cb4-33" aria-hidden="true"></a> <span class="kw">let</span> id3tag_reload <span class="op">=</span> <span class="pp">id3::Tag::</span>read_from_path(<span class="st">&quot;assets/a.mp3&quot;</span>)<span class="op">.</span>expect(<span class="st">&quot;Fail to read!&quot;</span>)<span class="op">;</span></span>
<span id="cb4-34"><a href="downcast.html#cb4-34" aria-hidden="true"></a> <span class="pp">assert_eq!</span>(id3tag_reload<span class="op">.</span>date_recorded()<span class="op">,</span> <span class="cn">Some</span>(timestamp))<span class="op">;</span></span>
<span id="cb4-35"><a href="downcast.html#cb4-35" aria-hidden="true"></a><span class="op">}</span></span></code></pre></div>
<span id="cb4-19"><a href="downcast.html#cb4-19" aria-hidden="true"></a> <span class="kw">let</span> <span class="kw">mut</span> id3tag_inner<span class="op">:</span> <span class="pp">id3::</span>Tag <span class="op">=</span> id3tag_reload<span class="op">.</span>try_into()<span class="op">.</span>unwrap()<span class="op">;</span></span>
<span id="cb4-20"><a href="downcast.html#cb4-20" aria-hidden="true"></a> <span class="co">// this would fail if `id3tag_reload` isn&#39;t really a id3 tag.</span></span>
<span id="cb4-21"><a href="downcast.html#cb4-21" aria-hidden="true"></a></span>
<span id="cb4-22"><a href="downcast.html#cb4-22" aria-hidden="true"></a> <span class="kw">let</span> timestamp <span class="op">=</span> <span class="pp">id3::</span>Timestamp <span class="op">{</span></span>
<span id="cb4-23"><a href="downcast.html#cb4-23" aria-hidden="true"></a> year<span class="op">:</span> <span class="dv">2013</span><span class="op">,</span></span>
<span id="cb4-24"><a href="downcast.html#cb4-24" aria-hidden="true"></a> month<span class="op">:</span> <span class="cn">Some</span>(<span class="dv">2u8</span>)<span class="op">,</span></span>
<span id="cb4-25"><a href="downcast.html#cb4-25" aria-hidden="true"></a> day<span class="op">:</span> <span class="cn">Some</span>(<span class="dv">5u8</span>)<span class="op">,</span></span>
<span id="cb4-26"><a href="downcast.html#cb4-26" aria-hidden="true"></a> hour<span class="op">:</span> <span class="cn">Some</span>(<span class="dv">6u8</span>)<span class="op">,</span></span>
<span id="cb4-27"><a href="downcast.html#cb4-27" aria-hidden="true"></a> minute<span class="op">:</span> <span class="cn">None</span><span class="op">,</span></span>
<span id="cb4-28"><a href="downcast.html#cb4-28" aria-hidden="true"></a> second<span class="op">:</span> <span class="cn">None</span><span class="op">,</span></span>
<span id="cb4-29"><a href="downcast.html#cb4-29" aria-hidden="true"></a> <span class="op">};</span></span>
<span id="cb4-30"><a href="downcast.html#cb4-30" aria-hidden="true"></a> id3tag_inner<span class="op">.</span>set_date_recorded(timestamp<span class="op">.</span>clone())<span class="op">;</span></span>
<span id="cb4-31"><a href="downcast.html#cb4-31" aria-hidden="true"></a> id3tag_inner</span>
<span id="cb4-32"><a href="downcast.html#cb4-32" aria-hidden="true"></a> <span class="op">.</span>write_to_path(<span class="st">&quot;assets/a.mp3&quot;</span><span class="op">,</span> <span class="pp">id3::Version::</span>Id3v24)</span>
<span id="cb4-33"><a href="downcast.html#cb4-33" aria-hidden="true"></a> <span class="op">.</span>expect(<span class="st">&quot;Fail to write!&quot;</span>)<span class="op">;</span></span>
<span id="cb4-34"><a href="downcast.html#cb4-34" aria-hidden="true"></a></span>
<span id="cb4-35"><a href="downcast.html#cb4-35" aria-hidden="true"></a> <span class="kw">let</span> id3tag_reload <span class="op">=</span> <span class="pp">id3::Tag::</span>read_from_path(<span class="st">&quot;assets/a.mp3&quot;</span>)</span>
<span id="cb4-36"><a href="downcast.html#cb4-36" aria-hidden="true"></a> <span class="op">.</span>expect(<span class="st">&quot;Fail to read!&quot;</span>)<span class="op">;</span></span>
<span id="cb4-37"><a href="downcast.html#cb4-37" aria-hidden="true"></a> <span class="pp">assert_eq!</span>(id3tag_reload<span class="op">.</span>date_recorded()<span class="op">,</span> <span class="cn">Some</span>(timestamp))<span class="op">;</span></span>
<span id="cb4-38"><a href="downcast.html#cb4-38" aria-hidden="true"></a><span class="op">}</span></span></code></pre></div>
</div>
</section>

File diff suppressed because one or more lines are too long

View file

@ -142,6 +142,8 @@ pub trait IntoAnyTag {
/// Convert the tag type, which can be lossy.
fn into_tag(&self, tag_type: TagType) -> Box<dyn AudioTag> {
// TODO: write a macro or something that implement this method for every tag type so that if the
// TODO: target type is the same, just return self
match tag_type {
TagType::Id3v2 => Box::new(Id3v2Tag::from(self.into_anytag())),
TagType::Mp4 => Box::new(Mp4Tag::from(self.into_anytag())),