mirror of
https://github.com/rust-embedded/heapless.git
synced 2025-09-30 05:50:29 +00:00
Impl Borrow and BorrowMut for String and Vec.
This enables them to be used in maps, especially with &str get values in a Map<String, T>.
This commit is contained in:
parent
a9ed238672
commit
103ae85bb5
@ -33,6 +33,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
|
||||
- Added `DequeView`, the `!Sized` version of `Deque`.
|
||||
- Added `QueueView`, the `!Sized` version of `Queue`.
|
||||
- Added `SortedLinkedListView`, the `!Sized` version of `SortedLinkedList`.
|
||||
- Added implementation of `Borrow` and `BorrowMut` for `String` and `Vec`.
|
||||
|
||||
### Changed
|
||||
|
||||
|
@ -71,7 +71,7 @@ where
|
||||
/// assert_eq!(map.capacity(), 8);
|
||||
/// ```
|
||||
pub fn capacity(&self) -> usize {
|
||||
self.buffer.borrow().capacity()
|
||||
self.buffer.capacity()
|
||||
}
|
||||
|
||||
/// Clears the map, removing all key-value pairs.
|
||||
|
@ -1,6 +1,7 @@
|
||||
//! A fixed capacity [`String`](https://doc.rust-lang.org/std/string/struct.String.html).
|
||||
|
||||
use core::{
|
||||
borrow,
|
||||
char::DecodeUtf16Error,
|
||||
cmp::Ordering,
|
||||
fmt,
|
||||
@ -732,6 +733,17 @@ impl<S: Storage> ops::DerefMut for StringInner<S> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<S: Storage> borrow::Borrow<str> for StringInner<S> {
|
||||
fn borrow(&self) -> &str {
|
||||
self.as_str()
|
||||
}
|
||||
}
|
||||
impl<S: Storage> borrow::BorrowMut<str> for StringInner<S> {
|
||||
fn borrow_mut(&mut self) -> &mut str {
|
||||
self.as_mut_str()
|
||||
}
|
||||
}
|
||||
|
||||
impl<S: Storage> AsRef<str> for StringInner<S> {
|
||||
#[inline]
|
||||
fn as_ref(&self) -> &str {
|
||||
|
@ -1,5 +1,6 @@
|
||||
//! A fixed capacity [`Vec`](https://doc.rust-lang.org/std/vec/struct.Vec.html).
|
||||
|
||||
use core::borrow;
|
||||
use core::{
|
||||
borrow::{Borrow, BorrowMut},
|
||||
cmp::Ordering,
|
||||
@ -1410,6 +1411,17 @@ impl<T, S: Storage> ops::DerefMut for VecInner<T, S> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<T, S: Storage> borrow::Borrow<[T]> for VecInner<T, S> {
|
||||
fn borrow(&self) -> &[T] {
|
||||
self.as_slice()
|
||||
}
|
||||
}
|
||||
impl<T, S: Storage> borrow::BorrowMut<[T]> for VecInner<T, S> {
|
||||
fn borrow_mut(&mut self) -> &mut [T] {
|
||||
self.as_mut_slice()
|
||||
}
|
||||
}
|
||||
|
||||
impl<T, S: Storage> AsRef<VecInner<T, S>> for VecInner<T, S> {
|
||||
#[inline]
|
||||
fn as_ref(&self) -> &Self {
|
||||
|
Loading…
x
Reference in New Issue
Block a user