🦀 rust
use log::debug;
fn main() {
env_logger::init();
debug!(target: "tswc", "inputs {:?}", inputs);
}
`RUST_LOG=tswc cargo run`
`RUST_LOG=trace cargo test -- --nocapture`
use swc_core::ecma::{ast::Ident, visit::VisitMut};
use tracing::debug;
pub struct Whatplatform;
impl VisitMut for Whatplatform {
// Implement necessary visit_mut_* methods for actual custom transform.
// A comprehensive list of possible visitor methods can be found here:
// https://rustdoc.swc.rs/swc_ecma_visit/trait.VisitMut.html
fn visit_mut_ident(&mut self, n: &mut Ident) {
debug!("Values: {:#?}", n);
}
}
marcos
- https://kaisery.github.io/trpl-zh-cn/ch19-06-macros.html?search=hong
- https://blog.logrocket.com/macros-in-rust-a-tutorial-with-examples/
attach codes to function and struct, just like inherit
test single file
cargo test --all no_document_write_valid -- --nocapture
- no_document_write_valid test function name
- nocapture enable print
npm package rust app
https://blog.woubuc.be/post/publishing-rust-binary-on-npm/
看 demo 例子更加实时
brew package rust app / 打包 rust 到 homebrew
https://federicoterzi.com/blog/how-to-publish-your-rust-project-on-homebrew/
create rust lib
create a rust lib package
cargo new --lib <path>
build
cargo fmt
cargo build
找到编译后的可执行文件
in `target/debug/<pkg.name>`
开启某些 `package`
的 `feature`
编译。以便使用只有在这些 `feature`
下才能使用的功能。
// cargo.toml
[dependencies]
swc_common = { version = "0.10.9", features = ["tty-emitter"] }
enable feature
// in cargo.toml
[dependencies]
swc_common = { version = "0.10.9", features = ["tty-emitter"] }
tips
`cargo build --release`
的编译结果执行速度要快于`cargo build`
的编译结果的执行速度
in
`~/.cargo/config`
如果出现其中一个失败,轻尝试切换另外一个,如果都失败了,那么请清空`~/.cargo/config`
内的文件,使用官方缘
use tsinghua
[source.crates-io]
replace-with = 'tuna'
[source.tuna]
registry = "https://mirrors.tuna.tsinghua.edu.cn/git/crates.io-index.git"
use ustc
[source.crates-io]
replace-with = 'ustc'
[source.ustc]
registry = "git://mirrors.ustc.edu.cn/crates.io-index"
一次性代理设置
RUSTUP_DIST_SERVER=https://mirrors.tuna.tsinghua.edu.cn/rustup rustup target add wasm32-unknown-unknown
refs: https://mirrors.tuna.tsinghua.edu.cn/help/rustup/
如果 `clone`
是个 `Option<T>`
。更新内部 `field`
可通过以下方式
if let Some(ref mut c) = clone {
c.enlarge(saved.unwrap().hi, hi);
}