18:  Add AsMut and AsRef implementations for Vec and String  r=japaric a=glandium

And a cleanup commit removing unused `#![features]`
This commit is contained in:
bors[bot] 2018-03-07 15:08:34 +00:00
commit 76f26e28e7
3 changed files with 60 additions and 2 deletions

View File

@ -92,9 +92,7 @@
#![deny(missing_docs)]
#![deny(warnings)]
#![feature(const_fn)]
#![feature(const_unsafe_cell_new)]
#![feature(core_intrinsics)]
#![feature(shared)]
#![feature(unsize)]
#![no_std]

View File

@ -426,6 +426,26 @@ where
}
}
impl<A> AsRef<str> for String<A>
where
A: Unsize<[u8]>,
{
#[inline]
fn as_ref(&self) -> &str {
self
}
}
impl<A> AsRef<[u8]> for String<A>
where
A: Unsize<[u8]>,
{
#[inline]
fn as_ref(&self) -> &[u8] {
self.as_bytes()
}
}
impl<A, B> PartialEq<String<B>> for String<A>
where
A: Unsize<[u8]>,

View File

@ -243,6 +243,46 @@ where
}
}
impl<T, A> AsRef<Vec<T, A>> for Vec<T, A>
where
A: Unsize<[T]>,
{
#[inline]
fn as_ref(&self) -> &Vec<T, A> {
self
}
}
impl<T, A> AsMut<Vec<T, A>> for Vec<T, A>
where
A: Unsize<[T]>,
{
#[inline]
fn as_mut(&mut self) -> &mut Vec<T, A> {
self
}
}
impl<T, A> AsRef<[T]> for Vec<T, A>
where
A: Unsize<[T]>,
{
#[inline]
fn as_ref(&self) -> &[T] {
self
}
}
impl<T, A> AsMut<[T]> for Vec<T, A>
where
A: Unsize<[T]>,
{
#[inline]
fn as_mut(&mut self) -> &mut [T] {
self
}
}
#[cfg(test)]
mod tests {
use Vec;