mirror of
https://github.com/openharmony/third_party_rust_tinyvec.git
synced 2026-07-18 12:25:35 -04:00
Update arrayvec.rs
This commit is contained in:
+7
-8
@@ -1025,16 +1025,15 @@ where
|
||||
}
|
||||
|
||||
#[cfg(feature = "experimental_write_impl")]
|
||||
impl<A> core::fmt::Write for ArrayVec<A>
|
||||
where
|
||||
A: Array,
|
||||
A::Item: From<u8>,
|
||||
impl<A: Array<Item=u8>> core::fmt::Write for ArrayVec<A>
|
||||
{
|
||||
fn write_str(&mut self, s: &str) -> core::fmt::Result {
|
||||
if self.len() + s.as_bytes().len() <= A::CAPACITY {
|
||||
for byte in s.bytes() {
|
||||
self.push(A::Item::from(byte))
|
||||
}
|
||||
let my_len = self.len();
|
||||
let str_len = s.as_bytes().len();
|
||||
if my_len + str_len <= A::CAPACITY {
|
||||
let remainder = &mut self.data.as_slice()[my_len..];
|
||||
let target = &mut remainder[..str_len];
|
||||
target.copy_from_slice(s.as_bytes());
|
||||
Ok(())
|
||||
} else {
|
||||
Err(core::fmt::Error)
|
||||
|
||||
Reference in New Issue
Block a user