Dolphin
Dolphin

Reputation: 38759

what should I do if the project name contains hyphen in rust

I am a newbie of rust, when I tried to write a rust web api, but the project contains hyphen so I could not use it, if the project name like diesel_demo , I could use it like this:

use diesel_demo::schema::posts::dsl::*;

but if my project name like diesel-demo, what should I do to use it? I can not change my project name now with hyphen reddwarf-music. I read the docs and tell me the cargo will trans the - to _ by default, so I am use it like this:

use reddwarf_music::schema::posts::dsl::*;

but shows error like this:

~/Documents/GitHub/reddwarf-music on  develop! ⌚ 17:56:51
$ cargo build                                                                                                                                  ‹ruby-2.7.2›
   Compiling hello-rocket v0.1.0 (/Users/dolphin/Documents/GitHub/reddwarf-music)
error[E0433]: failed to resolve: use of undeclared crate or module `reddwarf_music`
 --> src/biz/music/music.rs:1:5
  |
1 | use reddwarf_music::schema::posts::dsl::*;
  |     ^^^^^^^^^^^^^^ use of undeclared crate or module `reddwarf_music`

what should I do handle the - in rust? By the way the scheme is generate in my local src, not from third package. This is my project structure:

enter image description here

this is my Cargo.toml:

[package]
name = "reddwarf_music"
version = "0.1.0"
edition = "2018"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
rocket = { version = "0.5.0-rc.1", features = ["json"] }
rand = "0.8.4"
serde = { version = "1.0.64", features = ["derive"] }
serde_json = "1.0.64"
reqwest = "0.11.4"

# database
diesel = { version = "1.4.4", features = ["postgres"] }
dotenv = "0.15.0"

Upvotes: 0

Views: 896

Answers (1)

orlp
orlp

Reputation: 117701

Within a crate you don't use the crates name with use, rather, you refer to the crate itself using the identifier crate.

So inside your crate "reddwarf-music", when you want to use an internal symbol, instead of writing

use reddwarf_music::schema::posts::dsl::*;

you write

use crate::schema::posts::dsl::*;

Upvotes: 4

Related Questions