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

Heroku

Build apps, not infrastructure.

Dealing with servers, hardware, and infrastructure can take up your valuable time. Discover the benefits of Heroku, the PaaS of choice for developers since 2007.

Visit Site

Top comments (0)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs

👋 Kindness is contagious

Immerse yourself in a wealth of knowledge with this piece, supported by the inclusive DEV Community—every developer, no matter where they are in their journey, is invited to contribute to our collective wisdom.

A simple “thank you” goes a long way—express your gratitude below in the comments!

Gathering insights enriches our journey on DEV and fortifies our community ties. Did you find this article valuable? Taking a moment to thank the author can have a significant impact.

Okay