When or why would someone use a programming language (Swift, Java, C++, Rust etc…) over an engine like Unity?

Everytime I’ve read about people asking whether they should write their game in C++ or Unity, Unity is usually the default answer, unless they want to go through the hassle of creating an engine by themselves when Unity already does everything for you. If that’s the case is there ever a case where writing a game in C++, Java, Rust etc… is better than using Unity? If so what are these cases?

Why do all metals corrode when attacking a Rust Monster, yet it itself can only target ferrous metals

When you attack a rust monster, the following may apply:

Rust Metal. Any nonmagical weapon made of metal that hits the rust monster corrodes. […]

So, bronze for example being a metal would corrode.

But the rust monster has the following action:

Antennae. The rust monster corrodes a nonmagical ferrous metal object it can see within 5 feet of it. […]

But seeing as bronze is not ferrous, it cannot be targeted.

What is the lore reason behind this?

Deciding on whether to learn Rust or OpenGL next

I’m currently a student studying Computer Science. I love to learn new things in order to further enhance my skills in the things I find useful. Part of me wants to learn OpenGL so I can get a better understanding of graphics programming, and to apply it with Unity game making (working on my very first game). However, I am also intrigued in what I read about Rust and too also gain an additional programming language that I can add to my arsenal. I’m stuck and don’t know which would be more useful in the long run. I would appropriate all the help I can get. Thank you!

¿Cómo imprimir string con asm! en rust?

Estoy creando un código para poder imprimir texto en pantalla con el macro de rust (asm!) y este es el código:

fn printmsg(string: &str) {     let length: usize = string.len();     unsafe {         asm!("syscall" :: "{rax}"(1), "{rdi}"(1), "{rsi}"(&string), "{rdx}"(length));     } }  fn main() {     let s = "hello world!";     printmsg(s); } 

Cuando hago correr el código me imprime letras aleatorias…

¿Qué hago para que me imprima “hello world!” y no otra cosa?

Can Rust replace the C or C++ programs in the Future? [on hold]

I recently read an interesting Article that, due to a memory Overflow error Power system of Boeing will collapse and turns the Flight into a Flying Brick.

This is a low level memory Handling bug. Can this bug can be eliminated if use Programming Language like Rust. Since Rust Handles memory by Itself and It is close to hardware like C language.

Rust diferença entre std::ops para operadores normais

Olá estou buscando otimizar operações matemáticas em meu programa, explorando os módulos do Rust encontrei o std::ops.

Minha duvida é a seguinte.

use std::ops::{Add}; fn main() {     let x = 10;     println!{"{}",x.add(2)}; // retorna 12     println!{"{}",x + 2}; // retorna 12 } 

Em ambos os casos a saída é a mesma

Porem tem alguma diferença entre o desempenho do x.add(2) para o x + 2 ?

How can my rust code check for exceptions thrown by calls to java code?

I have rust code that invokes a java method:

let cls = je.find_class("com/purplefrog/batikExperiment/ToPixels")?;  let width = 400; let height = 400; let rgbs = je.new_byte_array(width*height*3)?; let rgbs2:JObject = JObject::from(rgbs);  let result = je.call_static_method(cls, "renderTo", "(II[B)V", &[     JValue::from(width),     JValue::from(height),     JValue::from(rgbs2), ])?; 

When I run it I get a lot of warnings like:

WARNING in native method: JNI call made without checking exceptions when required to from CallVoidMethod     at sun.dc.pr.PathStroker.dispose(Native Method)     at sun.dc.DuctusRenderingEngine.createStrokedShape(DuctusRenderingEngine.java:108)     at java.awt.BasicStroke.createStrokedShape(BasicStroke.java:301)     at org.apache.batik.gvt.StrokeShapePainter.getPaintedArea(StrokeShapePainter.java:125)     at org.apache.batik.gvt.StrokeShapePainter.getPaintedBounds2D(StrokeShapePainter.java:134)     at org.apache.batik.gvt.CompositeShapePainter.getPaintedBounds2D(CompositeShapePainter.java:156)     at org.apache.batik.gvt.ShapeNode.getPrimitiveBounds(ShapeNode.java:238)     at org.apache.batik.gvt.AbstractGraphicsNode.getTransformedPrimitiveBounds(AbstractGraphicsNode.java:854)     at org.apache.batik.gvt.AbstractGraphicsNode.getTransformedBounds(AbstractGraphicsNode.java:820)     at org.apache.batik.gvt.CompositeGraphicsNode.getPrimitiveBounds(CompositeGraphicsNode.java:224)     at org.apache.batik.gvt.CompositeGraphicsNode.getTransformedPrimitiveBounds(CompositeGraphicsNode.java:295)     at org.apache.batik.gvt.AbstractGraphicsNode.getTransformedBounds(AbstractGraphicsNode.java:820)     at org.apache.batik.gvt.CompositeGraphicsNode.getPrimitiveBounds(CompositeGraphicsNode.java:207)     at org.apache.batik.gvt.AbstractGraphicsNode.getBounds(AbstractGraphicsNode.java:768)     at org.apache.batik.gvt.AbstractGraphicsNode.paint(AbstractGraphicsNode.java:443)     at com.purplefrog.batikExperiment.ToPixels.renderTo(ToPixels.java:49) 

How can I modify my code to check for exceptions so it will not print hundreds of these warnings?

Miller-Rabin Large Prime Generator in Rust

I implemented the Miller-Rabin prime test in Rust and made a program to generate large primes.

I have also implemented the same program in C and Haskell and the Rust version is the slowest. I am looking for advice on how to improve performance and how to improve my Rust style code.

The code below is compiled using cargo build --release. The contents of the toml file follow.

For an input initial number n=10^500 and number of tests k=40, the time taken is 4.5 seconds on my computer (1 sec for C, 2 sec for Haskell) and the answer I get for the next prime is 10^500+961. cargo run <n> <k>

main.rs

use num; use rand; use num_bigint::{BigUint, RandBigInt}; use num::FromPrimitive; use num::{Zero, One}; use std::env;  const TRIAL_DIVISORS : [u32; 167] = [3,   5,   7,  11,  13,  17,  19,  23,  29,  31,  37,  41,   43,  47,  53,  59,  61,  67,  71,  73,  79,  83,  89,  97, 101,  103, 107, 109, 113, 127, 131, 137, 139, 149, 151, 157, 163, 167,  173, 179, 181, 191, 193, 197, 199, 211, 223, 227, 229, 233, 239,  241, 251, 257, 263, 269, 271, 277, 281, 283, 293, 307, 311, 313,  317, 331, 337, 347, 349, 353, 359, 367, 373, 379, 383, 389, 397,  401, 409, 419, 421, 431, 433, 439, 443, 449, 457, 461, 463, 467,  479, 487, 491, 499, 503, 509, 521, 523, 541, 547, 557, 563, 569,  571, 577, 587, 593, 599, 601, 607, 613, 617, 619, 631, 641, 643,  647, 653, 659, 661, 673, 677, 683, 691, 701, 709, 719, 727, 733,  739, 743, 751, 757, 761, 769, 773, 787, 797, 809, 811, 821, 823,  827, 829, 839, 853, 857, 859, 863, 877, 881, 883, 887, 907, 911,  919, 929, 937, 941, 947, 953, 967, 971, 977, 983, 991, 997];  fn main() {     let args: Vec<String> = env::args().collect();     let n = args[1].parse::<BigUint>().expect("Error reading bignum.");     let ntests = args[2].parse::<usize>().expect("Error reading ntests.");      let p = find_prime(n, ntests);      println!("{}", p);   }  fn find_prime(mut n : BigUint, ntests : usize) -> BigUint {     // If the input is even, it should be made odd.     if &n % 2u32 == BigUint::zero() {         n += 1u32;     }      let two : BigUint = BigUint::from_u32(2).unwrap();      while !mr_isprime(&n, &ntests) {         n += &two;     }      n }  fn mr_isprime(n : &BigUint, ntests : &usize) -> bool {       for i in TRIAL_DIVISORS.iter() {         if n % i  == BigUint::zero() {             if n==&(BigUint::from_u32(*i).unwrap()) {                 return true             }             return false         }     }      let (d,r) = decompose(n);     let mut rng = rand::thread_rng();     let two : BigUint = BigUint::from_u32(2).unwrap();      for _ in 0..*ntests {         let a: BigUint = rng.gen_biguint_range(&two,&(n-2u16));         if trial_composite(n, &d, &r, &a) {             return false;         }     }     true }   fn trial_composite(n: &BigUint, d: &BigUint,             r: &usize, a: &BigUint) -> bool {     let mut x = a.modpow(&d, &n);     if (x==BigUint::one()) || (x==(n-1u32)) {         return false;     }     let two = BigUint::from_u32(2).unwrap();     for i in 0..(r-1) {         let e = d*( &two << i);         x = a.modpow(&e,n);         if n - 1u32 == x {             return false;         }     }      true }  fn decompose(n : &BigUint) -> (BigUint, usize) {     // Split number such that     // n = d*2^r + 1     let mut d = n - 1u32;     let mut r : usize = 0;     while (&d % 2u32).is_zero() {         r += 1;         d /= 2u32;     }     (d, r)  } 

Cargo.toml

[package] name = "miller_rabin" version = "0.1.0" authors = [""] edition = "2018"  [dependencies] num = "0.2.0" num-bigint = { version = "0.2.2", features = ["rand"] } rand = "0.6.5" 

Getting redis sentinel info in Rust

I’ve cobbled together some Rust code to display Redis master/slave information. As a Rust newbie, I’d appreciate some review feedback.

use std::collections::HashMap;  fn main() {     let url = "redis://sentinel.service.consul:26379";     let client = redis::Client::open(url).unwrap();     let con = client.get_connection().unwrap();      let groups : Vec<HashMap<String, String>> = redis::cmd("SENTINEL").arg("MASTERS").query(&con).unwrap();     for group in groups {         let name = &group["name"];         println!("group {}", name);          let master : HashMap<String, String> = redis::cmd("SENTINEL").arg("MASTER").arg(name).query(&con).unwrap();         println!("  master {}:{}", master["ip"], master["port"]);          show_server_info(&format!("redis://{}:{}", master["ip"], master["port"]));          let slaves : Vec<HashMap<String, String>> = redis::cmd("SENTINEL").arg("SLAVES").arg(name).query(&con).unwrap();         for slave in slaves {             println!("  slave {}:{}", slave["ip"], slave["port"]);             show_server_info(&format!("redis://{}:{}", slave["ip"], slave["port"]));         }     } }  fn show_server_info(url : &str) {     let client = redis::Client::open(url).unwrap();     let con = client.get_connection().unwrap();      let info : String = redis::cmd("INFO").arg("server").query(&con).unwrap();     for line in info.lines() {         if line.starts_with("uptime_in_days:") {             println!("    {}", line);         }     } }