These are chat archives for rust-lang/rust

25th
Aug 2018
Tarık Binar
@ttarikbnr
Aug 25 2018 17:09
Hi, i have two rust project. Project A is a library and generates dll. Other one is a executable. I need to link the dll. Is there any complete example importing dll in linking time( Or is it possible?). Not in runtime.
Tarık Binar
@ttarikbnr
Aug 25 2018 17:20
i get error LNK2019: unresolved external symbol error.

minimal example
Project A

#[no_mangle]
pub extern "C" fn create_future() -> (){
    println!("Called");
}

Project B
main.rs

#[link(name = "plugin")]
extern "C"{
    fn create_future() -> ();
}
Fantasized
@Fantasized
Aug 25 2018 17:56
newbie question, Can't I specialize a generic type? like
struct Point<T> {
    x: T,
    y: T,
}

struct Point<f32> {
}
Fantasized
@Fantasized
Aug 25 2018 18:04
another question, if I instantiated type Point like Point { x:5, y:6}, what is the type of T here ? i8 or i16... how can I figure it out?
Lyle Mantooth
@IslandUsurper
Aug 25 2018 18:28
@Fantasized, you can't declare a new struct with a specialized type. But you can impl FooTrait for Point<f32> {}
For the other question, if the compiler can figure it out from context (by using x and y elsewhere as specific types), then that will work. If not, you'd have to decide what they should be: Point { x: 5i8, y: 6i8 }
Or when you assign it: let point: Point<i16> = Point { x: 5, y: 6 };
Joshua Barretto
@zesterer
Aug 25 2018 19:43
@ttarikbnr I had to use #[linkage = "external"] https://github.com/tupai-os/kernel/blob/master/src/main.rs#L66
Vitaly
@Virtuos86
Aug 25 2018 20:38

another question, if I instantiated type Point like Point { x:5, y:6}, what is the type of T here ? i8 or i16... how can I figure it out?

Use generic:

#[derive(Debug)]
struct Point<T> {
    x: T,
    y: T,
}

fn main() {
    println!("{:?}", Point { x: 0_i8, y: 0 });
    println!("{:?}", Point { x: 0_i16, y: 0 });
    println!("{:?}", Point { x: 0_isize,  y: 0 });
}