rust-crates

How do I make an Rust item public within a crate, but private outside it?

£可爱£侵袭症+ 提交于 2019-11-30 03:01:40
I have a crate that has lots of code, so I've split it into multiple files/modules. However, some modules have internal unsafe stuff (e.g. raw pointers) that I need to make public to the different modules, but I don't want to expose to users of my crate. How can I do that? The only way I can think of is to actually have my crate just be one big module, but then there's no way to split it into different files, other than this solution which seems a bit hacky. Normally when I come up against a real world problem that the simple examples in the Rust docs don't adequately explain I just copy a

How do I make an Rust item public within a crate, but private outside it?

给你一囗甜甜゛ 提交于 2019-11-29 00:32:23
问题 I have a crate that has lots of code, so I've split it into multiple files/modules. However, some modules have internal unsafe stuff (e.g. raw pointers) that I need to make public to the different modules, but I don't want to expose to users of my crate. How can I do that? The only way I can think of is to actually have my crate just be one big module, but then there's no way to split it into different files, other than this solution which seems a bit hacky. Normally when I come up against a

How to use a local unpublished crate?

 ̄綄美尐妖づ 提交于 2019-11-27 11:45:10
I've made a library: cargo new my_lib and I want to use that library in a different program: cargo new my_program --bin extern crate my_lib; fn main { println!("Hello, World!"); } what do I need to do to get this to work? They aren't in the same project folder. . ├── my_lib └── my_program Hopefully this makes sense. I thought I'd be able to override the path as per the Cargo guide , but it states You cannot use this feature to tell Cargo how to find local unpublished crates. This is when using the latest stable version of Rust (1.3). Add a dependency section to your executable's Cargo.toml and