Compare commits
10 Commits
9c2227c992
...
1d411cefb5
| Author | SHA1 | Date | |
|---|---|---|---|
| 1d411cefb5 | |||
|
|
d3cb2a9843 | ||
|
|
5ced9d3eca | ||
|
|
f5b2a7931c | ||
|
|
f964546f58 | ||
|
|
916aa267ca | ||
|
|
cbed25c41b | ||
|
|
da61e6e12c | ||
|
|
228542aad9 | ||
|
|
31a0115e26 |
@@ -1,8 +0,0 @@
|
|||||||
# See here for image contents: https://github.com/microsoft/vscode-dev-containers/tree/v0.195.0/containers/rust/.devcontainer/base.Dockerfile
|
|
||||||
# [Choice] Debian OS version (use bullseye on local arm64/Apple Silicon): buster, bullseye
|
|
||||||
ARG VARIANT="bullseye"
|
|
||||||
FROM mcr.microsoft.com/devcontainers/rust:1-${VARIANT}
|
|
||||||
|
|
||||||
# [Optional] Uncomment this section to install additional packages.
|
|
||||||
# RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \
|
|
||||||
# && apt-get -y install --no-install-recommends <your-package-list-here>
|
|
||||||
@@ -1,41 +1,24 @@
|
|||||||
// For format details, see https://aka.ms/vscode-remote/devcontainer.json or this file's README at:
|
// For format details, see https://aka.ms/devcontainer.json. For config options, see the
|
||||||
// https://github.com/microsoft/vscode-dev-containers/tree/v0.195.0/containers/rust
|
// README at: https://github.com/devcontainers/templates/tree/main/src/rust
|
||||||
{
|
{
|
||||||
"name": "Rust Sample",
|
"name": "Rust",
|
||||||
"build": {
|
// Or use a Dockerfile or Docker Compose file. More info: https://containers.dev/guide/dockerfile
|
||||||
"dockerfile": "Dockerfile",
|
"image": "mcr.microsoft.com/devcontainers/rust:1-1-bullseye",
|
||||||
"args": {
|
|
||||||
// Use the VARIANT arg to pick a Debian OS version: buster, bullseye
|
// Features to add to the dev container. More info: https://containers.dev/features.
|
||||||
// Use bullseye when on local on arm64/Apple Silicon.
|
// "features": {},
|
||||||
"VARIANT": "bullseye"
|
"postStartCommand": "cargo run",
|
||||||
}
|
|
||||||
},
|
|
||||||
"runArgs": [ "--cap-add=SYS_PTRACE", "--security-opt", "seccomp=unconfined" ],
|
|
||||||
|
|
||||||
// Configure tool-specific properties.
|
// Configure tool-specific properties.
|
||||||
"customizations": {
|
"customizations": {
|
||||||
// Configure properties specific to VS Code.
|
// Configure properties specific to VS Code.
|
||||||
"vscode": {
|
"vscode": {
|
||||||
// Set *default* container specific settings.json values on container create.
|
"settings": {},
|
||||||
"settings": {
|
|
||||||
"lldb.executable": "/usr/bin/lldb",
|
|
||||||
// VS Code don't watch files under ./target
|
|
||||||
"files.watcherExclude": {
|
|
||||||
"**/target/**": true
|
|
||||||
},
|
|
||||||
"rust-analyzer.checkOnSave.command": "clippy"
|
|
||||||
},
|
|
||||||
|
|
||||||
// Add the IDs of extensions you want installed when the container is created.
|
|
||||||
"extensions": [
|
"extensions": [
|
||||||
"vadimcn.vscode-lldb",
|
"streetsidesoftware.code-spell-checker"
|
||||||
"mutantdino.resourcemonitor",
|
|
||||||
"matklad.rust-analyzer",
|
|
||||||
"tamasfe.even-better-toml",
|
|
||||||
"serayuzgur.crates"
|
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
},
|
}
|
||||||
|
|
||||||
// Use 'forwardPorts' to make a list of ports inside the container available locally.
|
// Use 'forwardPorts' to make a list of ports inside the container available locally.
|
||||||
// "forwardPorts": [],
|
// "forwardPorts": [],
|
||||||
@@ -43,6 +26,6 @@
|
|||||||
// Use 'postCreateCommand' to run commands after the container is created.
|
// Use 'postCreateCommand' to run commands after the container is created.
|
||||||
// "postCreateCommand": "rustc --version",
|
// "postCreateCommand": "rustc --version",
|
||||||
|
|
||||||
// Comment out to run as root instead.
|
// Uncomment to connect as root instead. More info: https://aka.ms/dev-containers-non-root.
|
||||||
"remoteUser": "vscode"
|
// "remoteUser": "root"
|
||||||
}
|
}
|
||||||
|
|||||||
7
.gitea/workflows/dependabot.yml
Normal file
7
.gitea/workflows/dependabot.yml
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
# For more details, see https://containers.dev/guide/dependabot
|
||||||
|
version: 2
|
||||||
|
updates:
|
||||||
|
- package-ecosystem: "devcontainers"
|
||||||
|
directory: "/"
|
||||||
|
schedule:
|
||||||
|
interval: weekly
|
||||||
9
CODE_OF_CONDUCT.md
Normal file
9
CODE_OF_CONDUCT.md
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
# Microsoft Open Source Code of Conduct
|
||||||
|
|
||||||
|
This project has adopted the [Microsoft Open Source Code of Conduct](https://opensource.microsoft.com/codeofconduct/).
|
||||||
|
|
||||||
|
Resources:
|
||||||
|
|
||||||
|
- [Microsoft Open Source Code of Conduct](https://opensource.microsoft.com/codeofconduct/)
|
||||||
|
- [Microsoft Code of Conduct FAQ](https://opensource.microsoft.com/codeofconduct/faq/)
|
||||||
|
- Contact [opencode@microsoft.com](mailto:opencode@microsoft.com) with questions or concerns
|
||||||
79
README.md
79
README.md
@@ -1,76 +1,17 @@
|
|||||||
# Try Out Development Containers: Rust
|
# base
|
||||||
|
|
||||||
[](https://vscode.dev/redirect?url=vscode://ms-vscode-remote.remote-containers/cloneInVolume?url=https://github.com/microsoft/vscode-remote-try-rust)
|
Rust 基础开发环境镜像模板项目
|
||||||
|
|
||||||
A **development container** is a running [Docker](https://www.docker.com) container with a well-defined tool/runtime stack and its prerequisites. You can try out development containers with **[GitHub Codespaces](https://github.com/features/codespaces)** or **[Visual Studio Code Remote - Containers](https://aka.ms/vscode-remote/containers)**.
|
Rust 项目工程模板
|
||||||
|
|
||||||
This is a sample project that lets you try out either option in a few easy steps. We have a variety of other [vscode-remote-try-*](https://github.com/search?q=org%3Amicrosoft+vscode-remote-try-&type=Repositories) sample projects, too.
|
## 使用方法
|
||||||
|
|
||||||
> **Note:** If you already have a Codespace or dev container, you can jump to the [Things to try](#things-to-try) section.
|
```
|
||||||
|
cargo run
|
||||||
|
```
|
||||||
|
|
||||||
## Setting up the development container
|
### 版权说明
|
||||||
|
|
||||||
### GitHub Codespaces
|
Copyright @ Mengning Software
|
||||||
Follow these steps to open this sample in a Codespace:
|
|
||||||
1. Click the Code drop-down menu and select the **Open with Codespaces** option.
|
|
||||||
1. Select **+ New codespace** at the bottom on the pane.
|
|
||||||
|
|
||||||
For more info, check out the [GitHub documentation](https://docs.github.com/en/free-pro-team@latest/github/developing-online-with-codespaces/creating-a-codespace#creating-a-codespace).
|
梦宁软件(江苏)有限公司 版权所有
|
||||||
|
|
||||||
### VS Code Remote - Containers
|
|
||||||
|
|
||||||
If you already have VS Code and Docker installed, you can click the badge above or [here](https://vscode.dev/redirect?url=vscode://ms-vscode-remote.remote-containers/cloneInVolume?url=https://github.com/microsoft/vscode-remote-try-rust) to get started. Clicking these links will cause VS Code to automatically install the Remote - Containers extension if needed, clone the source code into a container volume, and spin up a dev container for use.
|
|
||||||
|
|
||||||
Follow these steps to open this sample in a container using the VS Code Remote - Containers extension:
|
|
||||||
|
|
||||||
1. If this is your first time using a development container, please ensure your system meets the pre-reqs (i.e. have Docker installed) in the [getting started steps](https://aka.ms/vscode-remote/containers/getting-started).
|
|
||||||
|
|
||||||
2. To use this repository, you can either open the repository in an isolated Docker volume:
|
|
||||||
|
|
||||||
- Press <kbd>F1</kbd> and select the **Remote-Containers: Try a Sample...** command.
|
|
||||||
- Choose the "Rust" sample, wait for the container to start, and try things out!
|
|
||||||
> **Note:** Under the hood, this will use the **Remote-Containers: Clone Repository in Container Volume...** command to clone the source code in a Docker volume instead of the local filesystem. [Volumes](https://docs.docker.com/storage/volumes/) are the preferred mechanism for persisting container data.
|
|
||||||
|
|
||||||
Or open a locally cloned copy of the code:
|
|
||||||
|
|
||||||
- Clone this repository to your local filesystem.
|
|
||||||
- Press <kbd>F1</kbd> and select the **Remote-Containers: Open Folder in Container...** command.
|
|
||||||
- Select the cloned copy of this folder, wait for the container to start, and try things out!
|
|
||||||
|
|
||||||
## Things to try
|
|
||||||
|
|
||||||
Once you have this sample opened, you'll be able to work with it like you would locally.
|
|
||||||
|
|
||||||
> **Note:** This container runs as a non-root user with sudo access by default. Comment out `"remoteUser": "vscode"` in `.devcontainer/devcontainer.json` if you'd prefer to run as root.
|
|
||||||
|
|
||||||
Some things to try:
|
|
||||||
|
|
||||||
1. **Edit:**
|
|
||||||
- Open `main.rs`
|
|
||||||
- Try adding some code and check out the language features.
|
|
||||||
- Notice that several extensions are already installed in the container, such as Rust support for VS Code, since the `.devcontainer/devcontainer.json` lists a set of extensions, including `"rust-lang.rust"`, to install automatically when the container is created.
|
|
||||||
1. **Terminal:** Press <kbd>ctrl</kbd>+<kbd>shift</kbd>+<kbd>\`</kbd> and type `uname` and other Linux commands from the terminal window.
|
|
||||||
1. **Build, Run, and Debug:**
|
|
||||||
- Open `main.rs`
|
|
||||||
- Add a breakpoint (e.g. on line 8).
|
|
||||||
- Press <kbd>F5</kbd> to launch the app in the container.
|
|
||||||
- Once the breakpoint is hit, try hovering over variables, examining locals, and more.
|
|
||||||
|
|
||||||
## Contributing
|
|
||||||
|
|
||||||
This project welcomes contributions and suggestions. Most contributions require you to agree to a
|
|
||||||
Contributor License Agreement (CLA) declaring that you have the right to, and actually do, grant us
|
|
||||||
the rights to use your contribution. For details, visit https://cla.microsoft.com.
|
|
||||||
|
|
||||||
When you submit a pull request, a CLA-bot will automatically determine whether you need to provide
|
|
||||||
a CLA and decorate the PR appropriately (e.g., label, comment). Simply follow the instructions
|
|
||||||
provided by the bot. You will only need to do this once across all repos using our CLA.
|
|
||||||
|
|
||||||
This project has adopted the [Microsoft Open Source Code of Conduct](https://opensource.microsoft.com/codeofconduct/).
|
|
||||||
For more information see the [Code of Conduct FAQ](https://opensource.microsoft.com/codeofconduct/faq/) or
|
|
||||||
contact [opencode@microsoft.com](mailto:opencode@microsoft.com) with any additional questions or comments.
|
|
||||||
|
|
||||||
## License
|
|
||||||
|
|
||||||
Copyright © Microsoft Corporation All rights reserved.<br />
|
|
||||||
Licensed under the MIT License. See LICENSE in the project root for license information.
|
|
||||||
|
|||||||
41
SECURITY.md
Normal file
41
SECURITY.md
Normal file
@@ -0,0 +1,41 @@
|
|||||||
|
<!-- BEGIN MICROSOFT SECURITY.MD V0.0.8 BLOCK -->
|
||||||
|
|
||||||
|
## Security
|
||||||
|
|
||||||
|
Microsoft takes the security of our software products and services seriously, which includes all source code repositories managed through our GitHub organizations, which include [Microsoft](https://github.com/microsoft), [Azure](https://github.com/Azure), [DotNet](https://github.com/dotnet), [AspNet](https://github.com/aspnet), [Xamarin](https://github.com/xamarin), and [our GitHub organizations](https://opensource.microsoft.com/).
|
||||||
|
|
||||||
|
If you believe you have found a security vulnerability in any Microsoft-owned repository that meets [Microsoft's definition of a security vulnerability](https://aka.ms/opensource/security/definition), please report it to us as described below.
|
||||||
|
|
||||||
|
## Reporting Security Issues
|
||||||
|
|
||||||
|
**Please do not report security vulnerabilities through public GitHub issues.**
|
||||||
|
|
||||||
|
Instead, please report them to the Microsoft Security Response Center (MSRC) at [https://msrc.microsoft.com/create-report](https://aka.ms/opensource/security/create-report).
|
||||||
|
|
||||||
|
If you prefer to submit without logging in, send email to [secure@microsoft.com](mailto:secure@microsoft.com). If possible, encrypt your message with our PGP key; please download it from the [Microsoft Security Response Center PGP Key page](https://aka.ms/opensource/security/pgpkey).
|
||||||
|
|
||||||
|
You should receive a response within 24 hours. If for some reason you do not, please follow up via email to ensure we received your original message. Additional information can be found at [microsoft.com/msrc](https://aka.ms/opensource/security/msrc).
|
||||||
|
|
||||||
|
Please include the requested information listed below (as much as you can provide) to help us better understand the nature and scope of the possible issue:
|
||||||
|
|
||||||
|
* Type of issue (e.g. buffer overflow, SQL injection, cross-site scripting, etc.)
|
||||||
|
* Full paths of source file(s) related to the manifestation of the issue
|
||||||
|
* The location of the affected source code (tag/branch/commit or direct URL)
|
||||||
|
* Any special configuration required to reproduce the issue
|
||||||
|
* Step-by-step instructions to reproduce the issue
|
||||||
|
* Proof-of-concept or exploit code (if possible)
|
||||||
|
* Impact of the issue, including how an attacker might exploit the issue
|
||||||
|
|
||||||
|
This information will help us triage your report more quickly.
|
||||||
|
|
||||||
|
If you are reporting for a bug bounty, more complete reports can contribute to a higher bounty award. Please visit our [Microsoft Bug Bounty Program](https://aka.ms/opensource/security/bounty) page for more details about our active programs.
|
||||||
|
|
||||||
|
## Preferred Languages
|
||||||
|
|
||||||
|
We prefer all communications to be in English.
|
||||||
|
|
||||||
|
## Policy
|
||||||
|
|
||||||
|
Microsoft follows the principle of [Coordinated Vulnerability Disclosure](https://aka.ms/opensource/security/cvd).
|
||||||
|
|
||||||
|
<!-- END MICROSOFT SECURITY.MD BLOCK -->
|
||||||
20
src/main.rs
20
src/main.rs
@@ -3,7 +3,21 @@
|
|||||||
* Licensed under the MIT License. See https://go.microsoft.com/fwlink/?linkid=2090316 for license information.
|
* Licensed under the MIT License. See https://go.microsoft.com/fwlink/?linkid=2090316 for license information.
|
||||||
*-------------------------------------------------------------------------------------------------------------*/
|
*-------------------------------------------------------------------------------------------------------------*/
|
||||||
|
|
||||||
fn main() {
|
fn two_sum(nums: Vec<i32>, target: i32) -> Vec<i32> {
|
||||||
let name = "VS Code Remote - Containers";
|
use std::collections::HashMap;
|
||||||
println!("Hello, {}!", name);
|
let mut map = HashMap::new();
|
||||||
|
for (i, &num) in nums.iter().enumerate() {
|
||||||
|
if let Some(&j) = map.get(&(target - num)) {
|
||||||
|
return vec![j as i32, i as i32];
|
||||||
|
}
|
||||||
|
map.insert(num, i);
|
||||||
|
}
|
||||||
|
vec![]
|
||||||
|
}
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
let nums = vec![2, 7, 11, 15];
|
||||||
|
let target = 9;
|
||||||
|
let result = two_sum(nums, target);
|
||||||
|
println!("{:?}", result); // 输出: [0, 1]
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user