# `chromium::import!` Macro

After adding `:my_rust_lib` to GN `deps`, we still need to learn how to import
and use `my_rust_lib` from `my_rust_lib_unittest.rs`. We haven't provided an
explicit `crate_name` for `my_rust_lib` so its crate name is computed based on
the full target path and name. Fortunately we can avoid working with such an
unwieldy name by using the `chromium::import!` macro from the
automatically-imported `chromium` crate:

```rust,ignore
chromium::import! {
    "//ui/base:my_rust_lib";
}

use my_rust_lib::my_function_under_test;
```

Under the covers the macro expands to something similar to:

```rust,ignore
extern crate ui_sbase_cmy_urust_ulib as my_rust_lib;

use my_rust_lib::my_function_under_test;
```

More information can be found in [the doc comment][0] of the `chromium::import`
macro.

<details>

`rust_static_library` supports specifying an explicit name via `crate_name`
property, but doing this is discouraged. And it is discouraged because the crate
name has to be globally unique. crates.io guarantees uniqueness of its crate
names so `cargo_crate` GN targets (generated by the `gnrt` tool covered in a
later section) use short crate names.

</details>

[0]: https://source.chromium.org/chromium/chromium/src/+/main:build/rust/chromium_prelude/chromium_prelude.rs?q=f:chromium_prelude.rs%20pub.use.*%5Cbimport%5Cb;%20-f:third_party&ss=chromium%2Fchromium%2Fsrc
