DEV Community

Cover image for Rust desde cero (parte 1)
kevin david cuadros
kevin david cuadros

Posted on

Rust desde cero (parte 1)

Este documento contiene los principios mas básicos del lenguaje de programación Rust.

Tabla de contenido

Imprimir en consola

Single placeholder

  • el single placeholder es utilizado cuando se quiere imprimir un valor único.

Single Placeholder

fn main() {
    println!("Number: {}", 1);
}
Enter fullscreen mode Exit fullscreen mode

Multiple placeholders

  • podemos usar múltiples placeholders dentro de la macro println!().
  • el número de placeholders debe ser igual el número de valores a imprimir.
fn main() {
    println!("{} con {} company", "Aprendiendo", "Cuadros");
}
Enter fullscreen mode Exit fullscreen mode

Argumentos posicionales

  • los argumentos posicionales especifica la posición de los valores en la macro.
  • la lista de valores puede tener cualquier orden.
  • un valor puede ser utilizado cualquier numero de veces.
fn main() {
    println!("Enhance your coding skills from {0} courses.  {0} courses are very {1}", "Educative", "interactive");
}
Enter fullscreen mode Exit fullscreen mode

Comentarios

  • Rust tiene dos maneras de hacer comentarios

Comentarios en línea

  • para comentar una línea de código debe comenzar por doble slash //
// Writing a Rust program
fn main() {
    //The line comment is the recommended comment style
    println!("This is a line comment!"); // print hello World to the screen
}
Enter fullscreen mode Exit fullscreen mode

Comentario de bloque

  • el texto debe estar encerrado dentro de /*...*/
fn main() {
    /* 
    The block comment is extremely useful for temporarily disabling
    a large chunk of code. /* Block comments can also be /* nested, */ */
    To comment a large block just write in between /* text */
    */
    println!("This is a line comment!"); // print hello World to the screen
}
Enter fullscreen mode Exit fullscreen mode

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

Top comments (0)

Image of AssemblyAI

Automatic Speech Recognition with AssemblyAI

Experience near-human accuracy, low-latency performance, and advanced Speech AI capabilities with AssemblyAI's Speech-to-Text API. Sign up today and get $50 in API credit. No credit card required.

Try the API

👋 Kindness is contagious

Discover a treasure trove of wisdom within this insightful piece, highly respected in the nurturing DEV Community enviroment. Developers, whether novice or expert, are encouraged to participate and add to our shared knowledge basin.

A simple "thank you" can illuminate someone's day. Express your appreciation in the comments section!

On DEV, sharing ideas smoothens our journey and strengthens our community ties. Learn something useful? Offering a quick thanks to the author is deeply appreciated.

Okay