Rust Programming

8438 readers
25 users here now

founded 5 years ago
MODERATORS
351
352
 
 

Is Rust the first language to feature this borrow checker, memory safe without garbage collection concept? What other languages are there that accomplish the same things memory wise?

353
 
 

I've been trying to skill up in terms of using Rust for developing web services, and it occurred to me that there weren't any crates available for conveniently adding OWASP's best-practice HTTP headers to outgoing responses by default

So, today, I published 2x new MIT-licensed crates: owasp-headers and tower-default-headers

They may be used separately, but you can also combine them if you want to include OWASP's set of headers in the default set of headers for your HTTP server

I'm still fairly new to web services and Futures in Rust, so I'm sure there's room for improvement

Give these crates a spin and let me know how you go :)

354
355
356
357
358
359
360
 
 

Hey all! I'm the developer of pict-rs, the image host API used by lemmy. I'm here to officially announce the availability of the pict-rs 0.3 beta releases. As I type this, v0.3.0-beta.3 is currently building and should be published to dockerhub shortly. Here's what's new

Api

There are now APIs to fetch metadata about images. These endpoints are mentioned in pict-rs's README.md, but at a high level they can return mime-type, dimensions, and creation date for original or processed images

The rest of the pict-rs APIs have not changed, so if you experience different behavior, please let me know in the #pict-rs:matrix.asonix.dog channel on matrix.

Dependencies

pict-rs no longer links against imagemagick, ffmpeg, and gexiv2. This change makes developing on pict-rs significantly easier, since it now compiles like a normal rust application with very few system dependencies. This also means it can be easily linked against the musl standard library to create a static executable.

Instead of linking against the programs mentioned above, pict-rs will now spawn imagemagick, ffmpeg, and perl-image-exiftool processes in order to manipulate images. The required versions are

  • Imagemagick: At least 7.0
  • ffmpeg: At least 4.0
  • perl-image-exiftool: whatever Arch or Alpine are packaging right now

Files

images are now organized into directories by default, and will no longer have original files dumped into the root of files/. If upgrading from 0.2, a migration script will attempt to move existing files from their current locations to this new structure. Please please please take a backup of your pict-rs storage directories before upgrading.

Configuration

pict-rs now supports configuring the service with a file, rather than relying on commandline arguments or environment variables. The majority of settings can still be manipulated through the environment or through the commandline, but there is a specific feature (mentioned below) that can only be accessed through a configuration file. For information on configuring pict-rs, take a look at the pict-rs.toml file

Object Storage

There is now object storage support built-in to pict-rs. If you already have a pict-rs deployment as part of your lemmy server, there is an included migration feature to help move from your existing block storage to object storage for the image files. This does not completely remove pict-rs dependency on a local filesystem, but all original images and transformed images will be stored in object storage rather than on the local filesystem.

In particular, pict-rs database still resides on the local filesystem, and temporary files created when manipulating images will still use the /tmp directory.

Object Storage has not been tested with any cloud provider, but I have set up a local minio container for local testing. If you try to use pict-rs with your favorite cloud provider and it doesn't work, please let me know in the #pict-rs:matrix.asonix.dog channel on matrix.

If you are migrating from local storage to object storage, the specific way to accomplish that is with pict-rs's --migrate-file <file> flag, and the associated migration file. An example can be found here

Finally, object-storage is behind a feature flag, and can be disabled in custom builds of pict-rs by providing the --no-default-features flag to cargo when building

io-uring

Since actix-rt gained support for io-uring with 2.3.0, I have implemented an io-uring file backend for pict-rs. It is disabled by default, as io-uring requires a recent linux kernel release and I don't want to publish an application that doesn't work on most people's computers, but if you are interested in building and running an io-uring version of the application, you can pass --features io-uring to cargo to produce an io-uring backed binary rather than traditional blocking file IO.

In my personal testing, io-uring performed significantly better for serving files on my laptop running linux kernel 5.13.

Keep in mind that io-uring in the actix-web ecosystem is currently considered unstable and is therefore exempt from semver, so the io-uring feature in pict-rs should also be considered unstable.

Links

That about wraps up this announcement! Here's some useful links for pict-rs:

361
362
363
 
 

⚕️ Buy Steroids Online with OurMedicnes.com | Best Quality Steroids Buy Testosterone, Steroids & Vitamins Online in USA at the cheapest Rate. Buy Testosterone, Steroids & Vitamins With Credit Card and Bitcoin. $25 Off- October 2021 Buy Now!!!

364
4
rustflags (doc.rust-lang.org)
submitted 3 years ago* (last edited 3 years ago) by [email protected] to c/[email protected]
 
 

RUSTFLAGS — A space-separated list of custom flags to pass to all compiler invocations that Cargo performs. In contrast with cargo rustc, this is useful for passing a flag to all compiler instances. See build.rustflags for some more ways to set flags. This string is split by whitespace.

target-cpu

This instructs rustc to generate code specifically for particular processor. You can run rustc --print target-cpus to see the valid options to pass here. Each target has a default base CPU. Special values include: native can be passed to use the processor of the host machine. generic refers to an LLVM target with minimal features but modern tuning.

opt-level

This flag controls the optimization level.
0: no optimizations, also turns on cfg(debug_assertions) (the default).
1: basic optimizations.
2: some optimizations.
3: all optimizations.
s: optimize for binary size.
z: optimize for binary size, but also turn off loop vectorization.
Note: The -O flag is an alias for -C opt-level=2. The default is 0.

pgo

365
366
367
 
 

A simple note taking application written in Rust and GTK4.

Rnote aims to be a simple but functional note taking application for freehand drawing or annotating pictures or documents. It eventually should be able to import / export various media file formats. One main consideration is that it is vector based, which should make it very flexible in editing and altering the contents.

368
1
submitted 3 years ago* (last edited 3 years ago) by [email protected] to c/[email protected]
 
 

Is an article from Medium, that's why I used Scribe.rip to share it. thanks to @[email protected] for developing this magnificent front-end! <3

369
 
 

I'm getting a weird compiler warning from using a macro that I wrote:

warning: unnecessary parentheses around type
--> crates/apub/src/activities/community/announce.rs:43:19
|
43 | #[activity_handler(LemmyContext)]
|                   ^            ^
|
= note: `#[warn(unused_parens)]` on by default
help: remove these parentheses
|
43 - #[activity_handler(LemmyContext)]
43 + #[activity_handlerLemmyContext]
| 

Here is the code that it is warning about:

#[derive(Clone, Debug, Deserialize, Serialize, ActivityHandler, ActivityFields)]
#[serde(untagged)]
#[activity_handler(LemmyContext)]
pub enum AnnouncableActivities {
  CreateOrUpdateComment(CreateOrUpdateComment),
  CreateOrUpdatePost(Box<CreateOrUpdatePost>),
    ...
}

Macro definition is here.

The warning is clearly wrong, because the code compiles, but if after applying the suggested fix, it breaks. I also can't find any info about this problem, or how to fix it. In general there seems to be a real lack of resources for Rust macros.

So does anyone here know how to get rid of the warning, without explicitly ignoring it?

370
 
 

Buy Testosterone Cypionate 250mg / ml Tablets at low price online in US to treat hypogonadism. Order Testosterone Cypionate 250mg / 10ml (Testosterone steroids) tablets without prescriptions & get discount of $25 + free shipping for sale, fast + free + cash on delivery (cod), credit card / bitcoin payment in California, New York, Florida & Texas in the USA and UK & Australia @Unitedmedicines.

371
 
 

In the past months, with the help of Casey, I wrote a library that tries to make it more convenient to run child processes from rust programs. It's called cradle. We've been using it for a couple of our projects with success. We've just released version 0.1.0. Which means that it's not feature complete, but we don't expect drastic API changes to the existing functionality. If you try it out, please let me know what you think! Either here or in the issue tracker.

372
 
 

Using async Rust libraries is usually easy. It's just like using normal Rust code, with a little async or .await here and there. But writing your own async libraries can be hard. The first time I tried this, I got really confused by arcane, esoteric syntax like T: ?Unpin and Pin<&mut Self>. I had never seen these types before, and I didn't understand what they were doing. Now that I understand them, I've written the explainer I wish I could have read back then.

373
30
submitted 3 years ago* (last edited 3 years ago) by [email protected] to c/[email protected]
374
 
 

cross-posted from: https://lemmy.ml/post/76557

Put simply, Clojure implemented atop Rust! For now, a Clojure interpreter implemented in Rust.

375
 
 

Iframely is our embed / picture thumbnail fetcher for external sites. But its extremely heavy, unreliable ( crashes a lot ), and doesn't build for ARM.

view more: ‹ prev next ›