As far as I know, there’s two ways to link native libraries in a Rust package: Attributes : #[link(name = "…")] Build scripts : cargo:rustc-link-lib=dylib=… You can also pass the linker flags directly to rustc , but that’s a bit too low level for packages. The attribute approach is the easiest, but it’s also fairly inflexible. Once the attribute is set in the upstream FFI library, dependents…
A simplified listing of the various Future combinators in futures-rs ( expanded version ): // Constructing leaf futures fn empty () -> Future < T , E > fn ok ( T ) -> Future < T , E > fn err ( E ) -> Future < T , E > fn result ( Result < T , E >) -> Future < T , E > // General future constructor fn poll_fn ( FnMut ( thread_local! ( Task )) -> Poll < T , E >) -> Future < T , E > // Mapping futures…
Note: This article is somewhat biased toward Linux-like environments. Native vs non-native Native libraries : these are the ones you get through native compilation. This applies to languages such as C, C++, Fortran. These libraries are interoperable. This category also applies to modern natively-compiled languages such as Haskell or Rust, but I’m not as familiar with those so I won’t discuss them…
Git submodules are useful, but their UX is a bit intrusive for users who aren’t even interacting with the submodules. Here’s a list of the two common ones I often run into. (Let me know if there’s anything else that folks often run into!) I cloned a repo containing submodules, but there’s nothing in them! This happens if you clone a submodule without the --recursive flag. The solution is to run…
Below is a graphical depiction of moving, copying, and borrowing in the Rust language . Most of these concepts are fairly specific to Rust and are therefore a common stumbling block for many learners. To avoid clutter in the graphics, I have tried to keep the text to a minimum. It isn’t meant to be a replacement for the various tutorials out there but more of a different perspective for…
In this post, I’ll walk through the mathematical formalism of reverse-mode automatic differentiation (AD) and try to explain some simple implementation strategies for reverse-mode AD. Demo programs in Python and Rust are included. A simple example Suppose we want to calculate the expression : \[z = x \cdot y + \sin(x)\] To do this using a program, we’d just translate it directly to code: z = x * y…
In the process of writing a math-heavy blog post, I ran into several problems with the existing Jekyll configuration. I had set up Jekyll to use Redcarpet as the Markdown renderer, but it simply does not play well with MathJax: it will screw up \ and & inside the MathJax code. It is said that Kramdown does better with MathJax, but it doesn’t support syntax highlighting on fenced code blocks and…
Today’s shower thought is: Is there a way to interpret double negation elimination as a program? ((a -> Void ) -> Void ) -> a (Here, Void denotes the empty type.) At first glance, it seems preposterous: how does one expect to produce a return value of a completely arbitrary type a merely from a function of type (a -> Void) -> Void , which doesn’t even return a value of type a ? A hint comes from…
A friend once asked me a question like this: void register_event_handler( void *f_ctx, void (*f)( void *ctx)); I’m a little confused about the purpose of f_ctx . Here, f is a handler function that gets called when the event is triggered, and f_ctx is − according to the documentation – some pointer argument that gets passed to f whenever it gets called. Why do we need f_ctx ? Wouldn’t f alone…
Most sorting algorithms rely on the correct implementation of a comparison function that returns the ordering between two elements – that is, a function that takes two elements and returns whether the first is less than, equal to, or greater than the second: function compare(x, y) { if (x < y) { return LESS_THAN; } else if (x > y) { return GREATER_THAN; } else { return EQUAL; } } The comparison…