Giter Site home page Giter Site logo

examples-rust's Introduction

examples-rust

Some Rust code examples for discussions.

examples-rust's People

Contributors

kriswuollett avatar

Watchers

 avatar

examples-rust's Issues

Cannot `Send` `*mut c_void`

Tried with and without wrapping in Arc<Mutex<T>>:

% cargo build --release -p kriswuollett_examples_c_callback
   Compiling libc v0.2.147
   Compiling autocfg v1.1.0
   Compiling proc-macro2 v1.0.66
   Compiling unicode-ident v1.0.11
   Compiling serde v1.0.171
   Compiling io-lifetimes v1.0.11
   Compiling rustix v0.37.23
   Compiling bitflags v1.3.2
   Compiling syn v1.0.109
   Compiling os_str_bytes v6.5.1
   Compiling hashbrown v0.12.3
   Compiling serde_json v1.0.103
   Compiling ryu v1.0.15
   Compiling strsim v0.10.0
   Compiling parking_lot_core v0.9.8
   Compiling fastrand v1.9.0
   Compiling cfg-if v1.0.0
   Compiling itoa v1.0.9
   Compiling termcolor v1.2.0
   Compiling textwrap v0.16.0
   Compiling cbindgen v0.24.5
   Compiling clap_lex v0.2.4
   Compiling heck v0.4.1
   Compiling log v0.4.19
   Compiling indexmap v1.9.3
   Compiling tempfile v3.6.0
   Compiling lock_api v0.4.10
   Compiling scopeguard v1.2.0
   Compiling smallvec v1.11.0
   Compiling tokio v1.29.1
   Compiling bytes v1.4.0
   Compiling pin-project-lite v0.2.10
   Compiling quote v1.0.31
   Compiling syn v2.0.26
   Compiling errno v0.3.1
   Compiling atty v0.2.14
   Compiling mio v0.8.8
   Compiling socket2 v0.4.9
   Compiling num_cpus v1.16.0
   Compiling signal-hook-registry v1.4.1
   Compiling clap v3.2.25
   Compiling parking_lot v0.12.1
   Compiling serde_derive v1.0.171
   Compiling tokio-macros v2.1.0
   Compiling toml v0.5.11
   Compiling kriswuollett_examples_c_callback v0.1.0 (/Users/kris/code/kriswuollett/examples-rust/c-callback)
error[E0277]: `*mut c_void` cannot be sent between threads safely
   --> c-callback/src/lib.rs:30:24
    |
30  |       tokio::task::spawn(async move {
    |  _____------------------_^
    | |     |
    | |     required by a bound introduced by this call
31  | |         println!("init task");
32  | |         let val = VAL.get_or_init(init_val_fn).await;
33  | |         println!("init done: {val}");
34  | |         let mut locked_context = callback.context.lock().unwrap();
35  | |         (callback.f)(*locked_context);
36  | |     });
    | |_____^ `*mut c_void` cannot be sent between threads safely
    |
    = help: the trait `Send` is not implemented for `*mut c_void`
    = note: required for `std::sync::Mutex<*mut c_void>` to implement `Sync`
    = note: required for `Arc<std::sync::Mutex<*mut c_void>>` to implement `Send`
note: required because it's used within this `async` block
   --> c-callback/src/lib.rs:30:24
    |
30  |       tokio::task::spawn(async move {
    |  ________________________^
31  | |         println!("init task");
32  | |         let val = VAL.get_or_init(init_val_fn).await;
33  | |         println!("init done: {val}");
34  | |         let mut locked_context = callback.context.lock().unwrap();
35  | |         (callback.f)(*locked_context);
36  | |     });
    | |_____^
note: required by a bound in `tokio::spawn`
   --> /Users/kris/.cargo/registry/src/index.crates.io-6f17d22bba15001f/tokio-1.29.1/src/task/spawn.rs:166:21
    |
164 |     pub fn spawn<T>(future: T) -> JoinHandle<T::Output>
    |            ----- required by a bound in this function
165 |     where
166 |         T: Future + Send + 'static,
    |                     ^^^^ required by this bound in `spawn`

error[E0277]: `*mut c_void` cannot be sent between threads safely
   --> c-callback/src/lib.rs:48:24
    |
48  |       tokio::task::spawn(async move {
    |  _____------------------_^
    | |     |
    | |     required by a bound introduced by this call
49  | |         println!("init task");
50  | |         let val = VAL.get_or_init(init_val_fn).await;
51  | |         println!("init done: {val}");
52  | |         let mut locked_context = callback.context.lock().await;
53  | |         (callback.f)(*locked_context);
54  | |     });
    | |_____^ `*mut c_void` cannot be sent between threads safely
    |
    = help: the trait `Send` is not implemented for `*mut c_void`
    = note: required for `tokio::sync::Mutex<*mut c_void>` to implement `Sync`
    = note: required for `Arc<tokio::sync::Mutex<*mut c_void>>` to implement `Send`
note: required because it's used within this `async` block
   --> c-callback/src/lib.rs:48:24
    |
48  |       tokio::task::spawn(async move {
    |  ________________________^
49  | |         println!("init task");
50  | |         let val = VAL.get_or_init(init_val_fn).await;
51  | |         println!("init done: {val}");
52  | |         let mut locked_context = callback.context.lock().await;
53  | |         (callback.f)(*locked_context);
54  | |     });
    | |_____^
note: required by a bound in `tokio::spawn`
   --> /Users/kris/.cargo/registry/src/index.crates.io-6f17d22bba15001f/tokio-1.29.1/src/task/spawn.rs:166:21
    |
164 |     pub fn spawn<T>(future: T) -> JoinHandle<T::Output>
    |            ----- required by a bound in this function
165 |     where
166 |         T: Future + Send + 'static,
    |                     ^^^^ required by this bound in `spawn`

For more information about this error, try `rustc --explain E0277`.
error: could not compile `kriswuollett_examples_c_callback` (lib) due to 2 previous errors

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.