Complex module Dependency

This is a no_std with custom core crate I am trying to build it is similar to this but more up to date and for my purpose My project can be followed here GitHub - lquinn2015/cs3240 at kore_io which is the git hash I used to make the below. This work is independent of that class I am just following along the online portion myself

I have the following crate structure. I am currently trying to add kore_io which is why its read. It use to be core_io but that project was deprecated and unusable

Basically I am trying to compile that PI crate which has a uart.rs which is failing to compile because kore_io seems to not be exporting any symbols. See below essentially I am hoping that "use shim::io" will expose the io namespace and I can resolve io::Result to my kore_io module.

use shim::io;
mod uart_io {
    use super::io;
    use super::MiniUart;
    use shim::ioerr;

    impl io::Read for MiniUart {   // ERROR Result not found in crate `io`
        fn read(&mut self, buf: &mut [u8]) -> io::Result<usize> {
            if self.wait_for_byte().is_err() {
                return ioerr!(TimedOut, "out of time");
            }
            let mut i = 0;
            while self.has_byte() && i < buf.len() {
                buf[i] = self.read_byte();
                i += 1;
            }
            Ok(i)
        }
    }
}

So the issue I thought could be in 2 places

  1. Kore_io is not export the symbols (I think its here)
  2. Shim is not exporting the io namespace correctly.

Shim is pretty short as it just includes kore_io as io. The lib.rs which just selects which module and looks like

//lib/shim/lib.rs

#![cfg_attr(feature = "no_std", no_std)]
#![feature(never_type)]
#![allow(unused_imports)]

#[cfg(feature = "alloc")]
extern crate alloc;

cfg_if::cfg_if! {
    if #[cfg(feature = "no_std")] {
        mod no_std;
        pub use self::no_std::*;
    } else {
        mod std;
        pub use self::std::*;
    }
}

#[macro_use]
pub mod macros;

#[cfg(test)]
mod tests;

I have used cargo expand --features no_std and get the expect result similar too

mod no_std {
    pub use kore_io as io;
} 
pub use self::no_std::*;

Thus I think my error must be in the kore_io crate I have but I thought I was doing everything correctly. I'll focus on the Result getting exported correctly because I think the issue is the probably the same everywhere.

In kore_io i have a lib.rs top which does the following

#![no_std]  //  kore_io/src/lib.rs
#![feature(error_in_core)]
#![cfg(feature = "alloc")]
#![feature(allocator_api)]
#[cfg(feature = "alloc")]
extern crate alloc;

pub mod io;

The io module beginning is like this.

use core::cmp;   // kore_io/src/io/mod.rs
use core::fmt;
use core::iter::Iterator;
use core::option::Option::{self, None, Some};
use core::result;
use core::result::Result::{Err, Ok};

pub use self::cursor::Cursor;
pub use self::error::{Error, ErrorKind, Result};

mod cursor;
mod error;
mod impls;
pub mod prelude;

const DEFAULT_BUF_SIZE: usize = 64 * 1024;
...

As you can see it pulls the Result structure into the namespace of self::io on line 9. The definition is taken from my error.rs which looks like

// lib/kore_io/src/io/error.rs
use core::fmt;
use core::option::Option::{self, None, Some};
use core::result;

pub type Result<T> = core::result::Result<T, Error>;

#[derive(Debug)]
pub struct Error {
    pub kind: ErrorKind,
    pub msg: &'static str,
}
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub enum ErrorKind {
...

But that's where I am lost the compiler isn't finding the Result in shim::io. But I don't know why it didn't follow this path like I just did. Am I missing some pub verse private module restriction?

shim::io corresponds to kore_io (pub use kore_io as io;), which does not export a Result, correct? kore_io contains the io module which then contains the Result, so the Result type should be at shim::io::io::Result.

1 Like

Okay you are right about that but when i switch to use kore_io::io; I think I found the root issue!! I have my cfg incorrect. I have a ! before it so nothing gets compiled unless alloc is on ... that took so long to find I am marking you as the solution thank you so much

1 Like

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.