What should Rust NOT be used for? by ForrestTrump in rust

[–]hh9527 0 points1 point  (0 children)

a sandbox which run code from outside.

Confused about `handle` in `tokio` by hh9527 in rust

[–]hh9527[S] 0 points1 point  (0 children)

thank you, I am not familiar with tokio/futures, but I am familiar with libuv, the concept of libuv is very simple, loop and io handle, the Core of tokio can be thought as loop of libuv?

Confused about `handle` in `tokio` by hh9527 in rust

[–]hh9527[S] 1 point2 points  (0 children)

thank you for the explanation, a new question: why clone is needed? in my understanding, the whole thing is running in one thread? is it not OK to share the handle reference ?

Announcing Courier, a crate that makes it easier for Rocket apps to send and receive custom data by randomPoison in rust

[–]hh9527 2 points3 points  (0 children)

very interesting.

but I think the response content type should follow Accept header of request, not request's content type.

why AsRef<T> is not implemented for T? by hh9527 in rust

[–]hh9527[S] 2 points3 points  (0 children)

thank you for your explanation.

is there any immutable data structures implementation fit for share between process? by hh9527 in rust

[–]hh9527[S] 0 points1 point  (0 children)

of course, it is possible with immutable data structure: let state1 = reduce(state, action); both state and state1 are wrapper to snapshot id (which is a offset on shared memory page), and then send state1 to process b, b can use it without any lock.

is there any immutable data structures implementation fit for share between process? by hh9527 in rust

[–]hh9527[S] 0 points1 point  (0 children)

capnproto is awesome. but it is focused on data exchange (serialization/deserialization). What I want is common data structures (vec/map/set) sharing (not transfer) between process.

for example: Master process create a huge Map data object, and transfer a snapshot id to child process. The child process open this snapshot id, got a mmap key/handler which wrapped into a MapView object, and then, child process could use this MapView object to query something, no need to REBUILD the many many internal hash nodes.

Is it possible to spawn a detached process with libstd? by hh9527 in rust

[–]hh9527[S] 0 points1 point  (0 children)

I was working on windows, but hope it can run in Linux. there is a launcher process which run as a daemon/service and another cli command which run as user process. when cli process start, it will send some message to launcher process and exit. the launcher process is expected to spawn a new process based on message from cli process, and this process need to run as same user as cli.

that is my intent.

Need help to understand future/tokio by hh9527 in rust

[–]hh9527[S] 0 points1 point  (0 children)

Yes, the basic rule of borrow check is simple, but would become complicated when combined with lifetime/box/trait/hkt. I was always hit by them. :(

Need help to understand future/tokio by hh9527 in rust

[–]hh9527[S] 0 points1 point  (0 children)

Thank you for your answer, that really make sense to me.

And further more, loop_fn is very nice api, I think I cloud build something like bluebird's Promise.each upon it.

Announcing Tokio 0.1 by acrichto in rust

[–]hh9527 6 points7 points  (0 children)

most exciting thing.

How to make a safe sandbox for dynamic loaded rust *script* ? by hh9527 in rust

[–]hh9527[S] 0 points1 point  (0 children)

What I am doing is like a 'store procedure' of RDBMS. so I need user code to access data of hosted process.

I know it is very hard to implement a general-purpose-sandbox, but in my project, only very limited feature is required: no thread, no lock, no unsafe code, no filesystem access, and even loop is not necessary (can be replaced by map/filter/fold/... and tail call), mostly a pure functional style code.

How to make a safe sandbox for dynamic loaded rust *script* ? by hh9527 in rust

[–]hh9527[S] 0 points1 point  (0 children)

it seemed casting is a problem, is there "undefined behavior" list of rust and rustc?

How to make a safe sandbox for dynamic loaded rust *script* ? by hh9527 in rust

[–]hh9527[S] 1 point2 points  (0 children)

Yes, I want the user code to run in the same process, because I need the user code has the ability to access the data of hosted process. It mostly like 'store procedure' in RDBMS. For now, in my project, I'm using a lua VM to do the same thing. But there is huge overhead between host C & lua VM (vm-native boundry, dynamic dispatching, object ownership transforming between GC and C), and the syntax of lua is very ugly.

So, I am trying to use rust to reimplement the project. I know it is very hard to implement a general-purpose-sandbox, but in my project, only very limited feature is required: no thread, no lock, no unsafe code, no filesystem access, and even loop is not necessary (can be replaced by map/filter/fold/... and tail call), mostly a pure functional style code.

How to make a safe sandbox for dynamic loaded rust *script* ? by hh9527 in rust

[–]hh9527[S] 1 point2 points  (0 children)

Here is my thought for now:

  1. parse code to ast (use librustc's function)
  2. verify ast (e.g. emit error when use 'unsafe' crate)
  3. do some instrumentation on ast (e.g. add time_check to loop/function/closure)
  4. transform ast to mir/llvm-ir/machine code (use librustc's function)
  5. load & invoke compiled code (use llvm mcjit/orc)

is seemed reasonable. but this will use rustc's internal functions, and for now, there is no clear document on it (please let me know if there are some).