I have created a library crate and all code is in lib.rs. Now lib.rs is getting to be too large, so I want to move code out to other files (not other folders). But when I do, the other files will not compile because the structs, methods, and so forth in those files are marked as unused. Here is the simplest example I could come up with to illustrate this:
lib.rs:
pub struct S1 {}
impl S1 {
pub fn new() -> S1 {
S1 {}
}
}#[cfg(test)]
mod tests {
#[test]
fn it_works() {
assert_eq!(2 + 2, 4);
}
}
This builds and the test runs.
Now I move the S1 related code to s1.rs in the same folder:
s1.rs:
pub struct S1 {}
impl S1 {
pub fn new() -> S1 {
S1 {}
}
}#[cfg(test)]
mod tests {
#[test]
fn it_works() {
assert_eq!(2 + 2, 4);
}
}
and lib.rs:
mod s1;
Now if I try to build, the compiler complains that 'S1' is never constructed, and 'new' is never used. The test still executes, however.
Is there something I can do, other than turning off the dead_code warning, that will allow me to compile s1.rs?