mirror of
https://github.com/librespot-org/librespot.git
synced 2024-12-18 17:11:53 +00:00
core API: move StrChunks* to metadata
This commit is contained in:
parent
0ed4fb1c68
commit
edbe00c62b
2 changed files with 26 additions and 27 deletions
|
@ -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 {}
|
||||
|
||||
|
|
|
@ -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
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue