В одной из тем был накидан такой исходник. Решил его разбить на несколько файлов.
Получилось два файла: semver.rs и main.rs. Тупо вынес всю логику semver в отдельный файл, ничего не меняя.
Добавил в начало main.rs mod semver;
. Запускаю:
Compiling vers v0.1.0 (file:///home/deterok/data/projects/vers)
semver.rs:63:6: 63:23 error: failed to resolve. Use of undeclared type or module `std::fmt`
semver.rs:63 impl std::fmt::Display for Version {
^~~~~~~~~~~~~~~~~
semver.rs:63:6: 63:23 error: use of undeclared trait name `std::fmt::Display`
semver.rs:63 impl std::fmt::Display for Version {
^~~~~~~~~~~~~~~~~
semver.rs:103:6: 103:23 error: failed to resolve. Use of undeclared type or module `std::str`
semver.rs:103 impl std::str::FromStr for Version {
^~~~~~~~~~~~~~~~~
semver.rs:103:6: 103:23 error: use of undeclared trait name `std::str::FromStr`
semver.rs:103 impl std::str::FromStr for Version {
^~~~~~~~~~~~~~~~~
semver.rs:131:6: 131:23 error: failed to resolve. Use of undeclared type or module `std::fmt`
semver.rs:131 impl std::fmt::Display for ParseVersionError {
^~~~~~~~~~~~~~~~~
semver.rs:131:6: 131:23 error: use of undeclared trait name `std::fmt::Display`
semver.rs:131 impl std::fmt::Display for ParseVersionError {
^~~~~~~~~~~~~~~~~
main.rs:8:23: 8:30 error: use of undeclared type name `Version`
main.rs:8 fn check_version(v1: &Version, v2: &Version) {
^~~~~~~
main.rs:8:37: 8:44 error: use of undeclared type name `Version`
main.rs:8 fn check_version(v1: &Version, v2: &Version) {
^~~~~~~
main.rs:17:18: 17:37 error: failed to resolve. Use of undeclared type or module `VersionBuilder`
main.rs:17 let mut v1 = VersionBuilder::new();
^~~~~~~~~~~~~~~~~~~
main.rs:17:18: 17:37 error: unresolved name `VersionBuilder::new`
main.rs:17 let mut v1 = VersionBuilder::new();
^~~~~~~~~~~~~~~~~~~
main.rs:22:14: 22:21 error: `Version` does not name a structure
main.rs:22 let v2 = Version{major: 1, minor: 2, patch:5}.inc_minor();
^~~~~~~
main.rs:27:30: 27:37 error: use of undeclared type name `Version`
main.rs:27 match v2.value().parse::<Version>() {
^~~~~~~
error: aborting due to 12 previous errors
Could not compile `vers`.
Ага! Надо добавить use semver::*;
в main.rs. Собираю:
cargo run
Compiling vers v0.1.0 (file:///home/deterok/data/projects/vers)
semver.rs:63:6: 63:23 error: failed to resolve. Use of undeclared type or module `std::fmt`
semver.rs:63 impl std::fmt::Display for Version {
^~~~~~~~~~~~~~~~~
semver.rs:63:6: 63:23 error: use of undeclared trait name `std::fmt::Display`
semver.rs:63 impl std::fmt::Display for Version {
^~~~~~~~~~~~~~~~~
semver.rs:103:6: 103:23 error: failed to resolve. Use of undeclared type or module `std::str`
semver.rs:103 impl std::str::FromStr for Version {
^~~~~~~~~~~~~~~~~
semver.rs:103:6: 103:23 error: use of undeclared trait name `std::str::FromStr`
semver.rs:103 impl std::str::FromStr for Version {
^~~~~~~~~~~~~~~~~
semver.rs:131:6: 131:23 error: failed to resolve. Use of undeclared type or module `std::fmt`
semver.rs:131 impl std::fmt::Display for ParseVersionError {
^~~~~~~~~~~~~~~~~
semver.rs:131:6: 131:23 error: use of undeclared trait name `std::fmt::Display`
semver.rs:131 impl std::fmt::Display for ParseVersionError {
^~~~~~~~~~~~~~~~~
main.rs:9:23: 9:30 error: use of undeclared type name `Version`
main.rs:9 fn check_version(v1: &Version, v2: &Version) {
^~~~~~~
main.rs:9:37: 9:44 error: use of undeclared type name `Version`
main.rs:9 fn check_version(v1: &Version, v2: &Version) {
^~~~~~~
main.rs:18:18: 18:37 error: failed to resolve. Use of undeclared type or module `VersionBuilder`
main.rs:18 let mut v1 = VersionBuilder::new();
^~~~~~~~~~~~~~~~~~~
main.rs:18:18: 18:37 error: unresolved name `VersionBuilder::new`
main.rs:18 let mut v1 = VersionBuilder::new();
^~~~~~~~~~~~~~~~~~~
main.rs:23:14: 23:21 error: `Version` does not name a structure
main.rs:23 let v2 = Version{major: 1, minor: 2, patch:5}.inc_minor();
^~~~~~~
main.rs:28:30: 28:37 error: use of undeclared type name `Version`
main.rs:28 match v2.value().parse::<Version>() {
^~~~~~~
error: aborting due to 12 previous errors
Could not compile `vers`.
Как правильно это сделать?