Info
This post is auto-generated from RSS feed The Rust Programming Language Forum - Latest topics. Source: RUST noob.. questions
So I am trying to create some mixed C & RUST examples
I found a crc32 - in rust example, and I am trying to create my own 'crate' as a learning exersize, and some things are not making sense. Hence my questions.
I am familiar with the process for C static libraries, and I am trying to replicate that. It is my basic understanding that a "crate" - generally creates either (1) a static library, or (2) a dynamic (.so, or .dll) file that is used by a larger application or library. If one views the organization as branches, twigs and leaves - i have a directory full of leaves - i do not see an example of this.
I desire to keep the content of the library/create "opaque" and I do not wish to expose the implementation. However it seems the rust language does not agree with this approach. Instead, rust (cargo?) seems to demand the source to every create be present and the crate must be visible.. Grr....
**QUESTION #1 ** Why is this a requirement? If my goal is "opaque" APIs how does that help?
QUESTION #2 Related: How can I create the equal to a C language header file that exposes the API, structures and enumerations but NOT the implementation of the crate (that I want to keep opaque)
QUESTION #3 How can I have a dozen or so separate .RS files in my crate static library. - cargo only compiles the one source file. Why is this?
const CRC32_TABLE: [u32; 256] = [ ... long list of numbers ...];
/* Then: */
fn crc32_rust( data: &[u8]) -> u32 {
...
for byte in data {
.. stuff that references CRC32_TABLE[]
}
}
** Question #4 - ** This example does not pass a length or count of bytes in the data array, is the length passed as a hidden variable, or is an RUST array a more complex structure that contains both a length and the data?
** Question #5 - ** When I compile this - I see "warning constant CRC32_TABLE
is never use."
But it is - it is used in the function 'crc32_rust()' - but I suspect it is not used for the reasons of the next question.
** Question #6 - ** Cargo also says: "function crc32_rust' is never used
How do I mark a function as: "this is a public function that will be used by external clients of this crate? I'll have several hundred of these so I'd like to better understand this process.
This is in effect a static library - so there is no, and will be no "main" function that will ever call this function from within this library. Thus, yes, I would think that because "crc32_rust()" is not used - it stands to reason that CRC32_TABLE would then also be not used. But that is not what I am trying to accomplish.
But - my example and question still holds for other reasons.
Say for example I have a large lookup table that is in a library. An example might be (A) a LOGO BITMAP image to display on a screen, or (B) a lookup table of floating point numbers for a sensor, (C) a data structure in a "BoardSupport" Package that represents the available UARTS on the embedded platform/board. The library might provide for example a "find_uart_by_name" function that traverses the array of data structures to find the specified UART. Each board would have its own 'board-support-package' create.
QUESTION #7 - How do I mark a data variable, or function as "this is a used thing" - it is not an unused thing and it must remain in the final static library that is being generated.
2 posts - 2 participants
🏷️ rust_feed