core API: move StrChunks* to metadata

This commit is contained in:
awiouy 2018-02-13 08:33:50 +01:00
parent 0ed4fb1c68
commit edbe00c62b
2 changed files with 26 additions and 27 deletions

View file

@ -29,32 +29,6 @@ pub fn powm(base: &BigUint, exp: &BigUint, modulus: &BigUint) -> BigUint {
result
}
pub struct StrChunks<'s>(&'s str, usize);
pub trait StrChunksExt {
fn chunks(&self, size: usize) -> StrChunks;
}
impl StrChunksExt for str {
fn chunks(&self, size: usize) -> StrChunks {
StrChunks(self, size)
}
}
impl<'s> Iterator for StrChunks<'s> {
type Item = &'s str;
fn next(&mut self) -> Option<&'s str> {
let &mut StrChunks(data, size) = self;
if data.is_empty() {
None
} else {
let ret = Some(&data[..size]);
self.0 = &data[size..];
ret
}
}
}
pub trait ReadSeek: ::std::io::Read + ::std::io::Seek {}
impl<T: ::std::io::Read + ::std::io::Seek> ReadSeek for T {}

View file

@ -14,7 +14,6 @@ use linear_map::LinearMap;
use core::mercury::MercuryError;
use core::session::Session;
use core::spotify_id::{FileId, SpotifyId};
use core::util::StrChunksExt;
pub use protocol::metadata::AudioFile_Format as FileFormat;
@ -215,3 +214,29 @@ impl Metadata for Artist {
}
}
}
struct StrChunks<'s>(&'s str, usize);
trait StrChunksExt {
fn chunks(&self, size: usize) -> StrChunks;
}
impl StrChunksExt for str {
fn chunks(&self, size: usize) -> StrChunks {
StrChunks(self, size)
}
}
impl<'s> Iterator for StrChunks<'s> {
type Item = &'s str;
fn next(&mut self) -> Option<&'s str> {
let &mut StrChunks(data, size) = self;
if data.is_empty() {
None
} else {
let ret = Some(&data[..size]);
self.0 = &data[size..];
ret
}
}
}