1
0
mirror of https://github.com/google/comprehensive-rust.git synced 2025-04-13 20:50:47 +02:00

Put tinyvec example inline.

This commit is contained in:
Andrew Walbran 2023-03-21 14:57:26 +00:00
parent fb3fd3979c
commit f5b6e47f31
5 changed files with 10 additions and 41 deletions

7
Cargo.lock generated
View File

@ -2068,13 +2068,6 @@ dependencies = [
"tinyvec_macros",
]
[[package]]
name = "tinyvec-example"
version = "0.1.0"
dependencies = [
"tinyvec",
]
[[package]]
name = "tinyvec_macros"
version = "0.1.0"

View File

@ -3,6 +3,5 @@ members = [
"i18n-helpers",
"src/exercises",
"src/bare-metal/useful-crates/allocator-example",
"src/bare-metal/useful-crates/tinyvec-example",
"src/bare-metal/useful-crates/zerocopy-example",
]

View File

@ -1,7 +0,0 @@
[package]
name = "tinyvec-example"
version = "0.1.0"
edition = "2021"
[dependencies]
tinyvec = "1.6.0"

View File

@ -1,25 +0,0 @@
// Copyright 2023 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// ANCHOR: main
use tinyvec::{array_vec, ArrayVec};
fn main() {
let mut numbers: ArrayVec<[u32; 5]> = array_vec!(42, 66);
println!("{numbers:?}");
numbers.push(7);
println!("{numbers:?}");
numbers.remove(1);
println!("{numbers:?}");
}

View File

@ -6,7 +6,16 @@ allocated or on the stack, which keeps track of how many elements are used and p
use more than are allocated.
```rust,editable,compile_fail
{{#include tinyvec-example/src/main.rs:main}}
use tinyvec::{array_vec, ArrayVec};
fn main() {
let mut numbers: ArrayVec<[u32; 5]> = array_vec!(42, 66);
println!("{numbers:?}");
numbers.push(7);
println!("{numbers:?}");
numbers.remove(1);
println!("{numbers:?}");
}
```
<details>