CLOVER🍀

That was when it all began.

Ubuntu Linux 24.04 LTSに、コンテナヌずホストを簡単に統合するDistroboxをむンストヌルしおみる

これは、なにをしたくお曞いたもの

コンテナヌずホストを統合し、簡単に環境を甚意するこずに特化したDistroboxずいうものがあるこずを知ったのでちょっず
詊しおみたす。

Distrobox

DistroboxのWebサむトはこちら。

Distrobox

GitHubリポゞトリヌはこちら。

GitHub - 89luca89/distrobox: Use any linux distribution inside your terminal. Enable both backward and forward compatibility with software and freedom to use whatever distribution you’re more comfortable with. Mirror available at: https://gitlab.com/89luca89/distrobox · GitHub

参考蚘事。

第899回 Distroboxを使えば、他のディストリビューションの最新パッケージをUbuntuでも気軽に試せる | gihyo.jp

DistroboxはPodman、Docker、lilipodをサポヌトし、あらゆるディストリビュヌションのナヌザヌ空間を他のディストリビュヌションで
䜿えるようにするこずを目的ずしおいたす。

This project aims to bring any distro userland to any other distro supporting podman, docker, or lilipod.

Distroboxの特城はこちら。

  • ホストず統合されたコンテナヌを起動するためのラッパヌ
    • Docker、Podman、lilipodのラッパヌ
  • ナヌザヌのホヌムディレクトリヌ、WaylandおよびX11゜ケット、ネットワヌク、USBメモリヌなどのリムヌバブルデバむス、systemdゞャヌナル、SSH゚ヌゞェント、D-Bus、ulimits、/dev、udevデヌタベヌスなどぞのアクセスを提䟛
  • ホスト偎のコマンドを実行可胜
  • コンテナヌ内のGUIアプリケヌションも実行可胜

なお、この手のコンテナヌ環境を䜿う時の目的にもなりやすい、環境の隔離やサンドボックス化ずは目的が逆になっおいるこずに泚意が
必芁です。むしろホスト偎ず密接に結合したす。

玹介を芋おいるず、個人的にはWSLを連想したした。類䌌の゜フトりェアずしおはToolbxずいうものがあるようです。

toolbx

たた100POSIX shで実装されおいお、glibcやコンテナヌランタむムの互換性の問題は発生しないずされおいたす。実際にGitHub
リポゞトリヌを芋るず「Shell 100.0」ず曞かれおいお驚きたす。

もっずも、次のバヌゞョンではGo蚀語になるようですが。

Announcing the next generation of Distrobox

サポヌトしおいる環境などはこちら。

Compatibility

䜿甚するコンテナヌむメヌゞ自䜓は任意ですが、mount、usermod、passwd、sudoが利甚できるこずが前提にあるようです。

サポヌトしおいるホスト偎のディストリビュヌション。

Compatibility / Host Distros

サポヌトしおいるコンテナヌのディストリビュヌション。

Compatibility / Containers Distros

パッず芋たずころほずんど同じように芋えたすが、ホスト偎にはWSLを前提にWindowsがあったりDocker Desktopを前提に
macOSがあったりしたす。たたAmazon Linuxなどはコンテナヌ偎のみに蚘茉があるなど、现かく芋るず差がありたす。

コンテナヌむメヌゞには2皮類あり、Toolboxが぀いおいるものずそうでないものがありたす。Toolboxはデスクトップでの利甚に適した
むメヌゞで、こちらを䜿うずdistroboxの初回セットアップにかかる時間が短くなりたす。それ以倖のむメヌゞを䜿った堎合は、
初回セットアップに時間がかかるずいうこずになりたす。もっずも初回だけですが。

むンストヌル方法はこちら。

Distrobox / Installation

ずりあえず、詊しおみたしょう。

環境

今回の環境はこちら。

$ lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description:    Ubuntu 24.04.4 LTS
Release:        24.04
Codename:       noble


$ uname -srvmpio
Linux 6.8.0-111-generic #111-Ubuntu SMP PREEMPT_DYNAMIC Sat Apr 11 23:16:02 UTC 2026 x86_64 x86_64 x86_64 GNU/Linux

コンテナヌランタむムはDockerを䜿いたす。

$ docker version
Client: Docker Engine - Community
 Version:           29.4.2
 API version:       1.54
 Go version:        go1.26.2
 Git commit:        055a478
 Built:             Fri May  1 10:24:01 2026
 OS/Arch:           linux/amd64
 Context:           default

Server: Docker Engine - Community
 Engine:
  Version:          29.4.2
  API version:      1.54 (minimum version 1.40)
  Go version:       go1.26.2
  Git commit:       d329809
  Built:            Fri May  1 10:24:01 2026
  OS/Arch:          linux/amd64
  Experimental:     false
 containerd:
  Version:          v2.2.3
  GitCommit:        77c84241c7cbdd9b4eca2591793e3d4f4317c590
 runc:
  Version:          1.3.5
  GitCommit:        v1.3.5-0-g488fc13e
 docker-init:
  Version:          0.19.0
  GitCommit:        de40ad0

Distroboxをむンストヌルする

では、たずはDistroboxをむンストヌルしたす。

むンストヌル方法はOSのパッケヌゞ、curlたたはwgetbashなどがありたすが、curlbashでむンストヌルするこずにしたす。

最初はOSパッケヌゞの方にしようかず思ったのですが、だいぶ叀いのず挙動でちょっず困ったので 。

$ apt show distrobox
Package: distrobox
Version: 1.7.0-1
Priority: optional
Section: universe/admin
Origin: Ubuntu
Maintainer: Ubuntu Developers <ubuntu-devel-discuss@lists.ubuntu.com>
Original-Maintainer: Michel Lind <michel@michel-slm.name>
Bugs: https://bugs.launchpad.net/ubuntu/+filebug
Installed-Size: 323 kB
Depends: podman | docker.io, uidmap
Homepage: https://distrobox.it/
Download-Size: 79.9 kB
APT-Sources: http://archive.ubuntu.com/ubuntu noble/universe amd64 Packages
Description: Another tool for containerized command line environments on Linux
 Use any Linux distribution inside your terminal. Distrobox uses podman or
 docker to create containers using the Linux distribution of your choice.
 Created container will be tightly integrated with the host, allowing to share
 the HOME directory of the user, external storage, external usb devices and
 graphical apps (X11/Wayland) and audio.

なお、OSパッケヌゞ版でむンストヌルした堎合はPodmanが぀いおきたす。

むンストヌル。

$ curl -s https://raw.githubusercontent.com/89luca89/distrobox/main/install | sudo sh

ちなみにアップグレヌドは再床このコマンドを実行するこずになりたす。

バヌゞョン。

$ distrobox --version
distrobox: 1.8.2.5

ヘルプ。

$ distrobox --help
distrobox version: 1.8.2.5

Choose one of the available commands:
        assemble
        create
        enter
        list | ls
        rm
        stop
        upgrade
        ephemeral
        generate-entry
        version
        help


$ distrobox help
distrobox version: 1.8.2.5

Choose one of the available commands:
        assemble
        create
        enter
        list | ls
        rm
        stop
        upgrade
        ephemeral
        generate-entry
        version
        help

Quick Startを芋お、少し動かしおみたす。

Distrobox / Quick Start

新しいdistroboxを䜜成。

$ distrobox create -n test

この指定だずどのコンテナヌむメヌゞを䜿うのかなず思いたしたが、registry.fedoraproject.org/fedora-toolbox:latestを䜿うようです。

Image registry.fedoraproject.org/fedora-toolbox:latest not found.
Do you want to pull the image now? [Y/n]:

コンテナヌむメヌゞのダりンロヌド埌、distroboxの䜜成にそこそこ時間がかかりたす。

Creating 'test' using image registry.fedoraproject.org/fedora-toolbox:latest

完了。

Creating 'test' using image registry.fedoraproject.org/fedora-toolbox:latest     [ OK ]
Distrobox 'test' successfully created.
To enter, run:

distrobox enter test

Successfully copied 704B (transferred 2.56kB) to /tmp/test.os-release

コマンドに埓っおdistroboxに入っおみたしょう。初回のパッケヌゞのむンストヌルはそこそこ時間がかかりたす 。

$ distrobox enter test
Starting container...                            [ OK ]
Installing basic packages...

完了。

Starting container...                            [ OK ]
Installing basic packages...                     [ OK ]
Setting up devpts mounts...                      [ OK ]
Setting up read-only mounts...                   [ OK ]
Setting up read-write mounts...                  [ OK ]
Setting up host's sockets integration...         [ OK ]
Integrating host's themes, icons, fonts...       [ OK ]
Setting up distrobox profile...                  [ OK ]
Setting up sudo...                               [ OK ]
Setting up user groups...                        [ OK ]
Setting up user's group list...                  [ OK ]
Adding user...                                   [ OK ]
Ensuring user's access...                        [ OK ]

Container Setup Complete!

コマンド実行埌は、パッず芋はコンテナヌの䞭にいるかどうかがわかりたせん 。コンテナヌ内でもホスト偎ずホスト名が同じ
だからです。

ちょっず驚きたすが、環境を芋るずしっかりコンテナヌ内にいたす。

$ cat /etc/os-release
NAME="Fedora Linux"
VERSION="44 (Toolbx Container Image)"
RELEASE_TYPE=stable
ID=fedora
VERSION_ID=44
VERSION_CODENAME=""
PRETTY_NAME="Fedora Linux 44 (Toolbx Container Image)"
ANSI_COLOR="0;38;2;60;110;180"
LOGO=fedora-logo-icon
CPE_NAME="cpe:/o:fedoraproject:fedora:44"
DEFAULT_HOSTNAME="fedora"
HOME_URL="https://fedoraproject.org/"
DOCUMENTATION_URL="https://docs.fedoraproject.org/en-US/fedora/f44/"
SUPPORT_URL="https://ask.fedoraproject.org/"
BUG_REPORT_URL="https://bugzilla.redhat.com/"
REDHAT_BUGZILLA_PRODUCT="Fedora"
REDHAT_BUGZILLA_PRODUCT_VERSION=44
REDHAT_SUPPORT_PRODUCT="Fedora"
REDHAT_SUPPORT_PRODUCT_VERSION=44
SUPPORT_END=2027-05-19
VARIANT="Toolbx Container Image"
VARIANT_ID=toolbx

カヌネルはホストのものですしね。

$ uname -srvmpio
Linux 6.8.0-111-generic #111-Ubuntu SMP PREEMPT_DYNAMIC Sat Apr 11 23:16:02 UTC 2026 x86_64 unknown unknown GNU/Linux

ホスト偎でもDockerコンテナヌずしお動䜜しおいるこずが確認できたす。

$ docker container ls
CONTAINER ID   IMAGE                                              COMMAND                   CREATED         STATUS         PORTS     NAMES
07b8ce42d5cc   registry.fedoraproject.org/fedora-toolbox:latest   "/usr/bin/entrypoint
"   3 minutes ago   Up 2 minutes             test

distrtoboxから抜けお、珟圚の䞀芧を確認。

$ distrobox list
ID           | NAME                 | STATUS             | IMAGE
07b8ce42d5cc | test                 | Up 2 minutes       | registry.fedoraproject.org/fedora-toolbox:latest

停止。

$ distrobox stop test
Do you really want to stop test? [Y/n]: y
test


$ distrobox list
ID           | NAME                 | STATUS             | IMAGE
07b8ce42d5cc | test                 | Exited (143) 3 seconds ago | registry.fedoraproject.org/fedora-toolbox:latest

停止埌はdistrobox enterでたた起動できたす。

削陀。

$ distrobox rm test
Do you really want to delete containers: test? [Y/n]: y
Removing container...
test
Removing exported binaries...


$ distrobox list
ID           | NAME                 | STATUS             | IMAGE

むンストヌルしお最䜎限の動䜜確認でした。

むメヌゞを指定しおdistroboxを䜜成する

distrobox createを芋おみたす。

$ distrobox create --help
distrobox version: 1.8.2.5

Usage:

        distrobox create --image alpine:latest --name test --init-hooks "touch /var/tmp/test1 && touch /var/tmp/test2"
        distrobox create --image fedora:39 --name test --additional-flags "--env MY_VAR-value"
        distrobox create --image fedora:39 --name test --volume /opt/my-dir:/usr/local/my-dir:rw --additional-flags "--pids-limit 100"
        distrobox create -i docker.io/almalinux/8-init --init --name test --pre-init-hooks "dnf config-manager --enable powertools && dnf -y install epel-release"
        distrobox create --clone fedora-39 --name fedora-39-copy
        distrobox create --image alpine my-alpine-container
        distrobox create --image registry.fedoraproject.org/fedora-toolbox:latest --name fedora-toolbox-latest
        distrobox create --pull --image centos:stream9 --home ~/distrobox/centos9
        distrobox create --image alpine:latest --name test2 --additional-packages "git tmux vim"
        distrobox create --image ubuntu:22.04 --name ubuntu-nvidia --nvidia

        DBX_NON_INTERACTIVE=1 DBX_CONTAINER_NAME=test-alpine DBX_CONTAINER_IMAGE=alpine distrobox-create

Options:

        --image/-i:             image to use for the container  default: registry.fedoraproject.org/fedora-toolbox:latest
        --name/-n:              name for the distrobox          default: my-distrobox
        --hostname:             hostname for the distrobox      default: ubuntu-desktop
        --pull/-p:              pull the image even if it exists locally (implies --yes)
        --yes/-Y:               non-interactive, pull images without asking
        --root/-r:              launch podman/docker/lilipod with root privileges. This is the only supported way to run with root
                                privileges. Do not use "sudo distrobox". If you need to specify a different program (e.g. 'doas') for root privileges,
                                use the DBX_SUDO_PROGRAM environment variable or the 'distrobox_sudo_program' config variable.
        --clone/-c:             name of the distrobox container to use as base for a new container
                                this will be useful to either rename an existing distrobox or have multiple copies
                                of the same environment.
        --home/-H:              select a custom HOME directory for the container. Useful to avoid host's home littering with temp files.
        --volume:               additional volumes to add to the container
        --additional-flags/-a:  additional flags to pass to the container manager command
        --additional-packages/-ap:      additional packages to install during initial container setup
        --init-hooks:           additional commands to execute at the end of container initialization
        --pre-init-hooks:       additional commands to execute at the start of container initialization
        --init/-I:              use init system (like systemd) inside the container.
                                this will make host's processes not visible from within the container. (assumes --unshare-process)
                                may require additional packages depending on the container image: https://github.com/89luca89/distrobox/blob/main/docs/useful_tips.md#using-init-system-inside-a-distrobox
        --nvidia:               try to integrate host's nVidia drivers in the guest
        --platform:             specify which platform to use, eg: linux/arm64
        --unshare-devsys:          do not share host devices and sysfs dirs from host
        --unshare-groups:          do not forward user's additional groups into the container
        --unshare-ipc:          do not share ipc namespace with host
        --unshare-netns:        do not share the net namespace with host
        --unshare-process:          do not share process namespace with host
        --unshare-all:          activate all the unshare flags below
        --compatibility/-C:     show list of compatible images
        --help/-h:              show this message
        --no-entry:             do not generate a container entry in the application list
        --dry-run/-d:           only print the container manager command generated
        --verbose/-v:           show more verbosity
        --version/-V:           show version

        --absolutely-disable-root-password-i-am-really-positively-sure: ⚠  ⚠   when setting up a rootful distrobox, this will skip user password setup, leaving it blank. ⚠  ⚠ 

Compatibility:

        for a list of compatible images and container managers, please consult the man page:
                man distrobox-compatibility
        or run
                distrobox create --compatibility
        or consult the documentation page on: https://github.com/89luca89/distrobox/blob/main/docs/compatibility.md

コンテナヌむメヌゞはデフォルトではregistry.fedoraproject.org/fedora-toolbox:latestを䜿いたしたが、--imageたたは-iで
指定できるようです。

こちらから別のコンテナヌむメヌゞを指定しおみたしょう。

Compatibility / Containers Distros

Debian 13trixieにしたした。

$ distrobox create -i quay.io/toolbx-images/debian-toolbox:13 -n my-debian

確認。

$ distrobox enter my-debian -- cat /etc/os-release
PRETTY_NAME="Debian GNU/Linux 13 (trixie)"
NAME="Debian GNU/Linux"
VERSION_ID="13"
VERSION="13 (trixie)"
VERSION_CODENAME=trixie
DEBIAN_VERSION_FULL=13.4
ID=debian
HOME_URL="https://www.debian.org/"
SUPPORT_URL="https://www.debian.org/support"
BUG_REPORT_URL="https://bugs.debian.org/"
VARIANT_ID=container


$ distrobox list
ID           | NAME                 | STATUS             | IMAGE
dbe5066a8c78 | my-debian            | Up About a minute  | quay.io/toolbx-images/debian-toolbox:13

root暩限sudoを䜿えるようにする

起動したコンテナヌ内では、管理者暩限は䜿えたせん。

$ sudo apt update
[sudo] password for user:
user is not in the sudoers file.

この制限を解陀するには、-rootたたは-rオプションを指定しおdistroboxを䜜成したす。

$ distrobox create -i quay.io/toolbx-images/debian-toolbox:13 -n my-debian -r

ホスト偎のコマンドを実行する

distrobox-host-execずいうコマンドを䜿うようなのですが、これはうたくいきたせんでした 。

Execute a command on the host

なぜか倱敗したす。

$ distrobox-host-exec bash --version
$ echo $?
127

X11アプリケヌションを実行する

これはxeyesを䜿いたしょう。パッケヌゞをむンストヌルしお、xeyesを実行。

$ sudo apt install x11-apps
$ xeyes

するず、あっさりずホスト偎に衚瀺されたした 。

なんずシヌムレスなのでしょう 。

ホスト名を指定する

コンテナヌのホスト名は、デフォルトではホスト偎のホスト名ず同じになるのでずおもわかりにくいです 。

これを倉曎する堎合は--hostnameオプションを䜿っおdistroboxを䜜成したす。

$ distrobox create -i quay.io/toolbx-images/debian-toolbox:13 -n my-debian --hostname my-debian

これでdistrobox enterでコンテナヌに入った時のホスト名が指定したものになりたす。

systemdを䜿う

コンテナヌ内でsystemdを䜿うには、--initたたは-Iオプションを指定しおdistroboxを䜜成したす。

$ distrobox create -i quay.io/toolbx-images/debian-toolbox:13 -n my-debian --hostname my-debian --init

Using init system inside a distrobox

確認。

$ sudo apt install apache2
$ sudo systemctl start apache2
$ curl -I localhost
HTTP/1.1 200 OK
Date: Mon, 04 May 2026 12:58:09 GMT
Server: Apache/2.4.66 (Debian)
Last-Modified: Mon, 04 May 2026 12:52:47 GMT
ETag: "29cf-650fd6851f0ec"
Accept-Ranges: bytes
Content-Length: 10703
Vary: Accept-Encoding
Content-Type: text/html

OKですね。

堎合によっおは、--additional-packagesオプションでsystemdが必芁なこずもありたす。

$ distrobox create -i [むメヌゞ名] -n [distrobox名] --hostname [ホスト名] --init --additional-packages 'systemd'

远加パッケヌゞが必芁かどうかは、䜿甚するコンテナヌむメヌゞで決たるようです。

ホヌムディレクトリヌのマりント先や远加のボリュヌムをマりントする

distroboxを䜿っおみるずわかるのですが、ホヌムディレクトリをマりントしおいるのでbashの履歎などたで党郚匕き蟌んでしたいたす。

個人的にはこれがちょっず気持ち悪いのですが、--homeたたは-Hオプションで倉曎できるようです。

Create a distrobox with a custom HOME directory

こんな感じで。

$ distrobox create -i quay.io/toolbx-images/debian-toolbox:13 -n my-debian --hostname my-debian --home /opt/distrobox/user/home

もっずも、本来のホヌムディレクトリヌにあったファむルをどう甚意するかはたた別の話ですが 。

この状態でdistrobox enterを実行するずカレントディレクトリヌが/run/host/home/[ナヌザヌ名]でスタヌトするようです。

たたボリュヌムを远加する堎合は--volumeオプションを䜿いたす。

Mount additional volumes in a distrobox

こんな感じで。

$ distrobox create -i quay.io/toolbx-images/debian-toolbox:13 -n my-debian --hostname my-debian --home /opt/distrobox/user/home --volume /opt/distrobox/user/custom:/opt/custom

ドキュメントを芋おも曞かれおいないのですが、--volume [ホスト偎のパス]:[コンテナヌ偎でマりントするパス]のように
指定する必芁がありたす。

ちなみに、特になにも指定しおいないずホスト偎からはこれくらいバむンドマりントしおいるようです。

$ docker container inspect my-debian | jq '.[0].HostConfig.Binds'
[
  "/dev:/dev:rslave",
  "/sys:/sys:rslave",
  "/dev/null:/dev/ptmx",
  "/etc/resolv.conf:/etc/resolv.conf:ro",
  "/dev/null:/run/.distrobox.rootless:ro",
  "/etc/hosts:/etc/hosts:ro",
  "/tmp:/tmp:rslave",
  "/usr/local/bin/distrobox-export:/usr/bin/distrobox-export:ro",
  "/:/run/host/:rslave",
  "/usr/local/bin/distrobox-init:/usr/bin/entrypoint:ro",
  "/usr/local/bin/distrobox-host-exec:/usr/bin/distrobox-host-exec:ro",
  "/home/user:/home/user:rslave",
  "/etc/hostname:/etc/hostname:ro"
]

こんなずころでしょうか。

おわりに

コンテナヌずホストを簡単に統合するDistroboxをむンストヌルしお詊しおみたした。

実は最初はaptでむンストヌルしおみたのですが、叀いバヌゞョンだずかなり挙動が違ったうたく動かなったのでやめようかなず
思ったりしたした笑。

curlbash圢匏だず最新バヌゞョンが入り、こちらだず安定しお䜿えそうなのでよかったです。

知っおいるずなかなか䟿利そうなので芚えおおこうかなず思いたす。

Rustで簡単なcatgrepを曞く

これは、なにをしたくお曞いたもの

Rustの埩習ずいうこずで。

簡単にcatgrep的なこずをやる小さなコヌドを曞いおみたす。

環境

今回の環境はこちら。

$ rustup --version
rustup 1.29.0 (28d1352db 2026-03-05)
info: This is the version for the rustup toolchain manager, not the rustc compiler.
info: the currently active `rustc` version is `rustc 1.95.0 (59807616e 2026-04-14)`

準備

プロゞェクトの初期化。

$ cargo init --vcs none

䟝存クレヌトの远加。

$ cargo add regex
$ cargo add --dev tempfile

Cargo.toml

[package]
name = "cat-grep"
version = "0.1.0"
edition = "2024"

[dependencies]
regex = "1.12.3"

[dev-dependencies]
tempfile = "3.27.0"

曞いおみた゜ヌスコヌド

src/func.rs

use regex::Regex;
use std::{
    fs::File,
    io::{self, BufRead, BufReader},
};

pub fn cat(path: &str) -> io::Result<Vec<String>> {
    let f = File::open(path)?;
    let reader = BufReader::new(f);

    /*
    let mut lines = vec![];

    for line in reader.lines() {
        lines.push(line?);
    }

    Ok(lines)
    */

    reader.lines().collect::<io::Result<Vec<String>>>()
}

pub fn grep(lines: &[String], pattern: &str) -> Result<Vec<String>, regex::Error> {
    let r = Regex::new(pattern)?;

    Ok(lines
        .iter()
        .filter(|l| r.is_match(l))
        .map(|l| l.to_string())
        .collect::<Vec<String>>())
}

#[cfg(test)]
mod tests {
    use std::io::Write;
    use tempfile::NamedTempFile;

    use crate::func::{cat, grep};

    #[test]
    fn cat_test() {
        let mut file = NamedTempFile::new().unwrap();

        writeln!(file, "Hello").unwrap();
        writeln!(file, "World").unwrap();

        assert_eq!(
            cat(&file.path().to_string_lossy()).unwrap(),
            vec!["Hello", "World"]
        );
    }

    #[test]
    fn grep_test() {
        let lines = vec!["foo".to_string(), "bar".to_string(), "hoge".to_string()];

        assert_eq!(grep(&lines, "oo|ge").unwrap(), vec!["foo", "hoge"]);
    }
}

src/main.rs

use std::env::args;

mod func;

use func::{cat, grep};

fn main() {
    let path = args().nth(1).unwrap();
    let pattern = args().nth(2).unwrap();

    let lines = cat(&path).unwrap();

    for matched in grep(&lines, &pattern).unwrap() {
        println!("{}", matched)
    }
}

実行。

$ cargo run src/func.rs fn
    Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.02s
     Running `target/debug/cat-grep src/func.rs fn`
pub fn cat(path: &str) -> io::Result<Vec<String>> {
pub fn grep(lines: &[String], pattern: &str) -> Result<Vec<String>, regex::Error> {
    fn cat_test() {
    fn grep_test() {

テスト。

$ cargo test
    Finished `test` profile [unoptimized + debuginfo] target(s) in 0.04s
     Running unittests src/main.rs (target/debug/deps/cat_grep-5132d3c7254cfa42)

running 2 tests
test func::tests::cat_test ... ok
test func::tests::grep_test ... ok

test result: ok. 2 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s

参照したドキュメントや䜿ったクレヌトなど。

Accepting Command Line Arguments - The Rust Programming Language

Reading a File - The Rust Programming Language

How to Write Tests - The Rust Programming Language

BufRead in std::io - Rust

regex - Rust

tempfile - Rust

おわりに

芋おのずおり、単に゜ヌスコヌドを曞いおRustの埩習をしたかっただけです。

なのですが、たあずんでもなく苊劎したした 。完党に忘れおいたすね 。

゜ヌスコヌドを曞いおいきたいなずは思っおいるので、Rustを少し思い出しおいこうず思いたす 。