Cargo Watch로 Rust에서 핫 리로드
Rust 애플리케이션을 개발할 때 때때로 변경, 컴파일 및 실행 주기의 시간을 줄여야 할 필요가 있습니다. 조금 복잡하게 들리겠지만 오늘은 매우 간단하고 자동적인 방식으로 작업을 수행하는 도구를 보여드리겠습니다. 이 도구는
cargo watch 라고 하며 백그라운드에서 각 변경 주기의 시간을 줄입니다.카고 워치
Cargo Watch는 프로젝트 변경에 대한 리스너를 생성하고 변경 사항이 발생할 때 Cargo 명령을 실행합니다. 이 기사를 작성할 당시 최신 버전은
8.1.2 입니다.Cargo Watch doc
Github Project
부인 성명
이 튜토리얼에서는 여러분이 Cargo 사용에 익숙하다고 가정합니다.
Cargo is Rust’s build system and package manager. Most Rustaceans use this tool to manage their Rust projects because Cargo handles a lot of tasks for you, such as building your code, downloading the libraries your code depends on, and building those libraries
화물here에 대한 자세한 내용을 읽을 수 있습니다.
주기 변경

새 프로젝트를 만드는 것으로 시작합니다. 예를 들어
cargo-watch-example라고 하겠습니다.cargo new cargo-watch-example
프로젝트가 올바르게 생성된 경우 터미널에 다음 메시지가 표시됩니다.
Created binary (application) 화물 시계 예시packageCargo.toml 파일에 다음 행을 추가하십시오.
cargo-watch = "8.1.2"cargo.toml
[package]
name = "cargo-watch-example"
version = "0.1.0"
edition = "2022"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
cargo-watch = "8.1.2"
카고 워치 설치
cargo install cargo-watch
프로젝트 실행 및 변경 사항 관찰
cargo watch -x run
작업 디렉토리에서만 변경 사항을 수신하려면 -w 옵션을 추가하여 변경 사항을 수신하려는 파일 또는 디렉토리를 지정하십시오.
charge watch -w src -x run
데모

앞의 예는 전체 프로젝트 또는 특정 디렉터리의 변경 사항을 관찰하는 가장 간단한 구성이었지만 훨씬 더 많은 작업을 수행할 수 있습니다. 다음은 도움말 사본입니다.
USAGE:
    cargo watch [FLAGS] [OPTIONS]
FLAGS:
    -c, --clear              Clear the screen before each run
    -h, --help               Display this message
        --ignore-nothing     Ignore nothing, not even target/ and .git/
        --debug              Show debug output
        --why                Show paths that changed
    -q, --quiet              Suppress output from cargo-watch itself
        --no-gitignore       Don’t use .gitignore files
        --no-ignore          Don’t use .ignore files
        --no-restart         Don’t restart command while it’s still running
        --poll               Force use of polling for file changes
        --postpone           Postpone first run until a file changes
    -V, --version            Display version information
        --watch-when-idle    Ignore events emitted while the commands run.
                             Will become default behaviour in 8.0.
OPTIONS:
    -x, --exec <cmd>...
            Cargo command(s) to execute on changes [default: check]
    -s, --shell <cmd>...           Shell command(s) to execute on changes
    -d, --delay <delay>
            File updates debounce delay in seconds [default: 0.5]
        --features <features>
            List of features passed to cargo invocations
    -i, --ignore <pattern>...      Ignore a glob/gitignore-style pattern
    -B <rust-backtrace>
            Inject RUST_BACKTRACE=VALUE (generally you want to set it to 1)
            into the environment
        --use-shell <use-shell>
            Use a different shell. E.g. --use-shell=bash. On Windows, try
            --use-shell=powershell, which will become the default in 8.0.
    -w, --watch <watch>...
            Watch specific file(s) or folder(s) [default: .]
    -C, --workdir <workdir>
            Change working directory before running command [default: crate root]
ARGS:
    <cmd:trail>...    Full command to run. -x and -s will be ignored!
Cargo commands (-x) are always executed before shell commands (-s). You can use
the `-- command` style instead, note you'll need to use full commands, it won't
prefix `cargo` for you.
By default, your entire project is watched, except for the target/ and .git/
folders, and your .ignore and .gitignore files are used to filter paths.
On Windows, patterns given to -i have forward slashes (/) automatically
converted to backward ones (\) to ease command portability.
다음 자습서에서는
Docker Containers를 사용하여 이 예제를 적용합니다 😎
                Reference
이 문제에 관하여(Cargo Watch로 Rust에서 핫 리로드), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다 https://dev.to/devjorgecastro/hot-reload-in-rust-with-cargo-watch-5bon텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
                                
                                
                                
                                
                                
                                우수한 개발자 콘텐츠 발견에 전념
                                (Collection and Share based on the CC Protocol.)